/react18-upgrade:react18-batching-patternsfrom react18-upgrade
Diagnoses and fixes React 18 automatic batching regressions in class components, covering setState after await, setTimeout, Promise callbacks, and native event listeners. Guides refactoring vs. flushSync and updating tests for React 18 timing changes.
Ships in react18-upgrade. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Classify React 18 batching regressions, choose refactor versus flushSync, and update tests so class components no longer depend on React 17 intermediate renders in class-component async/await flows.
Location of setState | React 17 behavior | React 18 behavior | Review action |
|---|---|---|---|
| React event handler | Batched | Batched | Usually no change. |
setTimeout | Immediate re-render | Batched | Check for code or tests that expect intermediate state. |
Promise .then() / Promise .catch() | Immediate re-render | Batched | Refactor state reads and assertions. |
async / await continuation | Immediate re-render | Batched | Treat this.state reads after await as high-risk. |
Native addEventListener callback | Immediate re-render | Batched | Use React state rules even outside React synthetic events. |
Batched means all setState calls in that execution context flush together in one render at the end; no intermediate render is visible.
| Category | Signal | Default fix | Read next |
|---|---|---|---|
| A: silent state-read bug | Code reads this.state after await, setTimeout, or a Promise callback and uses it for a decision. | Compute the next value locally, use functional setState, or move dependent work into the callback. | references/batching-categories.md |
B: refactor, no flushSync | Intermediate render is not user-visible; only code structure or tests assume React 17 timing. | Collapse updates, assert final state, and remove timing assumptions. | references/batching-categories.md |
C: flushSync justified | User must see a loading/spinner/progress state, including a spinner/loading transition, before expensive sync work or an async operation begins. | Wrap only the minimum state update in flushSync. | references/flushSync-guide.md |
Use flushSync sparingly. It forces a synchronous render and bypasses React 18's concurrent scheduler, so overuse removes the performance benefit of automatic batching.
Use flushSync only when | Do not use flushSync when |
|---|---|
| A spinner or loading state must render before a fetch or expensive operation starts. | The next line merely needs a value; store it in a local variable instead. |
| Sequential UI steps must be visibly distinct, such as a progress wizard or multi-step flow. | A test asserts an intermediate render that users cannot observe. |
| Browser measurement must happen after a specific state update reaches the DOM. | Multiple state updates can be represented as one final state. |
references/batching-categories.md: Category A, B, and C explanations with full before/after code.references/flushSync-guide.md: flushSync import syntax, permitted use cases, and anti-patterns.Read these references only when the active file matches the category or the user is about to add flushSync.
## React 18 batching result - <component or file>
**Status:** fixed | recommendation only | blocked
**Category:** A state-read bug | B refactor/no flushSync | C flushSync justified
| Evidence | Decision | Change |
| --- | --- | --- |
| `<setState location and state read>` | `<why React 18 batching matters>` | `<refactor, test update, or flushSync>` |
### Validation
- Tests run: `<command or not run>`
- Intermediate state dependency removed or justified: `<yes/no>`
- `flushSync` used: `<no or minimal location and reason>`
setState calls was classified as Category A, B, or C.await was checked for this.state reads that drive decisions.flushSync was not used unless an intermediate UI state, spinner, progress step, or DOM measurement truly requires a synchronous render.flushSync.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
react-18, automatic-batching, setstate, flushsync, class-components, migration
npx claudepluginhub gbb-acelerators/awesome-harness-primitives --plugin react18-upgrade7 skills in this plugin
/react18-dep-compatibilityCheck React 18.3.1 and React 19 dependency compatibility before npm installs, peer-dependency resolutions, or upgrade plans. Use when reviewing a React upgrade matrix, resolving npm peer conflicts, choosing minimum compatible package versions, deciding on --legacy-peer-deps, or separating a react-router v5 to v6 migration./react18-enzyme-to-rtlRewrite Enzyme tests for React 18 into React Testing Library behavior tests. Use when a test imports enzyme, uses shallow, mount, wrapper.find(), wrapper.simulate(), wrapper.prop(), wrapper.state(), wrapper.instance(), Enzyme configure/Adapter, or needs React 18-compatible RTL migration patterns./react18-legacy-contextMigrate React legacy context API usage from contextTypes, childContextTypes, and getChildContext to modern createContext. Use this skill when touching legacy context in class or function components because provider and every consumer must be updated together to avoid React 18 warnings and React 19 runtime failures./react18-lifecycle-patternsMigrate unsafe React class component lifecycle methods to React 18.3.1-safe patterns. Use when fixing `componentWillMount`, `componentWillReceiveProps`, `componentWillUpdate`, `UNSAFE_` lifecycle warnings, choosing `getDerivedStateFromProps` versus `componentDidUpdate`, or adding `getSnapshotBeforeUpdate`./react18-string-refsMigrate React string refs, ref="name" assignments, and this.refs.name access to React.createRef(), callback refs, or child ref forwarding. Use this skill when migrating React 18.3.1 warnings or React 19 removals involving single refs, multiple refs, list refs, callback refs, or refs passed to child components./react-audit-grep-patternsProvide verified grep command libraries for React 18.3.1 and React 19 migration audits, including deprecated APIs, removed APIs, unsafe lifecycle methods, batching risks, tests, dependencies, and peer conflicts. Use this skill when writing or running React migration audit scan commands.Other plugins' skills for the same job