fix(runtime): create unique host ids #6018
Merged
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?
When hydrating components in e.g. Next.js we usually never hydrate the whole application at once and instead each individual component on its own. For example given the following example:
Our SSR logic for React and Next.js that is responsible for server side rendering the component would be first called on the
<cmp-a />
element. As many components introspect their light dom for rendering, what we are trying to do is to resolve the light dom as part of the process. At this point we would get the correct assignment of host ids as seen above.However, Next.js then goes through each individual component again to render it in a new context. It then replaces the result of that rendering with the previous generated code, ultimately responding the following to the server:
This particularly happens if you have components with ShadowRoots within the Light Dom of another component with ShadowRoot.
What is the new behavior?
For all hydration functions Stencil provides, e.g.
hydrateDocument
,renderToString
,serializeDocumentToString
andstreamToString
, we attach a uniquedocData
object to the document that allows us to continue the host id count throughout multiple hydration calls.Documentation
Does this introduce a breaking change?
Testing
n/a
Other information
n/a