Skip to content

Backport useDeferredValue initial values - #33

Draft
christopher-buss wants to merge 3 commits into
Roblox:mainfrom
christopher-buss:backport-react-19-deferred-initial-value
Draft

Backport useDeferredValue initial values#33
christopher-buss wants to merge 3 commits into
Roblox:mainfrom
christopher-buss:backport-react-19-deferred-initial-value

Conversation

@christopher-buss

@christopher-buss christopher-buss commented Aug 31, 2026

Copy link
Copy Markdown

Summary

Backport React 19.2's optional initialValue argument for useDeferredValue on top of #25.

The first render can commit the supplied preview immediately and then schedule the final value as a distinct deferred task. The port also includes the behavior needed to recover suspended previews, avoid nested deferred waterfalls, and preserve the existing one-argument React 18 contract.

React Debug Tools includes the #28508 correction: inspection logs and returns the committed deferred value so the inspected component follows the committed tree's control flow and every subsequent hook stays aligned.

Dependency and consolidation

Upstream source and test ledger

Pinned stable contract: React v19.2.0.

Upstream source or test React-Luau target Status and deviation
Public hook and dispatcher type ReactHooks.lua; ReactCurrentDispatcher.lua Direct. Luau cannot distinguish an omitted argument from explicit nil.
Hook implementation and seven DEV dispatchers ReactFiberHooks.new.lua Adapted to React 17's lane layout. Hidden-tree/Activity prerendering is unavailable and marked at the source site.
Deferred-lane request ReactFiberWorkLoop.new.lua React 17 has no identity-valued Suspense handler stack. The port reconstructs the exact boundary selected by its canonical throw path using the visibility cursor and shouldCaptureSuspense predicate, including fallback-subtree and unstable_avoidThisFallback semantics.
Deferred lane families and root bookkeeping ReactFiberLane.lua React 17's nine transition bits keep their numeric values. Seven remain update lanes and the two highest form an independently rotating deferred family.
Separate task and entangled render lanes ReactFiberLane.lua React 17 collapses those sets. A constrained reverse selection chooses a pinged deferred task only when its stored entangled parent is also selected and pinged; priority is unchanged.
DidDefer recovery and DidDefer flag ReactFiberBeginWork.new.lua; ReactFiberFlags.lua Direct behavior with site-level register-limit and mutually-exclusive flag-reuse deviations. Hydration-only branches are unavailable.
Boundaryless component suspension and HostRoot unwind ReactFiberThrow.new.lua; ReactFiberUnwindWork.new.lua Adapted prerequisite for concurrent roots. Interrupted mounted Fibers restore from alternates; new suspended mounts retain hook state.
Concurrent finish and commit readiness ReactFiberWorkLoop.new.lua React 17 folds the modern helpers together and explicitly threads spawnedLane through concurrent and separate sync paths.
Debug Tools implementation ReactDebugHooks.lua Returns the committed memoized value. React 19 debugInfo and hookSource schema fields are not available in this React 17 Debug Tools model and are marked at the test site.
Public deferred-value cases ReactDeferredValue.spec.lua All renderer-supported cases remain in upstream order. React 19 sibling-prewarming duplicate logs are omitted because React 17 does not prewarm siblings.
Debug Tools #28508 regression ReactHooksInspectionIntegration.spec.lua Preserves initial, pending, and final rendered output; State; DeferredValue; conditional Context; and both trailing Memo assertions. The slotless renderer read and inspection dispatcher read are inlined so the translation adds no custom-hook frame. React 17 StrictMode replay, synchronous act, Promise construction, one-based IDs, and option naming are marked locally.
React 17 handler reconstruction ReactDeferredValue.spec.lua Two local regressions prove a deferred hook in a fallback marks the outer catcher and an avoided inner boundary selects the desirable outer catcher.
Reserved-lane contract ReactFiberLane.roblox.spec.lua Six local cases cover matching, unpinged, unrelated-parent, transition-priority, and multiple-deferred selection.
Fizz, hydration, Activity/Offscreen hidden prerendering, and browser popstate tests No target Out of scope because React-Luau exposes none of those renderer contracts on this branch.

Behavior-bearing history includes #27500, #27509, #27512, #27888, #28508, #32821, and #34376.

Test-driven regressions

  • Before deferred-task reverse selection, the boundaryless recovery case retained the suspended preview yield before Final.
  • Before canonical Suspense capture selection, the fallback-subtree case stopped after Primary, Loading, and Outer Fallback instead of attempting Primary and Final again.
  • Before canonical avoided-boundary selection, the desirable-boundary case stopped after Loading and Outer Fallback instead of attempting Final.
  • Before the React 17 StrictMode setter adaptation, the #28508 test dispatched into the abandoned mount queue and never produced the pending tree.

Each failing state was reproduced before its corresponding implementation and the assertions were retained.

Verification

Exact candidate:

  • Commit: dcd0350
  • Tree: 6eef706509b8354de08fc0c965a17e5e98192f10
  • One commit on dependency head c6ce564
  • Archived source snapshot SHA-256: D50B88BE6EB1E7D7BB99F68CE146504027CDF1FDED02CF8E13BA194F8EA5619E

Static checks:

  • StyLua 0.18.1 check: passed on all 13 changed Luau files
  • luau-compile: passed on all 13 changed Luau files
  • Selene 0.28.0: 0 errors, 0 warnings, 0 parse errors
  • git diff --check and privacy/debug-residue audit: passed
  • Independent provenance, deviation, ancestry, attribution, and source-link audit: passed

Hardened single-runtime Studio CLI:

  • Package identity: 1/1
  • ReactDeferredValue: 15/15
  • ReactFiberLane: 53/53
  • ReactHooksInspectionIntegration: 17 passed, 3 pre-existing skipped
  • Focused #28508 regression: 1/1
  • Focused nil-useMemo regression: 1/1
  • Focused fallback-subtree handler regression: 1/1
  • Focused desirable-boundary regression: 1/1

Generated with Codex.

Adds startTransition, useTransition, and useDeferredValue with transition lane scheduling, queue entanglement, debug inspection, and upstream-derived coverage.

Co-authored-by: Codex <noreply@openai.com>
Co-authored-by: Codex <noreply@openai.com>
Backport React 19.2's initial-value contract, reserved deferred tasks, suspended-preview recovery, and committed Debug Tools inspection.

Co-authored-by: Codex <noreply@openai.com>
@christopher-buss
christopher-buss force-pushed the backport-react-19-deferred-initial-value branch from 55818df to 015ecda Compare September 1, 2026 04:51
@christopher-buss
christopher-buss force-pushed the backport-react-19-deferred-initial-value branch 2 times, most recently from d0abe86 to dcd0350 Compare September 6, 2026 17:20
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.

1 participant