Skip to content

Commit

Permalink
[Flight] Refactor the Render Loop to Behave More Like Fizz (#28065)
Browse files Browse the repository at this point in the history
This refactors the Flight render loop to behave more like Fizz with
similar naming conventions. So it's easier to apply similar techniques
across both. This is not necessarily better/faster - at least not yet.

This doesn't yet implement serialization by writing segments to chunks
but we probably should do that since the built-in parts that
`JSON.stringify` gets us isn't really much anymore (except serializing
strings). When we switch to that it probably makes sense for the whole
thing to be recursive.

Right now it's not technically fully recursive because each recursive
render returns the next JSON value to encode. So it's kind of like a
trampoline. This means we can't have many contextual things on the
stack. It needs to use the Server Context `__POP` trick. However, it
does work for things that are contextual only for one sequence of server
component abstractions in a row. Since those are now recursive.

An interesting observation here is that `renderModel` means that
anything can suspend while still serializing the outer siblings.
Typically only Lazy or Components would suspend but in principle a Proxy
can suspend/postpone too and now that is left serialized by reference to
a future value. It's only if the thing that we rendered was something
that can reduce to Lazy e.g. an Element that we can serialize it as a
lazy.

Similarly to how Suspense boundaries in Fizz can catch errors, anything
that can be reduced to Lazy can also catch an error rather than bubbling
it. It only errors when the Lazy resolves. Unlike Suspense boundaries
though, those things don't render anything so they're otherwise going to
use the destructive form. To ensure that throwing in an Element can
reuse the current task, this must be handled by `renderModel`, not for
example `renderElement`.

DiffTrain build for commit b123b9c.
  • Loading branch information
sebmarkbage committed Jan 25, 2024
1 parent f158e17 commit a39fd4e
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25572,7 +25572,7 @@ if (__DEV__) {
return root;
}

var ReactVersion = "18.3.0-canary-8bb6ee1d3-20240125";
var ReactVersion = "18.3.0-canary-b123b9c4f-20240125";

// Might add PROFILE later.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9131,7 +9131,7 @@ var devToolsConfig$jscomp$inline_1031 = {
throw Error("TestRenderer does not support findFiberByHostInstance()");
},
bundleType: 0,
version: "18.3.0-canary-8bb6ee1d3-20240125",
version: "18.3.0-canary-b123b9c4f-20240125",
rendererPackageName: "react-test-renderer"
};
var internals$jscomp$inline_1207 = {
Expand Down Expand Up @@ -9162,7 +9162,7 @@ var internals$jscomp$inline_1207 = {
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "18.3.0-canary-8bb6ee1d3-20240125"
reconcilerVersion: "18.3.0-canary-b123b9c4f-20240125"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_1208 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9559,7 +9559,7 @@ var devToolsConfig$jscomp$inline_1073 = {
throw Error("TestRenderer does not support findFiberByHostInstance()");
},
bundleType: 0,
version: "18.3.0-canary-8bb6ee1d3-20240125",
version: "18.3.0-canary-b123b9c4f-20240125",
rendererPackageName: "react-test-renderer"
};
var internals$jscomp$inline_1248 = {
Expand Down Expand Up @@ -9590,7 +9590,7 @@ var internals$jscomp$inline_1248 = {
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "18.3.0-canary-8bb6ee1d3-20240125"
reconcilerVersion: "18.3.0-canary-b123b9c4f-20240125"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_1249 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ if (__DEV__) {
) {
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error());
}
var ReactVersion = "18.3.0-canary-8bb6ee1d3-20240125";
var ReactVersion = "18.3.0-canary-b123b9c4f-20240125";

// ATTENTION
// When adding new symbols to this file,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -539,4 +539,4 @@ exports.useSyncExternalStore = function (
exports.useTransition = function () {
return ReactCurrentDispatcher.current.useTransition();
};
exports.version = "18.3.0-canary-8bb6ee1d3-20240125";
exports.version = "18.3.0-canary-b123b9c4f-20240125";
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ exports.useSyncExternalStore = function (
exports.useTransition = function () {
return ReactCurrentDispatcher.current.useTransition();
};
exports.version = "18.3.0-canary-8bb6ee1d3-20240125";
exports.version = "18.3.0-canary-b123b9c4f-20240125";
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
"function" ===
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8bb6ee1d33ca6c7e34342bc4b17aac0449ab6899
b123b9c4f054a7def7ed84e350ccd46cc86672a6

0 comments on commit a39fd4e

Please sign in to comment.