-
Notifications
You must be signed in to change notification settings - Fork 5
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
Explore options to eliminate flicker with async components #1
Comments
Hey @stereobooster! Firstly, thanks for react-snap. react-snap and react-snapshot were my inspirations for this module.The idea of using puppeteer, and inlining the critical CSS (and general perf optimisations) came from react-snap. However, the minimalCSS package didn't do the trick for me - it seems to only work with external stylesheets, whereas I wanted something that works with CSS-in-JS. While I was playing with react-snap, I tried loadable-components after seeing it suggested in your readme. (In fact, the I guess I need to dig deeper. However, I'm unclear about how it could eliminate the flicker. The fact that My current cop-out excuse is that the flicker only lasts for the shortest possible time, the preloading of scripts that this module does makes it work across any async loading mechanism (including react-loadable), and the flicker only happens once during the initial load. Not entirely happy about this anyway, but such is. :) As far as I can tell, the only way to prevent the flicker is to somehow prevent react from rendering an async component if the DOM already has stuff in it. But as far as I know, this isn't possible. (I could be wrong though - I'd love to stand corrected.) |
|
Also worth to note that most (not saying all) CSS-in-JS solutions are anti load performance solutions out of the box. See this example - gained ~20kb by removing |
Thanks for the detailed explanation, @stereobooster.
The flicker isn't because bundles haven't loaded - they already have. It's because import is asynchronous and react is synchronous. The flicker lasts for exactly 1 tick, and not for the duration of downloading the bundle, because the bundle is already downloaded.
AFAIK, there's no way around this issue. I'll be happy to be corrected. About CSS-in-JS, I'm using |
I see. Thanks
We can break async nature of promise, for example set some additional field with the source of module and read it directly in synchronous manner. Yes I know this is hack.
I haven't worked with it, but this is quote from documentation:
|
But wait a second
It means that any async solution ( |
I haven't explored SSR, so I can't speak to that. But yes, no matter the async solution, and no matter the snapshot tool, as long as react isn't going to wait for the import, it's going to flicker. |
It doesn't matter - issue happens in the browser. It doesn't matter how you generate HTML on the server. I wonder, how nobody else has noticed this before. 👏 👏 👏 |
:) People probably haven't noticed it because it's just exactly 1 tick - blink and you'll miss it. The worst 'flicker' happens when the bundle isn't available in the first place, as you've documented in the |
we discussed this in another issue |
To do this you need to be able to save state. If you can save state and pass it to
window
you can use, for example,loadable-components
Solution described here
The text was updated successfully, but these errors were encountered: