{"record":{"id":"74bb7159d24b3519","repo":"swc-project/swc","slug":"duplicate-self-is-found","errorCode":null,"errorMessage":"Duplicate __self is found","messagePattern":"Duplicate __self is found","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/swc_ecma_transforms_react/src/jsx/mod.rs","lineNumber":815,"sourceCode":"                                            panic!(\"Duplicate __source is found\");\n                                        }\n                                        source_props = attr\n                                            .value\n                                            .and_then(jsx_attr_value_to_expr)\n                                            .map(|expr| expr.as_arg());\n                                        assert_ne!(\n                                            source_props, None,\n                                            \"value of property '__source' should not be empty\"\n                                        );\n                                        continue;\n                                    }\n\n                                    if !use_create_element\n                                        && *i.sym == *\"__self\"\n                                        && self.development\n                                    {\n                                        if self_props.is_some() {\n                                            panic!(\"Duplicate __self is found\");\n                                        }\n                                        self_props = attr\n                                            .value\n                                            .and_then(jsx_attr_value_to_expr)\n                                            .map(|expr| expr.as_arg());\n                                        assert_ne!(\n                                            self_props, None,\n                                            \"value of property '__self' should not be empty\"\n                                        );\n                                        continue;\n                                    }\n\n                                    let value = self.process_attr_value(attr.value);\n\n                                    // TODO: Check if `i` is a valid identifier.\n                                    let key = if i.sym.contains('-') {\n                                        PropName::Str(Str {\n                                            span: i.span,","sourceCodeStart":797,"sourceCodeEnd":833,"githubUrl":"https://github.com/swc-project/swc/blob/5176682b65416c6b5de6b47379ae1588ea3ecb3f/crates/swc_ecma_transforms_react/src/jsx/mod.rs#L797-L833","documentation":"Symmetric to `__source`: with runtime=automatic and development=true, the transform reserves the first `__self` attribute for the dev-mode self argument (jsx/mod.rs:810-826). A second `__self` attribute on the same opening element cannot be forwarded, so the transform panics with \"Duplicate __self is found\".","triggerScenarios":"Compiling JSX whose opening tag contains two `__self` attributes (e.g. `<div __self={this} __self={that} />`) with jsc.transform.react.development=true and the automatic runtime.","commonSituations":"Reusing compiled dev-mode output as JSX source; codemods injecting `__self` for React error tracking on top of the compiler's own injection.","solutions":["Remove manually written `__self` attributes from JSX and rely on the dev runtime's injection.","Deduplicate the duplicated `__self` attribute in the offending element.","Turn off the react transform's development option if external tooling must manage `__self`."],"exampleFix":"// before\n<div __self={this} __self={globalThis} />\n\n// after\n<div /> // dev runtime injects __self itself","handlingStrategy":"validation","validationCode":"// Reject duplicate __self attributes before compiling.\n#[derive(Default)]\nstruct DupSelf { bad: Vec<Span> }\nimpl Visit for DupSelf {\n    fn visit_jsx_opening_element(&mut self, el: &JSXOpeningElement) {\n        let n = el.attrs.iter().filter(|a| matches!(a,\n            JSXAttrOrSpread::JSXAttr(a)\n                if matches!(&a.name, JSXAttrName::Ident(i) if i.sym == \"__self\"))).count();\n        if n > 1 { self.bad.push(el.span); }\n        el.visit_children_with(self);\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep hand-written `__self`/`__source` out of JSX sources entirely.","Audit codemods that inject dev attributes alongside the compiler's own injection.","Run dev-mode compiles in CI so duplicates surface before production builds."],"tags":["swc","jsx","react","development","duplicate-attribute","panic"],"backgroundTag":"duplicate-jsx-attribute","analyzedSha":"5176682b65416c6b5de6b47379ae1588ea3ecb3f","analyzedAt":"2026-08-17T16:16:52.067Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}