react
react copied to clipboard
[Flight][Fizz] tasks that ping in a microtask should render synchronously
stacked on #28900
This change modifies the ping mechanism for FlightServer and FizzServer to perform work synchronously if infer the ping is happening in a microtask. The heuristic is to consider whether we're already in a "work" phase which is only cleared in a second macrotask scheduled alongside the work task. If we are and the task is the only task in the queue we assume we're in a microtask and immediately retry the task.
There is an edge case however that I suspect can crop up where a ping is interleaved between a work task and the flush task. If this happens it will also appear like a microtask and be retried synchronously. While this isn't the intent of the PR this also isn't breaking any semantics so this should be fine.
I also updated the flight tests to use the same environment as FizzServer and stopped mocking setImmediate to run synchronously. This was necessary to actually exercise the timing here but it also better tests the Node implementation of FlightServer because it can't hide task scheduling mistakes behind synchronous execution
Comparing: 6f18664b82b61d34b30c794a151d7b032f8eabe0...6c0f74a94e84f4e12a7f9739adfe4a21c6b073af
Critical size changes
Includes critical production bundles, as well as any change greater than 2%:
| Name | +/- | Base | Current | +/- gzip | Base gzip | Current gzip |
|---|---|---|---|---|---|---|
| oss-stable/react-dom/cjs/react-dom.production.js | = | 497.71 kB | 497.71 kB | = | 88.93 kB | 88.93 kB |
| oss-experimental/react-dom/cjs/react-dom.production.js | = | 504.00 kB | 504.00 kB | = | 89.95 kB | 89.95 kB |
| facebook-www/ReactDOM-prod.classic.js | = | 591.14 kB | 591.14 kB | = | 103.91 kB | 103.91 kB |
| facebook-www/ReactDOM-prod.modern.js | = | 566.95 kB | 566.95 kB | = | 100.12 kB | 100.12 kB |
| test_utils/ReactAllWarnings.js | Deleted | 64.67 kB | 0.00 kB | Deleted | 16.09 kB | 0.00 kB |
Significant size changes
Includes any change greater than 0.2%:
Expand to show
Generated by :no_entry_sign: dangerJS against 6c0f74a94e84f4e12a7f9739adfe4a21c6b073af
closing in favor of https://github.com/facebook/react/pull/29491