Skip to content

Commit fb3f63f

Browse files
authored
Remove lazy invokation of segments (#20656)
This is a remainder from Blocks when these were separate query functions.
1 parent 6d94017 commit fb3f63f

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

packages/react-server/src/ReactFlightServer.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ type ReactModelObject = {+[key: string]: ReactModel};
6767

6868
type Segment = {
6969
id: number,
70-
query: () => ReactModel,
70+
model: ReactModel,
7171
ping: () => void,
7272
};
7373

@@ -113,7 +113,7 @@ export function createRequest(
113113
},
114114
};
115115
request.pendingChunks++;
116-
const rootSegment = createSegment(request, () => model);
116+
const rootSegment = createSegment(request, model);
117117
pingedSegments.push(rootSegment);
118118
return request;
119119
}
@@ -180,11 +180,11 @@ function pingSegment(request: Request, segment: Segment): void {
180180
}
181181
}
182182

183-
function createSegment(request: Request, query: () => ReactModel): Segment {
183+
function createSegment(request: Request, model: ReactModel): Segment {
184184
const id = request.nextChunkId++;
185185
const segment = {
186186
id,
187-
query,
187+
model,
188188
ping: () => pingSegment(request, segment),
189189
};
190190
return segment;
@@ -408,7 +408,7 @@ export function resolveModelToJSON(
408408
if (typeof x === 'object' && x !== null && typeof x.then === 'function') {
409409
// Something suspended, we'll need to create a new segment and resolve it later.
410410
request.pendingChunks++;
411-
const newSegment = createSegment(request, () => value);
411+
const newSegment = createSegment(request, value);
412412
const ping = newSegment.ping;
413413
x.then(ping, ping);
414414
return serializeByRefID(newSegment.id);
@@ -625,10 +625,8 @@ function emitSymbolChunk(request: Request, id: number, name: string): void {
625625
}
626626

627627
function retrySegment(request: Request, segment: Segment): void {
628-
const query = segment.query;
629-
let value;
630628
try {
631-
value = query();
629+
let value = segment.model;
632630
while (
633631
typeof value === 'object' &&
634632
value !== null &&
@@ -639,7 +637,7 @@ function retrySegment(request: Request, segment: Segment): void {
639637
// Attempt to render the server component.
640638
// Doing this here lets us reuse this same segment if the next component
641639
// also suspends.
642-
segment.query = () => value;
640+
segment.model = value;
643641
value = attemptResolveElement(
644642
element.type,
645643
element.key,

0 commit comments

Comments
 (0)