fix(SSR): patch scoped: true
SSR-ed, slotted nodes next/prev sibling accessors
#6057
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?
Stencil
scoped: true
components don't do enough work to hide their internals from the browser. This can cause hydration errors when using SSR via meta-frameworks (nuxt, next etc).GitHub Issue Number:
Fixes #6056
What is the new behavior?
As well as
childNodes
,children
&childElementCount
being patched viaexperimentalSlotFixes
(orslotChildNodesFix
),firstChild
andlastChild
accessors are now patched too; only returning slotted nodes.Additionally, SSR slotted node accessors
nextSibling
,nextSiblingElement
,previousSibling
.previousSiblingElement
are also patched, only returning 'lightDOM' nodes.Documentation
Does this introduce a breaking change?
Testing
Other information
Meta-frameworks (during SSR hydration) reconcile their DOM to check for rendering errors.
Typically this involves stepping over each node in the real DOM and comparing it with the expected output from the framework's VDOM.
When mis-matches are found, the existing SSR rendered nodes are removed and the client-side rendered nodes inserted instead, causing more work for the client runtime, a longer TTI and in Stencil's case, components that are broken.
This is an excerpt from Vue's hydration script: