-
Notifications
You must be signed in to change notification settings - Fork 47.2k
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
[Fiber] Mark cascading updates #31866
base: main
Are you sure you want to change the base?
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
@@ -229,13 +229,17 @@ function flushSyncWorkAcrossRoots_impl( | |||
isFlushingWork = false; | |||
} | |||
|
|||
function processRootScheduleInMicrotask() { | |||
function processRootScheduleInImmediateTask() { | |||
if (enableProfilerTimer && enableComponentPerformanceTrack) { | |||
// Track the currently executing event if there is one so we can ignore this | |||
// event when logging events. | |||
trackSchedulerEvent(); |
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 had to restructure this a bit so that we have two separate callbacks depending on if we do the Scheduler_scheduleCallback
pass or the microtask pass. Because we shouldn't call trackSchedulerEvent()
if we're inside a microtask callback because that could mark a real event as if it was a scheduler event (and therefore hidden).
Comparing: 518d06d...75b0af0 Critical size changesIncludes critical production bundles, as well as any change greater than 2%:
Significant size changesIncludes any change greater than 0.2%: (No significant changes) |
A common source of performance problems is due to cascading renders from calling
setState
inuseLayoutEffect
oruseEffect
. This marks the entry from the update to when we start the render as red and"Cascade"
to highlight this.In addition to this case, there's another case where you call
setState
multiple times in the same event causing multiple renders. This might be due to multipleflushSync
, or spawned a microtasks from auseLayoutEffect
. In theory it could also be from a microtask scheduled after the firstsetState
. This one we can only detect if it's from an event that has awindow.event
since otherwise it's hard to know if we're still in the same event.I decided against making a ping in a microtask considered a cascade. Because that should ideally be using the Suspense Optimization and so wouldn't be considered multi-pass.
We might consider making the whole render phase and maybe commit phase red but that should maybe reserved for actual errors. The "Blocked" phase really represents the
setState
and so will have the stack trace of the first update.