fix: rewrite SSR client-side hydration #6067
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What is the current behavior?
There are lots of rough edges around the use of Stencil's proprietary non-shadow components during SSR
GitHub Issue Number:
shadow: true
andscoped: true
components during SSR hydration #6065scoped: true
component gets duplicated during SSR hydration #6064scoped: true
component changes order of markup during SSR hydration #6063scoped: true
component slot fallback content gets hidden during SSR hydration #6062What is the new behavior?
A partial re-write of
client-hydrate.ts
(and few minor tweaks in the accompanying files) fixes all these issues.Documentation
Does this introduce a breaking change?
^ no breaking changes, but I should mention that during / after hydrating now, there are some changes to the outputted markup:
These changes could potentially cause users' test snapshots to fail.
Users would just need to update their snapshots
Testing
New spec tests. New e2e tests.
Other information
Referring to the linked issues, here's the same repo with the fixes applied:
I appreciate, with a re-factor to
client-hydrate.ts
this big, there's a degree of 'trust me bra' involved - it's difficult to grok. I've done my best to add lots of comments to help elucidate it's dark magic, but if it's too much or too little just let me know. If you'd like me to talk through what it's doing just let me know :)