-
Notifications
You must be signed in to change notification settings - Fork 47.5k
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
[Flight] model halted references explicitly #30731
Merged
+149
−24
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -615,7 +615,7 @@ function serializeThenable( | |
request.abortableTasks.delete(newTask); | ||
newTask.status = ABORTED; | ||
if (enableHalt && request.fatalError === haltSymbol) { | ||
emitModelChunk(request, newTask.id, reusableInfinitePromiseModel); | ||
emitBlockedChunk(request, newTask.id); | ||
} else { | ||
const errorId: number = (request.fatalError: any); | ||
const model = stringify(serializeByValueID(errorId)); | ||
|
@@ -1818,7 +1818,6 @@ function serializeLazyID(id: number): string { | |
function serializeInfinitePromise(): string { | ||
return '$@'; | ||
} | ||
const reusableInfinitePromiseModel = stringify(serializeInfinitePromise()); | ||
|
||
function serializePromiseID(id: number): string { | ||
return '$@' + id.toString(16); | ||
|
@@ -2176,9 +2175,6 @@ function renderModel( | |
if (typeof x.then === 'function') { | ||
if (request.status === ABORTING) { | ||
task.status = ABORTED; | ||
if (enableHalt && request.fatalError === haltSymbol) { | ||
return serializeInfinitePromise(); | ||
} | ||
const errorId: number = (request.fatalError: any); | ||
if (wasReactNode) { | ||
return serializeLazyID(errorId); | ||
|
@@ -2232,9 +2228,6 @@ function renderModel( | |
|
||
if (request.status === ABORTING) { | ||
task.status = ABORTED; | ||
if (enableHalt && request.fatalError === haltSymbol) { | ||
return serializeInfinitePromise(); | ||
} | ||
const errorId: number = (request.fatalError: any); | ||
if (wasReactNode) { | ||
return serializeLazyID(errorId); | ||
|
@@ -2976,6 +2969,12 @@ function emitPostponeChunk( | |
request.completedErrorChunks.push(processedChunk); | ||
} | ||
|
||
function emitBlockedChunk(request: Request, id: number): void { | ||
const row = serializeRowHeader('#', id) + '\n'; | ||
const processedChunk = stringToChunk(row); | ||
request.completedErrorChunks.push(processedChunk); | ||
} | ||
|
||
function emitErrorChunk( | ||
request: Request, | ||
id: number, | ||
|
@@ -3725,7 +3724,7 @@ function retryTask(request: Request, task: Task): void { | |
request.abortableTasks.delete(task); | ||
task.status = ABORTED; | ||
if (enableHalt && request.fatalError === haltSymbol) { | ||
emitModelChunk(request, task.id, reusableInfinitePromiseModel); | ||
emitBlockedChunk(request, task.id); | ||
} else { | ||
const errorId: number = (request.fatalError: any); | ||
const model = stringify(serializeByValueID(errorId)); | ||
|
@@ -3753,7 +3752,7 @@ function retryTask(request: Request, task: Task): void { | |
request.abortableTasks.delete(task); | ||
task.status = ABORTED; | ||
if (enableHalt && request.fatalError === haltSymbol) { | ||
emitModelChunk(request, task.id, reusableInfinitePromiseModel); | ||
emitBlockedChunk(request, task.id); | ||
} else { | ||
const errorId: number = (request.fatalError: any); | ||
const model = stringify(serializeByValueID(errorId)); | ||
|
@@ -3798,6 +3797,7 @@ function performWork(request: Request): void { | |
currentRequest = request; | ||
prepareToUseHooksForRequest(request); | ||
|
||
const hadAbortableTasks = request.abortableTasks.size > 0; | ||
try { | ||
const pingedTasks = request.pingedTasks; | ||
request.pingedTasks = []; | ||
|
@@ -3808,10 +3808,11 @@ function performWork(request: Request): void { | |
if (request.destination !== null) { | ||
flushCompletedChunks(request, request.destination); | ||
} | ||
if (request.abortableTasks.size === 0) { | ||
// we're done rendering | ||
const onAllReady = request.onAllReady; | ||
onAllReady(); | ||
if (hadAbortableTasks && request.abortableTasks.size === 0) { | ||
// We can ping after completing but if this happens there already | ||
// wouldn't be any abortable tasks. So we only call allReady after | ||
// the work which actually completed the last pending task | ||
allReady(request); | ||
} | ||
} catch (error) { | ||
logRecoverableError(request, error, null); | ||
|
@@ -3836,15 +3837,6 @@ function abortTask(task: Task, request: Request, errorId: number): void { | |
request.completedErrorChunks.push(processedChunk); | ||
} | ||
|
||
function haltTask(task: Task, request: Request): void { | ||
if (task.status === RENDERING) { | ||
// This task will be aborted by the render | ||
return; | ||
} | ||
task.status = ABORTED; | ||
emitModelChunk(request, task.id, reusableInfinitePromiseModel); | ||
} | ||
|
||
function flushCompletedChunks( | ||
request: Request, | ||
destination: Destination, | ||
|
@@ -4023,6 +4015,7 @@ export function abort(request: Request, reason: mixed): void { | |
} | ||
abortableTasks.forEach(task => abortTask(task, request, errorId)); | ||
abortableTasks.clear(); | ||
allReady(request); | ||
} | ||
const abortListeners = request.abortListeners; | ||
if (abortListeners.size > 0) { | ||
|
@@ -4078,8 +4071,11 @@ export function halt(request: Request, reason: mixed): void { | |
// to that row from every row that's still remaining. | ||
if (abortableTasks.size > 0) { | ||
request.pendingChunks++; | ||
gnoff marked this conversation as resolved.
Show resolved
Hide resolved
|
||
abortableTasks.forEach(task => haltTask(task, request)); | ||
const errorId = request.nextChunkId++; | ||
emitBlockedChunk(request, errorId); | ||
abortableTasks.forEach(task => abortTask(task, request, errorId)); | ||
abortableTasks.clear(); | ||
allReady(request); | ||
} | ||
const abortListeners = request.abortListeners; | ||
if (abortListeners.size > 0) { | ||
|
@@ -4094,3 +4090,8 @@ export function halt(request: Request, reason: mixed): void { | |
fatalError(request, error); | ||
} | ||
} | ||
|
||
function allReady(request: Request) { | ||
const onAllReady = request.onAllReady; | ||
onAllReady(); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we unify the rest of halt/abort, then this helper doesn't become necessary. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll do in the next where we re-add the error and postpone logging |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think technically maybe you need to check if it is pending first. Because it could've maybe been rejected already if we aborted between the reference and this row.