Skip to content

bug: hydrate crashes if head element with link tag exists #5870

Closed

Description

@mayerraphael

Prerequisites

Stencil Version

4.19.0

Current Behavior

Hydrate crashes if a full document is hydrated with serializeShadowRoot: false

unhandledRejection Error: referenceNode not found in parentNode.childNodes
    at insertBefore (C:\dev\ssr-stencil-test\dsd-ssr\hydrate\index.js:13860:15)
    at _MockDocument.insertBefore (C:\dev\ssr-stencil-test\dsd-ssr\hydrate\index.js:13071:7)
    at addStyle (C:\dev\ssr-stencil-test\dsd-ssr\hydrate\index.js:548:30)
    at attachStyles (C:\dev\ssr-stencil-test\dsd-ssr\hydrate\index.js:566:20)
    at updateComponent (C:\dev\ssr-stencil-test\dsd-ssr\hydrate\index.js:1175:5)
    at C:\dev\ssr-stencil-test\dsd-ssr\hydrate\index.js:1162:38
    at enqueue (C:\dev\ssr-stencil-test\dsd-ssr\hydrate\index.js:1167:6)
    at dispatchHooks (C:\dev\ssr-stencil-test\dsd-ssr\hydrate\index.js:1162:10)
    at dispatch (C:\dev\ssr-stencil-test\dsd-ssr\hydrate\index.js:1136:26)
    at C:\dev\ssr-stencil-test\dsd-ssr\hydrate\index.js:2039:7

This only happens if a <link ... > tag is inside the <head>

Happens inside the addStyle() -> insertBefore() method (see trace).

Expected Behavior

No crashes.

System Info

No response

Steps to Reproduce

  • See repo, set serializeShadowRoot to false in server.js.

Code Reproduction URL

https://github.com/mayerraphael/stencil-dsd-ssr-playground

Additional Information

server.js

const html = await hydrate.renderToString(
    `<html>
    <head>
      <link rel="stylesheet" href="whatever.css" >
    </head>

    <body>
      <div class="__next">
        <main>
          <my-component last-page="5"></my-component>
          <my-whatever-component>abc</my-whatever-component>
          <div class="my-5">
            <my-other-component label="2"></my-other-component>
          </div>
          <my-component last-page="2"></my-component>
        </main>
      </div>
    
      <script type="module">
          import { defineCustomElements } from "./static/loader/index.js";
          defineCustomElements().catch(console.error);
      </script>
    </body>
    </html>`,
    { fullDocument: true, serializeShadowRoot: false },
  );

Activity

  1. added
    Bug: Validated
    and removed on Jun 28, 2024
  2. christian-bromann commented on Jul 1, 2024

    @christian-bromann
    Member

    This should get resolved with #5876 which is currently being reviewed. You can use @stencil/[email protected] which is a dev release that contains this fix.

  3. ptmkenny commented on Jul 1, 2024

    @ptmkenny

    Since the Ionic starter apps have a <link> inside <head>, it would be great if there was an automated test against the starter apps to catch issues like this.

  4. christian-bromann commented on Jul 1, 2024

    @christian-bromann
    Member

    @ptmkenny thanks for the feedback @ptmkenny! We will evaluate this with the framework and Stencil team whether this is feasible for us as it requires running these starter apps with a custom compiled Ionic Framework version that uses a custom compiled Stencil version. Overall we have much better test coverage for these edge cases now which makes it less likely that these bugs happen again.

  5. christian-bromann commented on Jul 17, 2024

    @christian-bromann
    Member

    Closing as this has been resolved and was released with the last Stencil version.

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

Metadata

Metadata

Labels

Bug: Validated

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions