Skip to content

docs: document waitForResponse recipe for deferred mutations#30

Merged
jbrecht merged 1 commit into
mainfrom
docs/deferred-mutation-recipe
Jun 13, 2026
Merged

docs: document waitForResponse recipe for deferred mutations#30
jbrecht merged 1 commit into
mainfrom
docs/deferred-mutation-recipe

Conversation

@jbrecht

@jbrecht jbrecht commented Jun 13, 2026

Copy link
Copy Markdown
Owner

Closes #24.

What

Documents the page.waitForResponse(...) recipe as the reliable path for the standard Next.js App Router transition (startTransition + Server Action + router.refresh()), where settleUntil: 'networkidle' can race the deferred dispatch and settle on the pre-mutation UI.

The recipe arms the response wait before the action and awaits it after — it can't resolve until the matching request has fired and returned, closing the transition gap with no settleMs guess. Placement inside run() is required (waitFor runs too late to arm the listener).

Changes (docs-only, docs/writing-tutorials.md)

  • Added the waitForResponse recipe to the deferred-mutation warning blockquote.
  • Reframed the reliable options in precedence order: named DOM signal (waitFor) > known endpoint (waitForResponse) > network quiet (settleUntil: 'networkidle', now reserved for when you have neither).
  • Added a waitForResponse row to the Settling table and scoped the settleUntil row accordingly, so the table and prose agree.
  • Updated the settling rule-of-thumb.

Why guidance over code

Resolves #24 in favor of documentation rather than a new settleUntil: 'mutation' heuristic, per the issue's own "revisit only if the guidance proves insufficient in real authoring" framing. A request-aware heuristic would trade one subtle race (pre-mutation transient) for another (settling early on background polling, or hanging when a mutation fires no request). Consumers can drop their settleMs workarounds using the documented recipe with no release.

Review

Reviewed by the code-reviewer agent: recipe is technically sound (correct waitForResponse signature, arm-before/await-after pattern genuinely closes the gap), prose/fences/anchors clean. The one flagged consistency gap (table still steering known-endpoint cases to networkidle) was fixed before push.

🤖 Generated with Claude Code

The standard Next.js App Router transition (startTransition + Server
Action + router.refresh()) dispatches its request a tick after the
action returns, so settleUntil: 'networkidle' can resolve against the
pre-mutation UI. When there's no committed DOM signal to name for
waitFor but the request behind the change is identifiable, arm
page.waitForResponse(...) before the action and await it — it can't
resolve until the matching request has fired and returned, closing the
gap with no settleMs guess.

Adds the recipe to the deferred-mutation warning, reframes the three
reliable options in precedence order (DOM signal > endpoint > network
quiet), and updates the settling rule-of-thumb. Resolves #24 in favor
of guidance over a new settleUntil: 'mutation' heuristic.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@jbrecht jbrecht merged commit d5eba99 into main Jun 13, 2026
1 check passed
@jbrecht jbrecht deleted the docs/deferred-mutation-recipe branch June 13, 2026 23:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

React-idle settleUntil variant (deferred from #18)

1 participant