Skip to content

bug: @stencil/ssr package with Next.js streaming outputs error #693

@henrijoss

Description

@henrijoss

Prerequisites

Stencil Version

4.27.1

Stencil Framework Output Target

React

Stencil Framework Output Target Version

1.2.0

Current Behavior

When using the @stencil/ssr package with Next.js streaming a console error is logged:

A second declarative shadow root cannot be created on a host.

Expected Behavior

No console error.

Steps to Reproduce

Add a dynamic react server component containing a stencil web component which will resolve after a couple of seconds:

import { MyComponent } from 'component-library-react';

import { headers } from 'next/headers';

const wait = (ms: number) => new Promise((res) => setTimeout(res, ms));

export default async function AsyncTest() {
  // Force dynamic rendering
  const _ = await headers();
  await wait(3000);

  return (
    <>
      Async Data <MyComponent first="Stencil" last="'Don't call me a framework' JS" className="my-8" />
    </>
  );
}

Wrap the component in a Suspense boundary:

import { Suspense } from 'react';
import AsyncTest from '../../components/AsyncTest';

export default function Home() {
  return (
    <>
      <Suspense fallback="Loading...">
        <AsyncTest />
      </Suspense>
    </>
  );
}

Code Reproduction URL

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions