Skip to content

fix(#2366): rehydrated components added twice - #2508

Closed
peterpeterparker wants to merge 3 commits into
stenciljs:masterfrom
peterpeterparker:rehydrated-components-added-twice
Closed

peterpeterparker wants to merge 3 commits into
stenciljs:masterfrom
peterpeterparker:rehydrated-components-added-twice

Conversation

@peterpeterparker

Copy link
Copy Markdown
Contributor

Introduction

This is my suggestion to solve #2366. I am honestly not sure it is the proper solution and would appreciate any hints.

I am also not against that PR being rejected as long as the problem, I communicated in April 2020, finds a solution.

Indeed I am not able to upgrade our applications and therefore are kind of blocked with Stencil v1.8. I would be really happy to upgrade.

Moreover, I noticed that prerendering solved would enhance by more than 10% our load time, therefore, more really more than in need and looking forward to a solution.

Current behavior:

With prerendering, components are not rehydrated and are added twice to the DOM

Expected behavior:

Components are rehydrated with a single instance to the DOM

Root cause of issue

I mostly tested the issue with the ion-router, more precisely noticed the issue with the ion-nav and a "page" (app-home) being added twice two the DOM.

I did a comparison with the Stencil router, with which I did not face the issue, and noticed that the root case was the missing component reference (c-id).

Concretely, currently these elements would be prerendered as following:

<ion-nav s-id=14>
     <!--s.14.0.0.0.-->
     <app-home s-id=15>

But if they would be added as following, then the issue would be solved:

<ion-nav s-id=14>
     <!--s.14.0.0.0.-->
     <app-home s-id=15 c-id=14.0.0.1>

Adding c-id=14.0.0.1 was the solution here.

A spent some time debugging vdom-annotation.ts and figured out that this "missing annotation" was a result of the VDOM representation.

Indeed, if the ion-nav is referenced as parent of the app-home, the contrary was not correct, the app-home was not referenced as child of the ion-nav but its slot.

ion-nav element:

ion-app
    ion-nav
        slot

app-home element:

ion-nav
    app-home
         ion-content

Suggestion of solution

As both elements are kind of not fully linked, my idea is to add a post processing to the insertion of the annotation which checks if the node as received a c-id and if not, as a a parent which contains a comment for the slot. If so, it calculate the c-id and adds the attribute

Conclusion

As I said in my introduction, my solution might not be correct, it of course works out according my tests but you might find some reason why not. In such case, I am not against rejecting this PR, a cool, but would really, really appreciate if we can move forward with prerendering while using the Ionic Router.

@manucorporat

Copy link
Copy Markdown
Contributor

Thanks a lot for the PR! it was merge in this commit: e152773

@peterpeterparker

Copy link
Copy Markdown
Contributor Author

Awesome! Thx :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants