Skip to content

bug: ssr. Incorrect slotted node order with serializeShadowRoot: 'scoped' #6293

@johnjenkins

Description

@johnjenkins

Prerequisites

Stencil Version

latest

Current Behavior

When slotted nodes are nested in 2 (or more) components deep and rendered via serializeShadowRoot: 'scoped' the original node order will be lost; instead taking the order of the <slot /> elements within the component.
Visually, this doesn't impact anything however it can cause hydration errors in meta frameworks (e.g. nuxt / next etc).

Given the following outer markup:

<cmp-parent>
  <cmp-child>
    <p slot="two">Slot 2</p> <!-- should be first in the final dom  --!>
    <p slot="one">Slot 1</p>  <!-- should be second in final dom  --!>
  </cmp-child>
</cmp-parent>

returns the following:

Image

pay special attention to

<!--o.0.5.-->
<!--o.0.7.-->
...
<p c-id="0.7" slot="one">Slot 1</p>
<p c-id="0.5" slot="two">Slot 2</p>

The comments match the slotted nodes and represent the original order of the nodes: 5 first, 7 second.

However the final result shows slot 'one' is first and 'two' second - not the order they were originally

Image

Expected Behavior

The original order should be preserved in the final hydrated DOM

System Info

Steps to Reproduce

pnpm i
pnpm build
pnpm express

Code Reproduction URL

https://github.com/johnjenkins/stencil-start-m6opf9rg

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bug: ValidatedThis PR or Issue is verified to be a bug within StencilHelp Wanted

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions