-
Notifications
You must be signed in to change notification settings - Fork 795
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
prerender: rehydrated components (pages) added twice to the DOM #2366
Comments
@peterpeterparker , were you able to resolve this in your project? Any info on a workaround? Thanks! |
@Paul-Hebert I wasn't. Still unsure if something not correctly configured or "just" an issue in case of re-hydratation when the Ionic router is used. I actually reported it today and they (Ionic team) might have a look at it. |
Thanks @peterpeterparker ! I'm also in the awkward spot of not knowing whether I'm doing something wrong or if there's a bug. Would you mind updating me if you learn more? I'll post back here if I can figure it out. Thanks! |
@Paul-Hebert sure |
By the way, here's a simplified example that reproduces this issue for me: My simplified componentsimport { Component, h } from "@stencil/core";
@Component({
tag: "c4-button",
shadow: true,
})
export class C4Button {
render() {
return (
<button>
<slot />
</button>
);
}
} import { Component, h} from "@stencil/core";
@Component({
tag: "c4-page",
})
export class C4Page {
render() {
return (
<div>
<slot />
</div>
);
}
} My simplified document I'm hydrating<!DOCTYPE html>
<html>
<head>
<script src="/stencil/stencil-components.js"></script>
</head>
<body>
<c4-page>
<c4-button>I'm a c4-button!</c4-button>
</c4-page>
</body>
</html> My Node/Express code running the hydrate scriptapp.engine("stencil-ssr", function (filePath, options, callback) {
fs.readFile(filePath, function (err, content) {
if (err) return callback(err);
const htmlString = content.toString();
return renderToString(htmlString).then((resp) => {
return callback(null, resp.html);
});
});
}); (Though I see the same issue when prerendering instead of doing SSR) The outputNote how there's a second button with an empty slot. It's invisible in this screenshot, but when I have button CSS applying padding/backgrounds, etc. it becomes visible: If I remove shadow DOM from the If anyone could point me towards a solution or something I'm doing wrong I'd really appreciate it. Thanks! 😁 |
I just played with this again. In my actual app there are a number of different components with this issue, but there's not a clear pattern of why it happens. Sometimes it happens when it's just a wrapper div. When it happens these things seem to be consistent
Hopefully that extra detail is helpful 🙂 |
I did some experiment and found something I documented on slack, just gonna copy it here it that can help. After build my dummy app with the ion-router and ion-nav, my index.html contains:
This leads to the rehydratation issue. But if I correct manually the elements rendering information as following:
Then the problem is solved! Also, without removing the comment it would actually work too but then then
|
@Paul-Hebert can you give a try to the PR @ #2508 I just provided? It does fix my issue but I would be really happy to hear some second thoughts and tests. |
Co-authored-by: peterpeterparker <david.dalbusco@outlook.com> Co-authored-by: Adam Bradley <adamdbradley@users.noreply.github.com>
This should now be solved (any feedback appreciated). The PR #2517 has been merged. |
Hey @peterpeterparker sorry I missed your ping on this! I'll test this out tomorrow! Thanks for the PR! |
Actually I just remembered we have the day off tomorrow for Juneteenth. I'll try to check this out today or Monday |
@Paul-Hebert no worries, let me know if it (hopefully) works out! |
Dang, unfortunately I'm still running into duplication errors. Here are the steps I followed to test this out:
I'm currently working on some other tasks so don't have more time to dig into this now, but let me know if there's any more info I could provide to help out or anything else I should test. (I ran this against my simplified test case as well as my more complex app) Thanks for your work on this! |
If I find some time I'll whip up a repro repo, but it might be a bit before I have a chance. |
@Paul-Hebert dang :( yes a repro repo would be nice, I'll be happy to try to reproduce it on my laptop. If you can also post an example of the prerendered HTML file I would be interesting (to have a look on the |
Ping me |
Hey @peterpeterparker , sorry for the delay. Work's been busy but I put together reproduction repo: https://github.com/cloudfour/stencil-ssr-bug-reproduction This is based off of my main (private) project repo with unnecessary sections stripped out. Here's the steps I'm going through to reproduce:
As I was working through this I realized I had questions around a few things related to the error:
If you could take a look I'd really appreciate it. Hopefully I'm just doing something wrong in my repo. Or, if there is a Stencil issue hopefully this helps to troubleshoot it. Thanks! |
@Paul-Hebert cool, thx for the repo and details! I can reproduce the problem too and do see why too In the prerendered
but its parent is
then prerendering works out. so the question is why I've to add some console.log to stencil, let me try |
Ok so the PR I implemented kick in and calculate the right
|
Did not find the solution tonight. A bit busy with clients' projects next days but I'll comeback to it, I can reproduce and see where the heck is happening. |
Awesome, thank you @peterpeterparker ! |
@Paul-Hebert can you open a new issue? I do have a solution but it breaks all tests, that's why I am a bit confuse. I do see with your test repo that the problem is this indexation and the solution is modifying My solution would be the following. In vdom-annotations modify the Is:
My suggestion:
What do you think, works for you? |
Hey @peterpeterparker, Sorry for the delay. I've been out of the office doing some socially-distant dispersed camping in the woods. I'm focused on client work today but will try out that solution tomorrow and open a new issue. Thank you for all your help on this! |
@Paul-Hebert no worries, busy too these days and next weekend too. Ping me when you've got time, no rush. |
Hello, i'm running into that issue too. Any news to this problem? I'd be very thankful for a fix, sadly i can't really provide any help to the suggested solution above. |
Hey @peterpeterparker , thanks again for all your help here! Sorry for the super long delay in trying this out. I think this fixed the issue, but I had to test it in a kind of roundabout way. I was planning to do the following:
However, it's not clear to me the correct way to build the stencil core project. I tried I feel like I'm probably missing something obvious there, so if you could provide some guidance on the proper way to build that I can try it out that way. What I Did InsteadI ended up making this change directly in the package in my Node Modules package. When I made the change here it appears to fix my problem! 🎉 (I had to switch Next StepsLet me know if there's anything else you'd like me to do to test this. You also mentioned creating a new issue about this. Is there any specific info I should include there? I was planning to include the following:
Thanks David! |
@Paul-Hebert nice to hear from you and happy to hear that you were able to try it out. I am not sure anymore if I use the Anyway yes I think we should open a new issue, because this one begins to be quite long and as I said in the workaround, it breaks all tests therefore it definitely needs inputs from the Ionic/Stencil team. Regarding content of the issue, I think what you describe is what's needed. Please do post the link to the new issue in this one, so I can follow ;) And thx in advance 👍 |
Here you go @peterpeterparker: #2611 Thanks again for all your help! |
Nice @Paul-Hebert ! |
I just upgraded to Stencil 3.0 and I am noticing this issue. On the created link I am not seeing any resolution. Has there been any further development on this? Edit: One thing to point out is there is only a single container element created. <my-component>
<div> component markup </div>
<div> component markup </div>
</my-component> So based on this it does appear to be during the hydration of the component. Edit2: <my-component>
<nested-component>
<div> component markup </div>
<div> component markup </div>
</nested-component>
</my-component>
<nested-component>
<div> component markup </div>
</nested-component> |
@CollinHerber can you do me a favor and please create a new issue with a reproduction case for the team and myself? |
We ended up finding out that switching our components to shadow:true fixed the issue and have been rolling with the large amount of changes that creates for us with switching to shadow dow. I hope to have some time in the next week or two to get that to you but we are coming up to release time here and it's very busy. I will tag you when that happens though. |
Stencil version:
"stencil/core": "^1.12.3"
I'm submitting a:
[X] bug report
Current behavior:
When I upgrade my apps to Stencil v1.12.3 and run a prerender build (
npm run build --prerender
), the components (pages) are added twice to the DOM!I can confirm that if I run
npm run start
these are correctly added only once.Not sure if the problem is linked to Stencil or the Ionic router, which I'm using.
Expected behavior:
Component added only once to the DOM.
Steps to reproduce:
I provide a sample repo.
and then serve
www
with a local web server.Screenshot:
The text was updated successfully, but these errors were encountered: