oxc-project/oxc · error · OxcDiagnostic

Effect callbacks are synchronous to prevent race conditions.

Error message

Effect callbacks are synchronous to prevent race conditions.

What it means

Raised by react/exhaustive-deps when an effect callback is declared async (returns a Promise). React expects effects to be synchronous; async effects cause race conditions because cleanup cannot cancel pending promises.

Solutions

  1. Move the async work into an inner function and await it inside the synchronous effect body.
  2. Handle cleanup/cancellation explicitly (e.g. via an ignore flag or AbortController).
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/oxc_linter/src/rules/react/exhaustive_deps.rs:70 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of oxc-project/oxc@1f902a6962 (2026-08-20). Data as JSON: /api/errors/7f367d3103875665. Report an issue: GitHub.

Appendix: source

Thrown at crates/oxc_linter/src/rules/react/exhaustive_deps.rs:70

    OxcDiagnostic::warn(format!(
        "React Hook {hook_name} does nothing when called with only one argument."
    ))
    .with_label(span)
    .with_help("Did you forget to pass an array of dependencies?")
    .with_error_code_scope(SCOPE)
}

fn unknown_dependencies_diagnostic(hook_name: &str, span: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn(format!(
        "React Hook {hook_name} received a function whose dependencies are unknown."
    ))
    .with_help("Pass an inline function instead.")
    .with_label(span)
    .with_error_code_scope(SCOPE)
}

fn async_effect_diagnostic(span: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn("Effect callbacks are synchronous to prevent race conditions.")
        .with_label(span)
        .with_help("Consider putting the asynchronous code inside a function and calling it from the effect.")
        .with_error_code_scope(SCOPE)
}

fn missing_dependency_diagnostic(
    hook_name: &str,
    deps: &[Name<'_>],
    span: Span,
    mutable_ref_dependency: Option<&str>,
) -> OxcDiagnostic {
    let single = deps.len() == 1;
    let deps_pretty = if single {
        format!("'{}'", deps[0])
    } else {
        let mut iter = deps.iter();
        let all_but_last = iter.by_ref().take(deps.len() - 1).map(|s| format!("'{s}'")).join(", ");
        let last = iter.next().unwrap();

View on GitHub (pinned to 1f902a6962)