[2.0.4] Nested Shadow DOM custom elements fail to upgrade in Safari when mounted inside non-custom-element templates

オープン
#5,249 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@akzarma がすでに取り組んでいます。

2026年11月30日 から。

  • #5274 @akzarma による — オープン

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
48/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
javascript, typescript
領域
frontend, web-dev

調査の方向性

Start by tracing template(html, flag) and its create() path in @solidjs/web, then inspect the generated templates in the linked Playground example. Reproduce in Safari 26+ and compare how cloned nodes are adopted before and after insertion into the document. Done when nested custom elements upgrade in Safari as they do in Chrome and Firefox without breaking standard template cloning.

索引モデルが issue の本文から書いたものです。

説明

Describe the bug

When a component renders a custom element (e.g. <x-outer />) inside a standard HTML element template from a parent component (e.g. <form><OuterField /></form>), any nested custom elements (<x-inner>) cloned inside <x-outer>'s Shadow DOM during its constructor() permanently fail to upgrade in Safari 26+ (inner.shadowRoot === null, inner.customElementRegistry === null).

Your Example Website or App

https://playground.solidjs.com/anonymous/59ad5fbf-f032-49ca-9e78-28632ddd6915

Steps to Reproduce the Bug or Issue
  1. Open https://playground.solidjs.com/anonymous/59ad5fbf-f032-49ca-9e78-28632ddd6915 in Safari 26+ (macOS).
  2. Observe the Preview pane:
    • "x-inner upgraded and rendered" is not rendered.
    • Output shows:
      {
        "innerUpgraded": false,
        "innerCustomElementRegistry": "null"
      }
      
  3. Open the exact same Playground URL in Chrome:
  • "x-inner upgraded and rendered" renders in green.
  • Output shows "innerUpgraded": true and "innerCustomElementRegistry": "[object CustomElementRegistry]".
Expected behavior

<x-inner> inside <x-outer>'s Shadow DOM should keep window.customElements as its customElementRegistry and upgrade when <form> is connected to document, matching Chrome and Firefox.

Screenshots or Videos

No response

Platform
  • SolidJS: 2.0.4 ([email protected], @solidjs/[email protected] — also affects solid-js/web 1.x template())
  • OS: macOS 26.5.1
  • Browser: Safari 26+ (AppleWebKit/605.1.15) — reproduces
  • Chrome 146 / Firefox 161 — works as expected
Additional context

Root cause in @solidjs/web

In @solidjs/web's template(html, flag):

  1. For standard HTML templates (flag !== 1, e.g. _$template("<form>")), create() leaves the prototype node inside t.content, so node.ownerDocument is the inert <template> document (customElementRegistry === null), and node.cloneNode(true) returns a detached element still owned by that inert document.
  2. For custom-element templates (flag === 1, e.g. _$template("<x-outer>", 1)), Solid calls document.importNode(node, true), instantiating and upgrading <x-outer> in the main document. During new XOuter(), this.attachShadow({ mode: "open" }).appendChild(innerTpl.content.cloneNode(true)) creates <x-inner> with customElementRegistry === window.customElements (not yet upgraded while <x-outer> is disconnected).
  3. When Solid inserts <x-outer> into the detached <form> (form.appendChild(outer)), <x-outer> is adopted into the inert <template> document, clearing <x-inner>.customElementRegistry to null.
  4. When <form> is later inserted into document.body, WebKit adopts <form> and <x-outer> back into document, but fails to restore customElementRegistry on unupgraded descendants inside <x-outer.shadowRoot> (<x-inner>.customElementRegistry stays null forever, so <x-inner> never upgrades).

(Note: <form><x-outer /></form> in a single JSX expression does not trigger this because the compiler merges them into _$template("<form><x-outer>", 1). Splitting <OuterField /> into a child component emits separate templates and triggers the bug.)

Possible fix
Ensure cached template prototype nodes in create() belong to document (e.g. document.adoptNode(node) when flag !== 1), so node.cloneNode(true) is already owned by document and never adopts children into an inert <template> document.

Temporary local fix

if (typeof window !== 'undefined' && 'customElementRegistry' in Element.prototype) {
  const cloneNode = Element.prototype.cloneNode;
  Element.prototype.cloneNode = function (deep?: boolean) {
    return this.ownerDocument !== document && this.ownerDocument.defaultView === null
      ? document.importNode(this, deep)
      : cloneNode.call(this, deep);
  };
}
主要言語
TypeScript
スター
37k
フォーク
1.2k
平均マージ
8時間 43分
マージ済み PR(30日)
365

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

solidjs/solid のほかの issue

solidjs/solid の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。