oxc-project/oxc · error · OxcDiagnostic
Fast refresh only works when a file only exports components.
Error message
Fast refresh only works when a file only exports components. Move your React context(s) to a separate file.
What it means
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.
Source
Thrown at crates/oxc_linter/src/rules/react/only_export_components.rs:44
fn anonymous_components_diagnostic(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn(
"Fast refresh can't handle anonymous components. Add a name to your export.",
)
.with_label(span)
}
fn local_components_diagnostic(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Fast refresh only works when a file only exports components. Move your component(s) to a separate file.")
.with_label(span)
}
fn no_export_diagnostic(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Fast refresh only works when a file has exports. Move your component(s) to a separate file.")
.with_label(span)
}
fn react_context_diagnostic(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Fast refresh only works when a file only exports components. Move your React context(s) to a separate file.")
.with_label(span)
}
#[derive(Debug, Default, Clone, Deserialize)]
pub struct OnlyExportComponents(Box<OnlyExportComponentsConfig>);
impl std::ops::Deref for OnlyExportComponents {
type Target = OnlyExportComponentsConfig;
fn deref(&self) -> &Self::Target {
&self.0
}
}
#[derive(Debug, Default, Clone, Deserialize, Serialize, JsonSchema)]
#[serde(default, rename_all = "camelCase", deny_unknown_fields)]
pub struct OnlyExportComponentsConfig {
/// Treat specific named exports as HMR-safe (useful for frameworks that hot-replaceView on GitHub (pinned to e1e7af627c)
Solutions
- Move the React context declaration into its own module file.
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at crates/oxc_linter/src/rules/react/only_export_components.rs:44 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20).
Data as JSON: /api/errors/3eb3046eb0ba1f5e.
Report an issue: GitHub.