@samitouri / QOS-React / commits / bac33d1f82

[Flight] Unwrap lazy before reading the value (#30938)

This is important if the lazy is at the root of the chunk. I don't have a unit test for it but @gnoff has a repro. It also shouldn't unwrap the last value since that's the one we're referencing. This was already done correctly by @unstubbable in waitForReference so this just aligns with that.

Sebastian Markbåge committed Sep 10, 2024 at 19:42 UTC bac33d1f82d9094b45d6f662dd7fa895abab8bce
1 file changed +3 -3
packages/react-client/src/ReactFlightClient.js
+3 -3
@@ -1057,8 +1057,7 @@ function getOutlinedModel<T>(
1057 case INITIALIZED:
1058 let value = chunk.value;
1059 for (let i = 1; i < path.length; i++) {
1060 - value = value[path[i]];
1061 - if (value.$$typeof === REACT_LAZY_TYPE) {
1060 + while (value.$$typeof === REACT_LAZY_TYPE) {
1061 const referencedChunk: SomeChunk<any> = value._payload;
1062 if (referencedChunk.status === INITIALIZED) {
1063 value = referencedChunk.value;
@@ -1069,10 +1068,11 @@ function getOutlinedModel<T>(
1068 key,
1069 response,
1070 map,
1072 - path.slice(i),
1071 + path.slice(i - 1),
1072 );
1073 }
1074 }
1075 + value = value[path[i]];
1076 }
1077 const chunkValue = map(response, value);
1078 if (__DEV__ && chunk._debugInfo) {