Skip to content

Commit b239264

Browse files
committed
[Flight] Serialize deduped elements by direct reference even if they suspend (#28283)
In #28123 I switched these to be lazy references. However that creates a lazy wrapper even if they're synchronously available. We try to as much as possible preserve the original data structure in these cases. E.g. here in the dev outlining I only use a lazy wrapper if it didn't complete synchronously: https://github.com/facebook/react/pull/28272/files#diff-d4c9c509922b3671d3ecce4e051df66dd5c3d38ff913c7a7fe94abc3ba2ed72eR638 Unfortunately we don't have a data structure that tracks the status of each emitted row. We could store the task in the map but then they couldn't be GC:ed as they complete. We could maybe store the status of each element but seems so heavy. For now I just went back to direct reference which might be an issue since it can suspend something higher up when deduped. DiffTrain build for [ba5e6a8](ba5e6a8)
1 parent 64de3b0 commit b239264

File tree

5 files changed

+16
-11
lines changed

5 files changed

+16
-11
lines changed

compiled/facebook-www/REVISION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
e41ee9ea70f8998144fdd959ac11fd7a40e4ee20
1+
ba5e6a8329c7194a2c573c037a37f24ce45ee58f

compiled/facebook-www/ReactDOMTesting-prod.modern.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17066,7 +17066,7 @@ Internals.Events = [
1706617066
var devToolsConfig$jscomp$inline_1784 = {
1706717067
findFiberByHostInstance: getClosestInstanceFromNode,
1706817068
bundleType: 0,
17069-
version: "18.3.0-www-modern-da44ba18",
17069+
version: "18.3.0-www-modern-be690e4d",
1707017070
rendererPackageName: "react-dom"
1707117071
};
1707217072
var internals$jscomp$inline_2157 = {
@@ -17097,7 +17097,7 @@ var internals$jscomp$inline_2157 = {
1709717097
scheduleRoot: null,
1709817098
setRefreshHandler: null,
1709917099
getCurrentFiber: null,
17100-
reconcilerVersion: "18.3.0-www-modern-da44ba18"
17100+
reconcilerVersion: "18.3.0-www-modern-be690e4d"
1710117101
};
1710217102
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
1710317103
var hook$jscomp$inline_2158 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
@@ -17525,4 +17525,4 @@ exports.useFormStatus = function () {
1752517525
return ReactCurrentDispatcher$2.current.useHostTransitionStatus();
1752617526
throw Error(formatProdErrorMessage(248));
1752717527
};
17528-
exports.version = "18.3.0-www-modern-da44ba18";
17528+
exports.version = "18.3.0-www-modern-be690e4d";

compiled/facebook-www/ReactFlightDOMServer-dev.modern.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1952,12 +1952,16 @@ if (__DEV__) {
19521952
// but that is able to reuse the same task if we're already in one but then that
19531953
// will be a lazy future value rather than guaranteed to exist but maybe that's good.
19541954
var newId = outlineModel(request, value);
1955-
return serializeLazyID(newId);
1955+
return serializeByValueID(newId);
19561956
} else {
19571957
// We've already emitted this as an outlined object, so we can refer to that by its
1958-
// existing ID. We use a lazy reference since, unlike plain objects, elements might
1959-
// suspend so it might not have emitted yet even if we have the ID for it.
1960-
return serializeLazyID(_existingId);
1958+
// existing ID. TODO: We should use a lazy reference since, unlike plain objects,
1959+
// elements might suspend so it might not have emitted yet even if we have the ID for
1960+
// it. However, this creates an extra wrapper when it's not needed. We should really
1961+
// detect whether this already was emitted and synchronously available. In that
1962+
// case we can refer to it synchronously and only make it lazy otherwise.
1963+
// We currently don't have a data structure that lets us see that though.
1964+
return serializeByValueID(_existingId);
19611965
}
19621966
} else {
19631967
// This is the first time we've seen this object. We may never see it again

compiled/facebook-www/ReactFlightDOMServer-prod.modern.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -783,8 +783,9 @@ function renderModelDestructive(
783783
if (modelRoot === value) modelRoot = null;
784784
else
785785
return -1 === parentPropertyName
786-
? "$L" + outlineModel(request, value).toString(16)
787-
: "$L" + parentPropertyName.toString(16);
786+
? ((request = outlineModel(request, value)),
787+
serializeByValueID(request))
788+
: serializeByValueID(parentPropertyName);
788789
} else parent.set(value, -1);
789790
return renderElement(
790791
request,

compiled/facebook-www/ReactTestRenderer-dev.modern.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26053,7 +26053,7 @@ if (__DEV__) {
2605326053
return root;
2605426054
}
2605526055

26056-
var ReactVersion = "18.3.0-www-modern-2a20f3fe";
26056+
var ReactVersion = "18.3.0-www-modern-9c82ad3d";
2605726057

2605826058
// Might add PROFILE later.
2605926059

0 commit comments

Comments
 (0)