Index of every page on this site: llms.txt
All skills
github avatar

/react18-batching-patterns

@f10fdb8 official
by githubgithub/awesome-copilot42k stars
5,426
Run it yourself

Provides exact patterns for diagnosing and fixing automatic batching regressions in React 18 class components. Use this skill whenever a class component has multiple setState calls in an async method, inside setTimeout, inside a Promise .then() or .catch(), or in a native event handler. Use it before writing any flushSync call - the decision tree here prevents unnecessary flushSync overuse. Also use this skill when fixing test failures caused by intermediate state assertions that break after React 18 upgrade.

Use this Skill: https://skilld.dev/gh/github/awesome-copilot/react18-batching-patterns

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

SKILL.md

≈135 tokens for metadata: the name and description. ≈480 when used: this file. ≈2.1k more on demand in 2 files.

Description uses 6.8% of example budget

Before choosing a Skill, your Agent reads its name and description. All available Skills share that space.

  • A shorter description leaves more room for other Skills. This entry exceeds our 1% size suggestion.

In our Claude Code example, all Skill names and descriptions share 8,000 characters. This Skill uses ≈542 characters, or 6.8%.

The 1% threshold is a size suggestion. Longer descriptions can still fit.

Your model, settings, and other Skills decide how much text your Agent can read.

Example settings and source

The example uses a 200k-token context and default Claude Code settings. The count includes the name, description, separators, and when_to_use when present. Codex also counts local file paths.

Skit's source and limits: Codex 0.160.1, Claude Code 2.1.292.

React 18 Automatic Batching Patterns

Reference for diagnosing and fixing the most dangerous silent breaking change in React 18 for class-component codebases.

The Core Change

Location of setState React 17 React 18
React event handler Batched Batched (same)
setTimeout Immediate re-render Batched
Promise .then() / .catch() Immediate re-render Batched
async/await Immediate re-render Batched
Native addEventListener callback Immediate re-render Batched

Batched means: all setState calls within that execution context flush together in a single re-render at the end. No intermediate renders occur.

Quick Diagnosis

Read every async class method. Ask: does any code after an await read this.state to make a decision?

Code reads this.state after await?
  YES → Category A (silent state-read bug)
  NO, but intermediate render must be visible to user?
    YES → Category C (flushSync needed)
    NO → Category B (refactor, no flushSync)

For the full pattern for each category, read:

  • references/batching-categories.md - Category A, B, C with full before/after code
  • references/flushSync-guide.md - when to use flushSync, when NOT to, import syntax

The flushSync Rule

Use flushSync sparingly. It forces a synchronous re-render, bypassing React 18's concurrent scheduler. Overusing it negates the performance benefits of React 18.

Only use flushSync when:

  • The user must see an intermediate UI state before an async operation begins
  • A spinner/loading state must render before a fetch starts
  • Sequential UI steps have distinct visible states (progress wizard, multi-step flow)

In most cases, the fix is a refactor - restructuring the code to not read this.state after await. Read references/batching-categories.md for the correct approach per category.

Source: SKILL.md on GitHub

No rule matched.

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No alerts2mo4 checks · Risk SAFE
  • Gen Agent Trust Hub2mo

    This skill provides technical documentation and code patterns for diagnosing and fixing React 18 automatic batching regressions. It is purely informational and contains no executable code or external dependencies.

  • Socket2mo

    No alerts

  • Snyk2mo

    Risk: LOW · No issues

  • ZeroLeaks7mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at f10fdb8. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 4 days ago.

Activeupdated 7 months ago

README badge

README badge for github/awesome-copilot/react18-batching-patterns

Provides decision trees and patterns for diagnosing and fixing React 18's automatic batching behavior in class components, particularly setState calls in async methods, Promises, and native event handlers that silently broke in React 18. Use this before adding flushSync calls to determine whether you need synchronous re-renders or should refactor to avoid reading stale state after await.

Generated from the current SKILL.md.

Does this skill apply to functional components with hooks?
No. This skill targets class components only. React 18 batching behavior for functional components with useState is different and not covered here.
When should I use flushSync to fix a batching regression?
Only when the user must see an intermediate UI state before an async operation begins, like a loading spinner before a fetch. Most batching regressions should be fixed by refactoring to avoid reading this.state after await, not by adding flushSync.
Does this skill help with test failures after upgrading to React 18?
Yes. It covers fixing test failures caused by intermediate state assertions that break after React 18 upgrade, since intermediate re-renders no longer occur in setTimeout, Promise .then(), or async/await contexts.
What async contexts are affected by React 18 batching changes?
setTimeout, Promise .then()/.catch(), async/await, and native addEventListener callbacks now batch setState calls together in React 18, whereas React 17 would re-render immediately after each one.

Generated from the current SKILL.md. These answers refresh after source changes.