Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove lazy invokation of segments #20656

Merged
merged 1 commit into from
Jan 25, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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