You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
prerender: rehydrated components (pages) added twice to the DOM #2366
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.
git clone https://github.com/peterpeterparker/twice-component
npm run build
and then servewww with a local web server. Screenshot:
Reacted by Patrick Wespi, Paul Hebert, saiy2k and Guido Knoll
changed the title [-]prerender: component (pages) added twice to the DOM[/-][+]prerender: rehydrated components (pages) added twice to the DOM[/+]on May 9, 2020
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!
<!DOCTYPE html><html><head><scriptsrc="/stencil/stencil-components.js"></script></head><body><c4-page><c4-button>I'm a c4-button!</c4-button></c4-page></body></html>
(Though I see the same issue when prerendering instead of doing SSR)
The output
Note 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 c4-button, I get this similar but different issue. Now the duplicate buttons are nested:
If anyone could point me towards a solution or something I'm doing wrong I'd really appreciate it.
I'd love to improve the performance of my Stencil app with preloading but this is a major blocker in that effort.
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
the elements use Shadow DOM
the direct child of the Shadow DOM gets duplicated
the duplicate does not get any slot content (if there is a slot)
the duplicate does not get the classes Stencil adds during hydration (e.g. sc-c4-container)
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.
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 0.2 to 1.2 or 1.0.2. Therefore I do not what I am missing or if the indexing in the test can be updated. It needs input from the team, I do not want to submit a PR in which I modify all existing tests and break something.
My solution would be the following. In vdom-annotations modify the hostId of the orgLocationNodes to not always be 0 be rather reflect the s-id of the node, if one was set during parseVNodeAnnotations.
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.
Copy the build output into my bug repro repo, replacing my existing copy of Stencil core.
However, it's not clear to me the correct way to build the stencil core project. I tried build, build.prod and release.prepare. Each of these generated a /build directory with a different structure than I expected. It didn't match the structure of the Stencil Core in my project's Node Modules folder.
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 Instead
I 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 NODE_TYPE.ElementNode to 1 for this to work. Based on inline comments it looks like this change is automatically made during compilation.)
Next Steps
Let 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:
@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 build or build:pro command.
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 ;)
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.
This is what is observed
So based on this it does appear to be during the hydration of the component.
Edit2:
Further investigation suggests that this is only happening for component that have nested stencil components.
So the hydrated markup looks something like this
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.
Activity
[-]pretender add component (pages) twice to the DOM[/-][+]prerender add component (pages) twice to the DOM[/+][-]prerender add component (pages) twice to the DOM[/-][+]prerender: component (pages) added twice to the DOM[/+][-]prerender: component (pages) added twice to the DOM[/-][+]prerender: rehydrated components (pages) added twice to the DOM[/+]Paul-Hebert commentedon May 13, 2020
@peterpeterparker , were you able to resolve this in your project? Any info on a workaround? Thanks!
peterpeterparker commentedon May 13, 2020
@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.
Paul-Hebert commentedon May 13, 2020
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!
peterpeterparker commentedon May 14, 2020
@Paul-Hebert sure
Paul-Hebert commentedon May 14, 2020
By the way, here's a simplified example that reproduces this issue for me:
My simplified components
My simplified document I'm hydrating
My Node/Express code running the hydrate script
(Though I see the same issue when prerendering instead of doing SSR)
The output
Note 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
c4-button, I get this similar but different issue. Now the duplicate buttons are nested:If anyone could point me towards a solution or something I'm doing wrong I'd really appreciate it.
I'd love to improve the performance of my Stencil app with preloading but this is a major blocker in that effort.
Thanks! 😁
Paul-Hebert commentedon May 26, 2020
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
sc-c4-container)Hopefully that extra detail is helpful 🙂
peterpeterparker commentedon Jun 10, 2020
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
c-idhas to be incrementedpeterpeterparker commentedon Jun 12, 2020
@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.
It is my try out to bring the subject forward.
fix(#2366): rehydrate slot child
fix(#2366): rehydrate slot child
peterpeterparker commentedon Jun 17, 2020
This should now be solved (any feedback appreciated).
The PR #2517 has been merged.
10 remaining items
peterpeterparker commentedon Jun 24, 2020
@Paul-Hebert cool, thx for the repo and details!
I can reproduce the problem too and do see why too
In the prerendered
index.htmlthe button is parser as followingbut its parent is
s-id=1. if I correct thec-idas followingthen prerendering works out. so the question is why
0.2instead of1.2.I've to add some console.log to stencil, let me try
peterpeterparker commentedon Jun 24, 2020
Ok so the PR I implemented kick in and calculate the right
c-idbut later it is overidden, not sure why yetpeterpeterparker commentedon Jun 24, 2020
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.
Paul-Hebert commentedon Jun 24, 2020
Awesome, thank you @peterpeterparker !
peterpeterparker commentedon Jun 26, 2020
@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
0.2to1.2or1.0.2. Therefore I do not what I am missing or if the indexing in the test can be updated. It needs input from the team, I do not want to submit a PR in which I modify all existing tests and break something.My solution would be the following. In vdom-annotations modify the
hostIdof theorgLocationNodesto not always be0be rather reflect thes-idof the node, if one was set duringparseVNodeAnnotations.Is:
My suggestion:
What do you think, works for you?
Paul-Hebert commentedon Jul 1, 2020
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!
peterpeterparker commentedon Jul 1, 2020
@Paul-Hebert no worries, busy too these days and next weekend too. Ping me when you've got time, no rush.
guidoknoll commentedon Jul 30, 2020
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.
Paul-Hebert commentedon Aug 3, 2020
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
build,build.prodandrelease.prepare. Each of these generated a/builddirectory with a different structure than I expected. It didn't match the structure of the Stencil Core in my project's Node Modules folder.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 Instead
I 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
NODE_TYPE.ElementNodeto1for this to work. Based on inline comments it looks like this change is automatically made during compilation.)Next Steps
Let 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!
peterpeterparker commentedon Aug 4, 2020
@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
buildorbuild:procommand.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 👍
Paul-Hebert commentedon Aug 5, 2020
Here you go @peterpeterparker: #2611
Thanks again for all your help!
peterpeterparker commentedon Aug 5, 2020
Nice @Paul-Hebert !
CollinHerber commentedon Jan 31, 2023
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.
This is what is observed
So based on this it does appear to be during the hydration of the component.
Edit2:
Further investigation suggests that this is only happening for component that have nested stencil components.
So the hydrated markup looks something like this
rwaskiewicz commentedon Feb 9, 2023
@CollinHerber can you do me a favor and please create a new issue with a reproduction case for the team and myself?
CollinHerber commentedon Feb 9, 2023
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.