-
Notifications
You must be signed in to change notification settings - Fork 46.4k
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
Add failing test for Suspense bug #13832
Conversation
|
||
// This is a regression test for a Suspense bug. | ||
it('specifying larger maxDuration is equivalent to omitting it', () => { | ||
[100, 500, 1000, 2000, 5000, 10000, undefined].forEach(maxDuration => { |
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 don't know if all of these are a bug. At the very least [2000, undefined]
seems to demonstrate a bug to me. Others might fail for another (maybe legit?) reason although I don't see it immediately.
Details of bundled changes.Comparing: 0af8199...9fe64c8 react-test-renderer
scheduler
Generated by 🚫 dangerJS |
This is a known behavior for updates at user-blocking (nee interactive) priority, the consequence of an intentional performance/modeling trade-off. They time out effectively immediately, because our heuristic for computing the elapsed time is to subtract the normal expiration time offset from the render expiration time. Because the user-blocking expiration offset is ~1, and normal expiration time offset is ~5, the computed elapsed time of a user-blocking update is always ~4 seconds higher than the real one. Code is here: react/packages/react-reconciler/src/ReactFiberUnwindWork.js Lines 297 to 313 in a68ca9a
The reason we made this trade-off was so we could avoid storing the start time of every pending priority level. It seemed reasonable because if you want to suspend, you probably should be deferring the update to normal priority, anyway. We might want to consider revisiting this decision. I think it's probably fine for now. There are other compelling reasons to go back to tracking all the pending levels, so if we do, we should definitely pick this task back up at that point. |
Follow-up: I think we can fix this without needing to track every expiration time, once we start tracking the current priority level with Scheduler, we can use that to subtract the correct number. The Scheduler priority integration (which we were already planning to do for other reasons) replaces the need to maintain our own list of tasks per root — Scheduler is already doing that. |
Oh right, past Andrew also left this comment:
IOW, if we're in Concurrent Mode, and we get a timeout of 0ms, we can round that up to the nearest noticable threshold. Say, 250ms. That should avoid the pathological case. That'll be an easier fix for now, since Scheduler integration is a larger effort. |
I've also struggled this. I think it would be nice to print a warning in development mode if the timeout has come earlier than |
@koba04 I don't think what you're describing is necessarily related to this PR btw. It is going to be necessary to address this in the docs though. |
I don't know if this is still relevant. |
I expect that
maxDuration
that is larger than both the actual waiting time and the current expiration context timeout should be equivalent to not specifyingmaxDuration
at all. But that doesn't seem like what happens.A more concrete example:
I'd expect
Spinner
to never be shown — or at least the behavior to be consistent betweenmaxDuration={2000}
and missingmaxDuration
.