Remove lazy invokation of segments (#20656)
This is a remainder from Blocks when these were separate query functions.
Sebastian Markbåge committed
Jan 25, 2021 at 16:04 UTC
fb3f63f1ab6e9ebf25ddce74a19d975ef410d4f6
1 file changed
+7
-9
packages/react-server/src/ReactFlightServer.js
+7
-9
@@ -67,7 +67,7 @@ type ReactModelObject = {+[key: string]: ReactModel};
67
68
type Segment = {
69
id: number,
70
- query: () => ReactModel,
70
+ model: ReactModel,
71
ping: () => void,
72
};
73
@@ -113,7 +113,7 @@ export function createRequest(
113
},
114
};
115
request.pendingChunks++;
116
- const rootSegment = createSegment(request, () => model);
116
+ const rootSegment = createSegment(request, model);
117
pingedSegments.push(rootSegment);
118
return request;
119
}
@@ -180,11 +180,11 @@ function pingSegment(request: Request, segment: Segment): void {
180
}
181
}
182
183
-function createSegment(request: Request, query: () => ReactModel): Segment {
183
+function createSegment(request: Request, model: ReactModel): Segment {
184
const id = request.nextChunkId++;
185
const segment = {
186
id,
187
- query,
187
+ model,
188
ping: () => pingSegment(request, segment),
189
};
190
return segment;
@@ -408,7 +408,7 @@ export function resolveModelToJSON(
408
if (typeof x === 'object' && x !== null && typeof x.then === 'function') {
409
// Something suspended, we'll need to create a new segment and resolve it later.
410
request.pendingChunks++;
411
- const newSegment = createSegment(request, () => value);
411
+ const newSegment = createSegment(request, value);
412
const ping = newSegment.ping;
413
x.then(ping, ping);
414
return serializeByRefID(newSegment.id);
@@ -625,10 +625,8 @@ function emitSymbolChunk(request: Request, id: number, name: string): void {
625
}
626
627
function retrySegment(request: Request, segment: Segment): void {
628
- const query = segment.query;
629
- let value;
628
try {
631
- value = query();
629
+ let value = segment.model;
630
while (
631
typeof value === 'object' &&
632
value !== null &&
@@ -639,7 +637,7 @@ function retrySegment(request: Request, segment: Segment): void {
637
// Attempt to render the server component.
638
// Doing this here lets us reuse this same segment if the next component
639
// also suspends.
642
- segment.query = () => value;
640
+ segment.model = value;
641
value = attemptResolveElement(
642
element.type,
643
element.key,