New
Introducing React Doctor for Enterprise

react-doctor/async-defer-await

Move the `await` after the synchronous early-return guard so the skip path stays fast

  • Category: Performance
  • Severity: warn
  • Source: oxlint-plugin-react-doctor
  • Framework: global
  • Enabled when: always

Validation prompt

Use this to decide whether a fired diagnostic is real or a false positive.

Confirm an awaited variable declaration (e.g. const x = await foo()) immediately followed by an if (...) return ...; whose test AND consequent reference NONE of the awaited bindings. False positive: the early-return uses the awaited value (e.g. if (!user) return null; after const user = await fetch...) — those are legitimate guards.

Fix prompt

Use this once validation confirms the diagnostic is real.

Reorder so the synchronous early-return runs first, then the await: if (skip) return defaultValue; const x = await something(). The function only pays the network/IO latency on the path that actually needs the data. See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/await

More Performance rules from the rules reference:

  • react-doctor/async-parallel: Use `const [a, b] = await Promise.all([fetchA(), fetchB()])` to run independent operations concurrently
  • react-doctor/client-passive-event-listeners: Add `{ passive: true }` as the third argument: `addEventListener('scroll', handler, { passive: true })`. Only do this if the handler does NOT call `event.preventDefault()` — passive listeners silently ignore `preventDefault()`, which breaks features like pull-to-refresh suppression, custom gestures, and nested-scroll containment.
  • react-doctor/js-async-reduce-without-awaited-acc: Await the accumulator inside an async .reduce reducer: const acc = await previous; ...; return acc;
  • react-doctor/js-batch-dom-css: Batch DOM/CSS reads and writes — interleaving them inside a loop causes layout thrashing. Read first, then write
  • react-doctor/js-cache-property-access: Hoist the deep member access into a const at the top of the loop body: `const { x, y } = obj.deeply.nested`