Skip to content

Commit

Permalink
Remove lazy invokation of segments (#20656)
Browse files Browse the repository at this point in the history
This is a remainder from Blocks when these were separate query functions.
  • Loading branch information
sebmarkbage committed Jan 25, 2021
1 parent 6d94017 commit fb3f63f
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions packages/react-server/src/ReactFlightServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ type ReactModelObject = {+[key: string]: ReactModel};

type Segment = {
id: number,
query: () => ReactModel,
model: ReactModel,
ping: () => void,
};

Expand Down Expand Up @@ -113,7 +113,7 @@ export function createRequest(
},
};
request.pendingChunks++;
const rootSegment = createSegment(request, () => model);
const rootSegment = createSegment(request, model);
pingedSegments.push(rootSegment);
return request;
}
Expand Down Expand Up @@ -180,11 +180,11 @@ function pingSegment(request: Request, segment: Segment): void {
}
}

function createSegment(request: Request, query: () => ReactModel): Segment {
function createSegment(request: Request, model: ReactModel): Segment {
const id = request.nextChunkId++;
const segment = {
id,
query,
model,
ping: () => pingSegment(request, segment),
};
return segment;
Expand Down Expand Up @@ -408,7 +408,7 @@ export function resolveModelToJSON(
if (typeof x === 'object' && x !== null && typeof x.then === 'function') {
// Something suspended, we'll need to create a new segment and resolve it later.
request.pendingChunks++;
const newSegment = createSegment(request, () => value);
const newSegment = createSegment(request, value);
const ping = newSegment.ping;
x.then(ping, ping);
return serializeByRefID(newSegment.id);
Expand Down Expand Up @@ -625,10 +625,8 @@ function emitSymbolChunk(request: Request, id: number, name: string): void {
}

function retrySegment(request: Request, segment: Segment): void {
const query = segment.query;
let value;
try {
value = query();
let value = segment.model;
while (
typeof value === 'object' &&
value !== null &&
Expand All @@ -639,7 +637,7 @@ function retrySegment(request: Request, segment: Segment): void {
// Attempt to render the server component.
// Doing this here lets us reuse this same segment if the next component
// also suspends.
segment.query = () => value;
segment.model = value;
value = attemptResolveElement(
element.type,
element.key,
Expand Down

0 comments on commit fb3f63f

Please sign in to comment.