-
Notifications
You must be signed in to change notification settings - Fork 47k
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] Schedule work in a microtask #29491
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
throw new Error( | ||
'Legacy React Server builds should not be using scheduleMicrotask. This is a bug in React.', | ||
); |
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.
Should environments that previously scheduled all work sync just continue to do sync work? I Should probably rename to scheduleWorkInCurrentTask
since it otherwise lies about what it does.
I made this error because we have no legacy builds of flight which is currently the only place this new API is used but this feels pretty inconsistent to me.
: callback => { | ||
Promise.resolve(null).then(callback).catch(handleErrorInNextTick); | ||
}; |
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.
unlike in Fiber where there is a feature test for Promise I assume here that you must be using an environment with Promise globals. At this point I think we can safely just say React requires promises and since 19 is about to ship maybe we make this breaking change in Fiber too
export const scheduleMicrotask = queueMicrotask; | ||
|
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.
supported since Node 11 so just not bothering to fall back to Promise
packages/react-server/src/forks/ReactServerStreamConfig.dom-fb-experimental.js
Outdated
Show resolved
Hide resolved
4ecb5bc
to
87178ee
Compare
87178ee
to
6947934
Compare
6947934
to
9b366ff
Compare
9b366ff
to
b9a8668
Compare
b9a8668
to
ab5cea4
Compare
ab5cea4
to
c865358
Compare
Flight pings much more often than Fizz because async function components will always take at least a microtask to resolve . Rather than scheduling this work as a new macrotask Flight now schedules pings in a microtask. This allows more microta sks to ping before actually doing a work flush but doesn't force the vm to sping up a new task which is quite common give n the nature of Server Components
c865358
to
c2bbe63
Compare
Stacked on #29551 Flight pings much more often than Fizz because async function components will always take at least a microtask to resolve . Rather than scheduling this work as a new macrotask Flight now schedules pings in a microtask. This allows more microtasks to ping before actually doing a work flush but doesn't force the vm to spin up a new task which is quite common give n the nature of Server Components DiffTrain build for commit 1e1e5cd.
Stacked on #29491 Previously if you aborted during a render the currently rendering task would itself be aborted which will cause the entire model to be replaced by the aborted error rather than just the slot currently being rendered. This change updates the abort logic to mark currently rendering tasks as aborted but allowing the current render to emit a partially serialized model with an error reference in place of the current model. The intent is to support aborting from rendering synchronously, in microtasks (after an await or in a .then) and in lazy initializers. We don't specifically support aborting from things like proxies that might be triggered during serialization of props
Stacked on #29491 Previously if you aborted during a render the currently rendering task would itself be aborted which will cause the entire model to be replaced by the aborted error rather than just the slot currently being rendered. This change updates the abort logic to mark currently rendering tasks as aborted but allowing the current render to emit a partially serialized model with an error reference in place of the current model. The intent is to support aborting from rendering synchronously, in microtasks (after an await or in a .then) and in lazy initializers. We don't specifically support aborting from things like proxies that might be triggered during serialization of props DiffTrain build for commit c4b433f.
In facebook#29491 I updated the work scheduler for Flight to use microtasks to perform work when something pings. This is useful but it does have some downsides in terms of our ability to do task prioritization. Additionally the initial work is not instantiated using a microtask which is inconsistent with how pings work. In this change I update the scheduling logic to use microtasks consistently for prerenders and use regular tasks for renders both for the initial work and pings.
In facebook#29491 I updated the work scheduler for Flight to use microtasks to perform work when something pings. This is useful but it does have some downsides in terms of our ability to do task prioritization. Additionally the initial work is not instantiated using a microtask which is inconsistent with how pings work. In this change I update the scheduling logic to use microtasks consistently for prerenders and use regular tasks for renders both for the initial work and pings.
In #29491 I updated the work scheduler for Flight to use microtasks to perform work when something pings. This is useful but it does have some downsides in terms of our ability to do task prioritization. Additionally the initial work is not instantiated using a microtask which is inconsistent with how pings work. In this change I update the scheduling logic to use microtasks consistently for prerenders and use regular tasks for renders both for the initial work and pings.
Stacked on #29551
Flight pings much more often than Fizz because async function components will always take at least a microtask to resolve . Rather than scheduling this work as a new macrotask Flight now schedules pings in a microtask. This allows more microtasks to ping before actually doing a work flush but doesn't force the vm to spin up a new task which is quite common give n the nature of Server Components