[React 19] React Server Components: flushScheduled
Initialization in startWork
Can Be Improved
#32721
Labels
flushScheduled
Initialization in startWork
Can Be Improved
#32721
Issue Description
Currently in the React Server Components implementation, the
startWork
function initializes theflushScheduled
flag based on whether a destination exists:I've analyzed the behavior of this flag across three different scenarios:
When
startFlowing
is called beforestartWork
(settingdestination
before beginning rendering) - Effective: Prevents duplicate flush scheduling for the initial render completion.When
startFlowing
is called after the initial render completes - No difference: Whether this flag is set or not has no impact on behavior.When
startFlowing
is called during the initial render process - Ineffective: The flag cannot correctly control flush behavior in this scenario.This suggests there's room for improvement in how flush timing is controlled in the current implementation.
Problem
This approach is not robust enough if we want to ensure that no flushing occurs until the initial render is fully complete. The current design relies on indirect state and the timing of API calls, making it brittle and hard to reason about.
The code could be more explicit about its intent to batch initial render output, especially since
flushScheduled
is primarily used to prevent duplicate flush scheduling rather than controlling flush timing.Proposed Solution
I propose implementing a more explicit approach to control flushing behavior:
This makes the intent clearer and provides more predictable behavior regardless of when
startFlowing
is called.Benefits
Thank you for considering this improvement
The text was updated successfully, but these errors were encountered: