{"record":{"id":"b611fcbba1e66359","repo":"swc-project/swc","slug":"duplicate-source-is-found","errorCode":null,"errorMessage":"Duplicate __source is found","messagePattern":"Duplicate __source is found","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/swc_ecma_transforms_react/src/jsx/mod.rs","lineNumber":797,"sourceCode":"                                            HANDLER.with(|handler| {\n                                                handler\n                                                    .struct_span_err(\n                                                        i.span,\n                                                        \"The value of property 'key' should not \\\n                                                         be empty\",\n                                                    )\n                                                    .emit();\n                                            });\n                                        }\n                                        continue;\n                                    }\n\n                                    if !use_create_element\n                                        && *i.sym == *\"__source\"\n                                        && self.development\n                                    {\n                                        if source_props.is_some() {\n                                            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\");","sourceCodeStart":779,"sourceCodeEnd":815,"githubUrl":"https://github.com/swc-project/swc/blob/5176682b65416c6b5de6b47379ae1588ea3ecb3f/crates/swc_ecma_transforms_react/src/jsx/mod.rs#L779-L815","documentation":"With runtime=automatic and development=true (the !use_create_element path in jsx_elem_to_expr, jsx/mod.rs:792-808), the transform treats a `__source` attribute specially: the first one becomes the dev-mode source argument passed to jsxDEV. A second `__source` attribute on the same opening element has nowhere to go, so the transform panics with \"Duplicate __source is found\".","triggerScenarios":"Compiling JSX whose opening tag contains two `__source` attributes (e.g. `<div __source={a} __source={b} />`) with jsc.transform.react.development=true and the automatic runtime (Next.js dev mode uses exactly this combination).","commonSituations":"Pasting compiled dev output (which already contains injected `__source`) back into JSX source; a tooling/codemod that injects `__source` for error tracking while the compiler injects its own; ESLint autofix duplicating props.","solutions":["Delete manually written `__source` attributes from JSX and let the dev runtime inject them.","Deduplicate the duplicated attributes in the offending element.","If a tool must inject `__source` itself, disable the react transform's development option so the attribute is no longer special-cased."],"exampleFix":"// before\n<div __source={{ fileName: \"a.js\" }} __self={this} __source={{ fileName: \"b.js\" }} />\n\n// after\n<div /> // dev runtime injects __source/__self itself","handlingStrategy":"validation","validationCode":"// Reject duplicate special dev attributes before compiling.\n#[derive(Default)]\nstruct DupSource { bad: Vec<Span> }\nimpl Visit for DupSource {\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 == \"__source\"))).count();\n        if n > 1 { self.bad.push(el.span); }\n        el.visit_children_with(self);\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never paste compiled dev output (with injected __source/__self) back into JSX source.","If your tooling injects __source, disable the compiler's react development option.","Add an ESLint rule (react/jsx-props-no-duplicate) to CI for dev 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"}