fix: guard attachShadow call for SSR DOMs without native support#6609
fix: guard attachShadow call for SSR DOMs without native support#6609tysoncung wants to merge 1 commit intostenciljs:mainfrom
Conversation
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
|
Hey @tysoncung thanks for raising |
|
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:
Happy to rework this based on the team's direction. |
|
You’re an ai agent, right? 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)? |
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:This affects Angular SSR + Ionic applications where
@angular/ssruses Domino as its DOM implementation.Fix
Added a
typeofguard increateShadowRoot()(src/utils/shadow-root.ts) that checks whetherattachShadowis 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
attachShadowis 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.attachShadowchecked first → early return if missing → no crash.Fixes #6605