-
Notifications
You must be signed in to change notification settings - Fork 50.4k
Fix lazy thenable suspension race #35423
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
base: main
Are you sure you want to change the base?
Conversation
3b3cfe6 to
46604ca
Compare
|
This PR seems to also fix useId causing hydration issues. At least vercel/next.js#84029 and #35210 would be fixed. |
acdlite
left a comment
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.
This looks good to me. Great fix. Do you think you'd be able to write a regression test that reproduces the useId error you're referencing? (If not, I think it's fine to land as is.)
|
Comparing: 4a3d993...5027732 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) |
acdlite
left a comment
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.
actually nvm I think we need to add a regression test before landing this
|
The failing devtools test is also sus though it might just be a missing |
gnoff
left a comment
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 #35518 will fix the useId hydration issue. I do not think this change necessarily addressed the root cause but because RSC lazy elements often resolve synchronously the optimization in this PR to check the status again before throwing caused the bug in affected test cases to be hidden. However RSC does not guarantee that the lazy nodes will resolve sync b/c they may still be waiting on a microtask (or longer) so it is possible that the underlying bug could still be expressed albeit less often.
The changes in this PR may still be worthwhile (sync resolution of lazy's might be perf positive for RSC lazy elements). But the fact that the thenable state in this PR gets created over and over doesn't seem right and so the way to do this is more involved. The extra machinery in trackUsedThenableState is probably unecessary and we can jsut store what is required on the lazy iself.
A minimal change would maybe be
x.then(noop, noop)
if (lazyType._payload._status === INITIALIZED) return lazyType._payload._value
should probably put that in ReactLazy though
918b052 to
3c51c4b
Compare
|
I tried adding a test to show what sync resolution of lazy would look like but it should already be supported. when the lazy is in uninitialized status it will call .then on the returned thenable. If this runs sync then the lazy status will become Resolved before we fall through to the Resolved check below. So now I am less certain why this change actually helped with the useId change. Regardless since the underlying useId issue was addressed in #35518 I think we don't need this change anymore |
Summary
Testing
Fixes #35399