-
Notifications
You must be signed in to change notification settings - Fork 49.3k
[Fiber] Don't wait on Suspensey Images if we guess that we don't load them all in time anyway #34481
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
…basis for timeouts If some has already elapsed we should wait less.
Comparing: 47664de...ae59661 Critical size changesIncludes critical production bundles, as well as any change greater than 2%:
Significant size changesIncludes any change greater than 0.2%: Expand to show
|
export function waitForCommitToBeReady(): null | ((() => void) => () => void) { | ||
const SUSPENSEY_STYLESHEET_TIMEOUT = 60000; | ||
|
||
const SUSPENSEY_IMAGE_TIMEOUT = 800; |
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.
Because we now estimate before the timeout, I extended the actual timeout so that if we get the estimate wrong it's worth waiting a bit longer to at least get some benefit from having waited a bit already.
…ad all images within 500ms Since we're more conservative about starting to wait now, we now wait longer if we have started waiting so that we didn't wait for no good reason.
cd7e0ef
to
ae59661
Compare
Stacked on #34478.
In general we don't like to deal with timeouts in suspense world. We've had that in the past but in general it doesn't work well because if you have a timeout and then give up you made everything wait longer for no benefit at the end. That's why the recommendation is to remove a Suspense boundary if you expect it to be fast and add one if you expect it to be slow. You have to estimate as the developer.
Suspensey images suffer from this same problem. We want to apply suspensey images to as much as possible so that it's the default to avoid flashing because if just a few images flash it's still almost as bad as all of them. However, we do know that it's also very common to use images and on a slow connection or many images, it's not worth it so we have the timeout to eventually give up.
However, this means that in cases that are always slow or connections that are always slow, you're always punished for no reason.
Suspensey images is mainly a polish feature to make high end experiences on high end connections better but we don't want to unnecessarily punish all slow connections in the process or things like lots of images below the viewport.
This PR adds an estimate for whether or not we'll likely be able to load all the images within the timeout on a high end enough connection. If not, we'll still do a short suspend (unless we've already exceeded the wait time adjusted for #34478) to allow loading from cache if available.
This estimate is based on two heuristics:
navigator.connection.downlink
in Chrome or a 5mbps default in Firefox/Safari.This is somewhat conservative given that the image could've been preloaded and be better compressed.
So it really only kicks in for high end connections that are known to load fast.
In a follow up, we can add an additional wait for View Transitions that does the same estimate but only for the images that turn out to be in viewport.