-
Notifications
You must be signed in to change notification settings - Fork 41
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
Code runs twice on first load: "flash of non-COI code" #14
Comments
To continue from #16...
The core reason is so that you don't get a flash of errored content. That's the whole reason 🤣 Take a game for instance that uses SharedArrayBuffer as a core WASM Unity Unreal Engine whatever backend. If there's no SharedArrayBuffer on load, it errors. Thus, to hide said error, you want the page to only load if there's SharedArrayBuffer and otherwise whiteout with a blank page or a loading symbol. The "throw an error" technique is basically what the app already does, my suggestion is that there be some kind of way to make it so that you avoid those errors potentially making false UI flashes of "oh no there's an err- oh now it refreshed and there's no error" Basically just a AiO toolkit idea to take that UI/UX burden of managing a |
strictly speaking, the code doesn't run twice, it looks like you have persistent logs in your devtools so you see there 2 different page loads. installing Service Workers is inevitably asynchronous and you can easily bootstrap anything you like once with little extra code: const COI = Promise[crossOriginIsolated ? 'resolve' : 'reject'](); Now you can await that The same orchestration can be used to land any other script on the page to avoid counting visits twice, as example ... but the gist is: it's pretty trivial to avoid duplicated code execution and in the worst case scenario, the very first run will already cache some network request so that the reload will be faster once the Service Worker is up and running. |
Why this is bad. a lot of this is UX-based which is very subjective.
Why this is good and should stay as-is
it seems like the general "feel" of things is that "flash of ____ content" (like "flash of unstyled content") is generally discouraged as bad UX.
if this is actually intentional and the way that you want this library to be used, I think that adding a blurb about this double-execution in the readme would be good. 😊
The text was updated successfully, but these errors were encountered: