mirror of
https://github.com/hanzoai/react.git
synced 2026-09-24 17:02:27 +00:00
Remove lazy invokation of segments (#20656)
This is a remainder from Blocks when these were separate query functions.
This commit is contained in:
committed by
GitHub
parent
5559348caa
commit
a67658a3dc
+7
-9
@@ -67,7 +67,7 @@ type ReactModelObject = {+[key: string]: ReactModel};
|
||||
|
||||
type Segment = {
|
||||
id: number,
|
||||
query: () => ReactModel,
|
||||
model: ReactModel,
|
||||
ping: () => void,
|
||||
};
|
||||
|
||||
@@ -113,7 +113,7 @@ export function createRequest(
|
||||
},
|
||||
};
|
||||
request.pendingChunks++;
|
||||
const rootSegment = createSegment(request, () => model);
|
||||
const rootSegment = createSegment(request, model);
|
||||
pingedSegments.push(rootSegment);
|
||||
return request;
|
||||
}
|
||||
@@ -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;
|
||||
@@ -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);
|
||||
@@ -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 &&
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user