-
-
Notifications
You must be signed in to change notification settings - Fork 52
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
Flash of content on page load #65
Comments
Thanks @fabian-michael! This has been bothering me too. I think you're right that this is because of how we're hydrating the page. I used the model Rich provided here when setting this up. There are probably better hydration approaches out there that I need to look into. |
When compiling we should be setting I think it's put well here:
Per the svelte docs:
Not sure how exactly this will fit in since we're doing the replacement at the |
I have a proof of concept working for this. I modeled import App from './App.svelte';
const app = new App({
target: document.querySelector('#server-rendered-html'),
hydrate: true
}); And made sure to add Also found this React discussion about
|
Getting the "parent" of the import Router from './router.svelte';
let target = document.querySelector('#hydrate-plenti').parentNode;
new Router({
target: target,
hydrate: true
}); Makes me think that we could probably remove the injection of the Not super helpful, but a similar discussion is happening here: https://stackoverflow.com/questions/61640429/how-to-replace-the-contents-of-a-target-in-svelte-instead-of-appending-to-childr |
Console error:
|
I don't think Svelte was designed to hydrate the Unfortunately you get the same error if you try to explicitly set the anchor: import Router from './router.svelte';
let anchor = document.querySelector('html');
new Router({
target: document,
anchor: anchor,
hydrate: true
}); Related issue: sveltejs/svelte#2573 |
The updated hydration should work despite the console error, I guess we just live with that for now @fabian-michael I just retested with the new v0.2.37 release, on mobile "cumulative layout shift" seems ok, but it's still flagging it on desktop. I'll have to look into that some more. If you get a chance to retest, can you let me know if the flash of content looks better at least? Thanks! |
There still seems to be an issue around hydrating Related: sveltejs/svelte#1067 |
Hey sorry for the late reply. I haven't got much time. I'll have a look if I find some time. |
No worries @fabian-michael! I did switch out the element replacements we were doing previously for dom repairing hydration, which I think is the better way to go. Unfortunately I think some of the same issues we were experiencing previously are still there, so feel free to hold off testing. This appears to be an ongoing Svelte bug that the community is trying to work out, hopefully more on that soon. |
Comment from Baltimore Go about potential cause of flash of content: I think this is a separate issue that also may be happening, if you throttle your connection you might see a brief loading of unstyled content. Svelte has the option to export to a stylesheet or include with JS class: sveltejs/svelte#3604 (comment) The main issue I'm observing is the elements created by |
This does not appear to be the hydration issue I thought it was. I ended up pulling down the svelte fork with better hydration, but still had the same problem where the dynamic component was being removed. I also was having trouble replicating this issue in a non-plenti project. After a little more digging, it seems the issue is related to how we're getting the <script>
import Index from '../content/index.svelte';
export let route, content, allContent;
</script>
<svelte:component this={Index} {...content.fields} {allContent} /> |
I have a working model for this now that fixes the CLS on initial load: 1eccf04. Big thanks to @lukeed for helping me work through the routing setup! There is one more issue I have to resolve unfortunately before pushing out a release. The insertBefore error previously was just polluting our console logs, now that I've reworked the router to stop the flash of content it makes every page 404 (unless I edit |
I ended up reworking this a bit more. I had previously combined the router and the entrypoint, but that was causing flashes of unstyled content when navigating through client routes. It was hydrating the full dom on every route (including the This still needs a modified |
The newest release ( Note if you're coming from an older version of plenti and want to test the new release, check out this issue so it doesn't break your site: #76 If folks continue to notice flashing content, please reopen this ticket. Thanks! |
Loading a site results in a flash of content and thereby a bad cumulative layout shift. I suspect the hydration to be responsible for that.
Edit: See the second screenshot in Lighthouse where the content is gone
The text was updated successfully, but these errors were encountered: