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

[Flight] do not emit error after abort #30683

Merged
merged 1 commit into from
Aug 14, 2024

Conversation

gnoff
Copy link
Collaborator

@gnoff gnoff commented Aug 13, 2024

When synchronously aborting in a non-async Function Component if you throw after aborting the task would error rather than abort because React never observed the AbortSignal.

Using a sigil to throw after aborting during render isn't effective b/c the user code itself could throw so insteead we just read the request status. This is ok b/c we don't expect any tasks to still be pending after the currently running task finishes.

However I found one instance where that wasn't true related to serializing thenables which I've fixed so we may find other cases. If we do, though it's almost certainly a bug in our task bookkeeping so we should just fix it if it comes up.

I also updated abort to not set the status to ABORTING unless the status was OPEN. we don't want to ever leave CLOSED or CLOSING status

Copy link

vercel bot commented Aug 13, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
react-compiler-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 14, 2024 3:54am

@facebook-github-bot facebook-github-bot added CLA Signed React Core Team Opened by a member of the React Core Team labels Aug 13, 2024
@gnoff gnoff requested a review from sebmarkbage August 13, 2024 23:04
@react-sizebot
Copy link

react-sizebot commented Aug 13, 2024

Comparing: 8e60bac...52e76a5

Critical size changes

Includes critical production bundles, as well as any change greater than 2%:

Name +/- Base Current +/- gzip Base gzip Current gzip
oss-stable/react-dom/cjs/react-dom.production.js = 6.68 kB 6.68 kB +0.05% 1.82 kB 1.83 kB
oss-stable/react-dom/cjs/react-dom-client.production.js = 500.37 kB 500.37 kB = 89.80 kB 89.80 kB
oss-experimental/react-dom/cjs/react-dom.production.js = 6.69 kB 6.69 kB +0.05% 1.83 kB 1.83 kB
oss-experimental/react-dom/cjs/react-dom-client.production.js = 507.50 kB 507.50 kB = 90.96 kB 90.96 kB
facebook-www/ReactDOM-prod.classic.js = 595.24 kB 595.24 kB = 105.55 kB 105.55 kB
facebook-www/ReactDOM-prod.modern.js = 571.54 kB 571.54 kB = 101.75 kB 101.75 kB

Significant size changes

Includes any change greater than 0.2%:

(No significant changes)

Generated by 🚫 dangerJS against e86eab1

@@ -2183,7 +2183,7 @@ function renderModel(
}
}

if (thrownValue === AbortSigil) {
if (request.status === ABORTING || x === AbortSymbol) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to compare against the symbol since all cases it is thrown.

sebmarkbage
sebmarkbage previously approved these changes Aug 14, 2024
@@ -591,9 +589,11 @@ function serializeThenable(
logPostpone(request, postponeInstance.message, newTask);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't postpone get the same treatment?

When synchronously aborting in a non-async Function Component if you throw after aborting the task would error rather than abort because React never observed the AbortSignal.

This change adds an additional check to see if the request is currently aborting. I left the sigil check in place too in case a task pings after the request is closed (though I'm pretty sure that can't actually happen)

I also renamed AbortSigil to AbortSymbol and changed it to a Symbol to make some of the duck typing more efficient.
@gnoff gnoff merged commit 2a54019 into facebook:main Aug 14, 2024
185 checks passed
@gnoff gnoff deleted the handle-throws-after-abort branch August 14, 2024 03:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed React Core Team Opened by a member of the React Core Team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants