Open MTyson opened 3 years ago
I have been troubleshooting, and it has something to do with the SVG elements. If they are removed from the app, the problem goes away.
Here is minimal repro: https://github.com/MTyson/sapper-bug Just the starter template with a couple icons in it. It is running here: http://rfrndm.com/ Just reload a couple times and you'll see it.
Where would one start debugging this? I can start digging in the code.
I guess when sveltekit comes out this will be obviated...
It only happens on chrome base browser..
I`m not having this issue on firefox, but in chrome, all mess up.
I'm not sure what you're doing here, but I can't reproduce your issue, using chrome, or otherwise.
What I did notice on refresh is some severe layout shift, as if you're not fully understanding how SSR works, and are doing a lot of your work in the client side. It appears that all of your content renders, and then some css or js hides it all so that only the view you're looking at is shown.
It's possible that something in your javascript is breaking the client-side and that's why you're getting a double render.
If you can follow the issue template and fill in the required sections as requested it will be easier to help you.
I stayed the hole night trying to figure out if it was something wrong with my code, but happens that if I remove the images from Nav component, and place any other thing, the problem is finished. As soon as i put 2 different images, every thing rips apart. It gets easy be replicated with sapper template, and add 2 or 3 different images to Nav.svelte.
This bug happens on chrome and firefox just check below.
You can test here for a while: https://mayarahto.com
After some chat, i think that sapper interpreter are trying to find < / img ">, but images doesnt finish like that, or we get an error, imgs finish />... so sapper bugs trying to find this tag that doesnt ecxists in html.
^ I do not know that it's the image tag. I have seen the bug, and it's weird and inconsistent.
There's so much going on with that site that I don't know where to begin.
I loaded it the first time in a fresh browser and I got a navigation bar with pink icons. I loaded it again and I got duplicated icons (such as you describe in the issue) Then I deleted the service worker and got a NGINX error
Then when I loaded it again a couple of times I got a different site
needless to say the error isn't recreatable any more, since the site with the issue seems to have disappeared.
I'm afraid there seems to be a need for more work to isolate and reliably reproduce this issue - it's a bit of a moving target at the moment.
You might remove the service worker to reduce the complexity of the app.
Sorry, i was testing other versions of sapper to see if it was without this problem, but my vps crashed and i have to rebuild it, in the meanwhile i got out of light in my building. I'll re-build the server again and warn you about it. But it is simple, where is writen on sapper template, Home, About, Blog, between "a" tag, change it, placing 3 different images, and you get the bug. Anyway..
The way to create a repro for this is:
Get the buggy repro locally, make it as small as humanly possible so that the bug is really isolated, and run npm run build
and then npx http-server __sapper__/build
. If you can see the issue there, then commit the repro to github, so that we can do the same and have a look.
Beyond that, there are way too many things going on here to try to fix the issue.
Done it! http://mayarahto.com/ - for test And the repo, to take a look: I just changed Nav.svelte https://github.com/bardobrado/sample_sapper
I am also seeing this in production. As for how to reproduce with @bardobrado's repo, the following may help:
npm run build && npm run start
instead of npm run dev
.Also, by disable cache
in dev-tools, it completely removes the issue. Caching / rehydration issue?
What I did notice on refresh is some severe layout shift, as if you're not fully understanding how SSR works, and are doing a lot of your work in the client side. It appears that all of your content renders, and then some css or js hides it all so that only the view you're looking at is shown.
It's possible that something in your javascript is breaking the client-side and that's why you're getting a double render.
If you can follow the issue template and fill in the required sections as requested it will be easier to help you.
To create that later example, all I did was take the standard template and put a couple SVG in the navbar.
We basically put production on hold and are awaiting sveltekit hoping that will fix this.
Thanks for taking a look @antony
I stayed the hole night trying to figure out if it was something wrong with my code, but happens that if I remove the images from Nav component, and place any other thing, the problem is finished. As soon as i put 2 different images, every thing rips apart. It gets easy be replicated with sapper template, and add 2 or 3 different images to Nav.svelte.
I'm just glad we aren't the only team experiencing this.
A real nightmare.
I was able to repro the bug on your site, @bardobrado
Sorry, i was testing other versions of sapper to see if it was without this problem, but my vps crashed and i have to rebuild it, in the meanwhile i got out of light in my building. I'll re-build the server again and warn you about it. But it is simple, where is writen on sapper template, Home, About, Blog, between "a" tag, change it, placing 3 different images, and you get the bug. Anyway..
We tried rolling back to earlier versions of Sapper/Svelte (and related plugins), but it still repro'd the bug.
Which version(s) of Sapper did you go back to?
Which version(s) of Sapper did you go back to?
I don't recall exactly all the versions, but we are on sapper 0.29.1 right now, and we went back to 0.28.x for sure. I'm pretty sure we tried 0.27.x also. (We also changed svelte and the other related deps).
same issue! this my demo:http://198.16.50.194:3000 just ctrl+r refresh some times in brower, and you will see the bug! i dont know what happen!
one month ago , that not happen.
FYI: Not that this issue shouldn't be fixed on the sapper side of things, but I couldn't reproduce this issue with svelte-kit.
FYI: Not that this issue shouldn't be fixed on the sapper side of things, but I couldn't reproduce this issue with svelte-kit.
Thank god.
I found some interesting things. The service-worker did not work normally on the page where the problem occurred, but after reverse proxy a domain name, I refreshed it again and there was no problem, and the service-worker started to work normally! When I checked the network, I found this problem. If necessary, I can provide my server for official review. this is ip:port : this is reverse proxy a domain:
Same server: https://cms.beefun.cc
you can try 3001 port, refresh page and will see the bug!
but if you visit cms.beefun.cc, refresh page and work fine!
@MTyson i can provide my test server if you want and my code is open source, so dont worry.
Hi, just got same problem upgrading from 0.27.x to 0.29.x.
I have a login page with just a button and if I reload the page I got two buttons, side by side.
In the svelte page I have a simple Login tag.
Right, so it makes sense why I'm not seeing this now. I took a fork at Sapper 0.27.* and have been running off this. It looks like this was introduced somewhere after 0.28.
My advice is, if you've upgraded to Sapper 0.28 or later, I would revert that upgrade. We would also welcome help from the community in diagnosing and fixing this issue, since our resources to do so are very limited right now. If a fix is made for this issue we will create a new release to publish it, despite Sapper being in maintenance mode.
@antony - where would you start in debugging this?
I think I have found the solution.
%sapper.scripts%
within src/template.html
from the head
to the end of the body
.The reason why 0.28.0+ was because https://github.com/sveltejs/sapper-template/pull/247/commits/d4c75af7f2392af1a635210ef6da4581f7713a7f#diff-4b1d306eb7949b768a10a68600e5973cdcbeafa0827e6f6e3c78c55269d4cc0b .
I believe this causes the sapper script to be evaluated before the DOM has actually been properly mounted on slower connections, thereby creating duplicate elements. This becomes more pronounced the larger the client script is (i.e. base64ed images). It's the best explanation I've got anyways.
I think I have found the solution.
- Move
%sapper.scripts%
withinsrc/template.html
from thehead
to the end of thebody
.The reason why 0.28.0+ was because sveltejs/sapper-template@d4c75af#diff-4b1d306eb7949b768a10a68600e5973cdcbeafa0827e6f6e3c78c55269d4cc0b .
I believe this causes the sapper script to be evaluated before the DOM has actually been properly mounted on slower connections, thereby creating duplicate elements. This becomes more pronounced the larger the client script is (i.e. base64ed images). It's the best explanation I've got anyways.
Bad ass!!
It is also worth repeating in this thread that a more elegant solution, suggested by @benmccann, is wrapping your sapper.start() in a window load event listener.
// src/client.js
window.addEventListener('load', () => sapper.start({
target: document.querySelector('#sapper')
}));
Hi, I can confirm @babeard solution is working, no more duplicated content.
Hi, I can confirm @babeard solution is working, no more duplicated content.
Likewise, using the load event in client.js fixed the problem.
Could people test if https://github.com/sveltejs/sapper/pull/1722 fixes this?
Unfortunately, no. I tested that a week ago and again just now and no dice.
According to MDN
The defer attribute has no effect on module scripts — they defer by default.
I just saw a variation of this bug after not seeing it for a while (after using this fix: https://github.com/sveltejs/sapper/issues/1725#issuecomment-801559348)
Seems to be mostly fixed though.
Hmm. @MTyson did you use the window load event method or the append %sapper.scripts%
to body method? Curious to see if one works better than the other.
Hmm. @MTyson did you use the window load event method or the append
%sapper.scripts%
to body method? Curious to see if one works better than the other.
I used the window.addEventListener('load'
in client variation... I'm going to try the other next.
Hi,
Just want to add to this that adding window.addEventListener('load'
solved an issue I was having when refreshing Safari with a normal cmd+r where almost never the client code would kick in (I had an onMount with a console log in a layout file). This in my case was only an issue in Safari, both desktop and iOS
We recently had the duplication with components with SVGs. Strangely, it was caused by the hydration because the original page source didn't contain any duplication.
We found that there was a <link>
tag inside of a component outside of <svelte:head>
tags. I think that screwed up the selectors of elements and upon hydration it duplicated the elements. Putting the link tag into the head fixed our issues immediately.
Thanks @asdfdelta , that is a good find.
In my case, when I used saper with ssr, it ignored first element inside <div id="sapper">
when hydratating content. So i just added sacrificial <div style="display:none;" />
and everything works now.
I have markup like so:
In my nav.svelte component. This works fine in dev.
However, in production, there is often a strange duplication of many elements. This is not consistent, but common. It is worse on remote cloud deployment of the app, but also seen on local running of prod build.
Other elements are strangely reproduced, but this is an easy instance you can see. Notice the word "referendum: is displayed twice, but only in the markup once.
The app is live here, you might need to reload a couple times to see it. http://35.223.159.8/