Skip to content

Comments

fix: guard attachShadow call for SSR DOMs without native support#6609

Open
tysoncung wants to merge 1 commit intostenciljs:mainfrom
tysoncung:fix/ssr-attach-shadow-guard
Open

fix: guard attachShadow call for SSR DOMs without native support#6609
tysoncung wants to merge 1 commit intostenciljs:mainfrom
tysoncung:fix/ssr-attach-shadow-guard

Conversation

@tysoncung
Copy link

Problem

When using Stencil's hydrate runtime with server-side DOM implementations that don't provide attachShadow (e.g., Domino used by Angular SSR), the hydration process crashes with:

TypeError: this.attachShadow is not a function
    at createShadowRoot ...
    at proxyHostElement ...

This affects Angular SSR + Ionic applications where @angular/ssr uses Domino as its DOM implementation.

Fix

Added a typeof guard in createShadowRoot() (src/utils/shadow-root.ts) that checks whether attachShadow is available on the host element before calling it. When it's missing (SSR environments), the function returns early, allowing hydration to continue without crashing.

This is a minimal, safe change — in browser environments attachShadow is always available so the guard is never hit. In SSR environments, the shadow root simply isn't created, which matches the expected SSR behavior (shadow roots are typically handled during client-side hydration).

Call path

proxyHostElement()createShadowRoot.call(elm, cmpMeta)this.attachShadow(opts) 💥

After fix: this.attachShadow checked first → early return if missing → no crash.

Fixes #6605

Server-side DOM implementations like Domino do not provide
attachShadow on host elements, causing hydration to crash with
'TypeError: this.attachShadow is not a function'.

Add a typeof check before calling attachShadow so hydration can
continue gracefully in environments where shadow DOM is unavailable.

Fixes stenciljs#6605
@tysoncung tysoncung requested a review from a team as a code owner February 23, 2026 05:54
@johnjenkins
Copy link
Contributor

Hey @tysoncung thanks for raising
But I don’t think this will help really. It will just cause the components to fail silently (as opposed to noisily)

@tysoncung
Copy link
Author

Thanks for the feedback! Good point - silently skipping isn't ideal.

What would be the preferred approach here? A few options I can think of:

  1. Polyfill attachShadow on the server side so components still get a shadow root
  2. Use a declarative shadow DOM approach for SSR contexts
  3. Something else entirely?

Happy to rework this based on the team's direction.

@johnjenkins
Copy link
Contributor

You’re an ai agent, right?
attachShadow is already polyfilled in Stencil’s usual server DOM solution.
The issue is with Domino (whose last update was 6 years ago).

I wonder if there’s an opportunity for users to patch Domino before attempting to SSR components.

Take a look at some example code at https://github.com/ionic-team/ionic-framework/blob/main/packages/angular-server/src/ionic-server-module.ts is there a potential call site users can use to patch Domino (the underlying Angular DOM implementation)?
Post your code here.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: Hydrate runtime crashes with external SSR DOMs that do not implement attachShadow (Angular SSR + Domino)

2 participants