{"record":{"id":"3eb3046eb0ba1f5e","repo":"oxc-project/oxc","slug":"fast-refresh-only-works-when-a-file-only-exports-c-3eb304","errorCode":null,"errorMessage":"Fast refresh only works when a file only exports components. Move your React context(s) to a separate file.","messagePattern":"Fast refresh only works when a file only exports components\\. Move your React context\\(s\\) to a separate file\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"error","filePath":"crates/oxc_linter/src/rules/react/only_export_components.rs","lineNumber":44,"sourceCode":"fn anonymous_components_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\n        \"Fast refresh can't handle anonymous components. Add a name to your export.\",\n    )\n    .with_label(span)\n}\n\nfn local_components_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Fast refresh only works when a file only exports components. Move your component(s) to a separate file.\")\n        .with_label(span)\n}\n\nfn no_export_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Fast refresh only works when a file has exports. Move your component(s) to a separate file.\")\n        .with_label(span)\n}\n\nfn react_context_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Fast refresh only works when a file only exports components. Move your React context(s) to a separate file.\")\n        .with_label(span)\n}\n\n#[derive(Debug, Default, Clone, Deserialize)]\npub struct OnlyExportComponents(Box<OnlyExportComponentsConfig>);\n\nimpl std::ops::Deref for OnlyExportComponents {\n    type Target = OnlyExportComponentsConfig;\n\n    fn deref(&self) -> &Self::Target {\n        &self.0\n    }\n}\n\n#[derive(Debug, Default, Clone, Deserialize, Serialize, JsonSchema)]\n#[serde(default, rename_all = \"camelCase\", deny_unknown_fields)]\npub struct OnlyExportComponentsConfig {\n    /// Treat specific named exports as HMR-safe (useful for frameworks that hot-replace","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/react/only_export_components.rs#L26-L62","documentation":"Raised by react/only_export_components when a file exports React context objects (e.g. `export const MyContext = createContext(...)`) alongside or instead of pure components. At the throw site context exports prevent Fast Refresh from cleanly handling the module — context creation is not a component and invalidates the refresh boundary, so edits cause full reloads. react_context_diagnostic fires from report_diagnostics for createContext calls that reach the module's exports, directing contexts into their own file.","triggerScenarios":"Thrown at crates/oxc_linter/src/rules/react/only_export_components.rs:44 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Move the React context declaration into its own module file."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}