Now liveThe Skillselion MCP - thousands of ranked skills, loaded into your agent mid-task. No install.Get it →
github avatar

React18 Batching Patterns

  • 756 installs
  • 37.1k repo stars
  • Updated July 28, 2026
  • github/awesome-copilot

react18-batching-patterns fixes React 18 automatic batching regressions in class components and related test failures.

About

React 18 Automatic Batching Patterns documents the silent breaking change where setState inside setTimeout, Promise handlers, async/await, and native event listeners now batches into a single re-render instead of flushing immediately as in React 17. A quick diagnosis tree classifies bugs into Category A silent state-read after await, Category B refactor without flushSync, or Category C when intermediate UI must be visible before async work continues. The flushSync rule limits synchronous re-renders to spinner or loading states and multi-step visible wizards because overuse bypasses the concurrent scheduler. Reference files batching-categories.md and flushSync-guide.md carry full before/after patterns for each category. The skill explicitly targets class components and test failures from intermediate state assertions after React 18 upgrade.

  • React 18 batches setState in setTimeout, promises, async/await, and native listeners.
  • Diagnosis tree: state read after await, refactor path, or flushSync requirement.
  • Category A fixes silent bugs from reading this.state after await.
  • flushSync only when users must see intermediate UI before async continues.
  • Addresses test failures from intermediate state assertions post-upgrade.

React18 Batching Patterns by the numbers

  • 756 all-time installs (skills.sh)
  • +17 installs in the week ending Jul 19, 2026 (Skillselion tracking)
  • Ranked #454 of 2,277 Frontend Development skills by installs in the Skillselion catalog
  • Security screen: LOW risk (skills.sh audit)
  • Data as of Jul 28, 2026 (Skillselion catalog sync)
At a glance

react18-batching-patterns capabilities & compatibility

Capabilities
react 17 versus 18 batching behavior comparison · category a/b/c diagnosis decision tree · refactor guidance to avoid post await state read · selective flushsync usage rules · test failure remediation for batched renders
Use cases
testing · debugging · refactoring
From the docs

What react18-batching-patterns says it does

Use `flushSync` sparingly.
SKILL.md
npx skills add https://github.com/github/awesome-copilot --skill react18-batching-patterns

Add your badge

Show developers this skill is listed on Skillselion. Paste this into your README.

Listed on Skillselion
Installs756
repo stars37.1k
Security audit3 / 3 scanners passed
Last updatedJuly 28, 2026
Repositorygithub/awesome-copilot

Why do class components break after React 18 when setState runs inside async code or timers?

Diagnose and fix React 18 automatic batching regressions in class components with async setState, setTimeout, Promise handlers, and selective flushSync use.

Who is it for?

Teams upgrading class-component codebases to React 18.3.1 with async setState or failing intermediate assertions.

Skip if: Skip for function components with hooks only, dependency version matrices, or Enzyme migration work.

When should I use this skill?

Class component has multiple setState in async methods, timers, promises, or tests assert intermediate renders.

What you get

Category-based diagnosis with refactor-first fixes and sparing flushSync for required intermediate UI.

  • Corrected async React handler code

Files

SKILL.mdMarkdownGitHub ↗

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 setStateReact 17React 18
React event handlerBatchedBatched (same)
setTimeoutImmediate re-renderBatched
Promise .then() / .catch()Immediate re-renderBatched
async/awaitImmediate re-renderBatched
Native addEventListener callbackImmediate re-renderBatched

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.

Related skills

How it compares

Use react18-batching-patterns for concrete React 18 batching before/after snippets; reach for general React docs when learning batching theory without migration bugs.

FAQ

setTimeout setState behavior in React 18?

Batched into one re-render at end of execution context, unlike immediate renders in React 17.

When use flushSync?

Only when users must see loading or intermediate UI before async work; refactor is preferred in most cases.

Code reads this.state after await?

Category A silent bug; restructure so decisions do not depend on stale state after await.

Is React18 Batching Patterns safe to install?

skills.sh reports 3 of 3 security scanners passed. Review the Security Audits panel on this page before installing in production.

Frontend Developmentfrontendtesting

This week in AI coding

Five minutes, every Monday - the tools, releases and tactics for developers.

unsubscribe anytime.