bug: v5 streamed SSR host is released too early when a script inserts a node while it is parsed
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 55/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- typescript
調査の方向性
Start by reading packages/core/src/runtime/parse-gate.ts, especially isParsed() and flush(), and compare the three streaming cases in the linked reproduction. Trace how document mutations can release hosts while parsing is paused. Done means all three pages retain the expected light DOM and shadow root without duplicate rendering or a declarative shadow root warning; add or run focused coverage for those cases.
索引モデルが issue の本文から書いたものです。
説明
Stencil Version
5.0.0-rc.12
Current Behavior
The parse gate for streamed server markup (#7005) releases a host too early when a script inserts a node into the document while the parser is still inside that host.
The gate treats a host as parsed once the host or one of its ancestors has a next sibling. A node that a script appends to an ancestor, e.g. document.body.appendChild(container) for a portal, a toast container or a script tag, is such a sibling, although the parser has not finished the host.
Depending on where the parser is at that moment:
- Before the
<template shadowrootmode>of the host: Stencil attaches its own shadow root, and the parser can no longer attach the declarative one. Chromium logsA second declarative shadow root cannot be created on a host, the<template>stays in the light DOM of the host, and the component renders on the client instead of hydrating. This is the outcome #6690 describes. - Inside the
<template>: Stencil hydrates the part of the shadow root that has arrived and renders the rest. The parser then appends the rest of the server markup to the same nodes, so the content is there twice.
The parser stops inside a host whenever a chunk of the response ends there, so this needs no unusual markup, only a script that runs in that pause.
Expected Behavior
A host is held until the parser has finished it, whatever scripts do to the document meanwhile. In the reproduction all three pages should end like control:
light DOM children of the host: span
shadow root: <div><p>Server label</p><slot></slot></div>
System Info
System: node 22.21.0
Platform: darwin (27.0.0)
CPU Model: Apple M2 Pro (12 cpus)
Stencil: 5.0.0-rc.12 🔈
TypeScript: 6.0.3
Rolldown: 1.3.3
Terser: 5.51.4
Browsers: Chromium and WebKit (Playwright 1.63)
Steps to Reproduce
- Clone https://github.com/henrijoss/stencil-v5-repros and run
npm install npm install @stencil/[email protected](the repository is pinned to rc.10, which behaves the same)npm start --workspace=ssr-streamingand open http://localhost:3336- Open
control,insert-before-templateandinsert-inside-template
The project has a loader-bundle and an ssr output target. The server renders <repro-ssr label="Server label"><span>Slotted</span></repro-ssr> with renderToString(), starts the response, waits until the component is defined, sends the markup up to the middle of the host, and sends the rest once the script of the page has run. Each page prints the light DOM children and the shadow root of the host:
control, nothing is inserted:
light DOM children of the host: span
shadow root: <div><p>Server label</p><slot></slot></div>
insert-before-template, the page appends a <div> to <body> after the opening tag of the host has arrived:
light DOM children of the host: template, span
shadow root: <div><p>Server label</p><slot></slot></div>
plus A second declarative shadow root cannot be created on a host. in the console of Chromium.
insert-inside-template, the same after <template shadowrootmode="open"><div c-id="…"> has arrived:
light DOM children of the host: span
shadow root: <div><p>Server label</p><slot></slot><p c-id="3.1.1.0"><!--t.3.2.2.0-->Server label</p><slot c-id="3.3.1.1"></slot></div>
Code Reproduction URL
https://github.com/henrijoss/stencil-v5-repros/tree/main/ssr-streaming
Additional Information
The check is isParsed() in packages/core/src/runtime/parse-gate.ts:
const isParsed = (elm) => {
if (win.document.readyState !== 'loading') return true;
for (let n = elm; n; n = parentOf(n)) if (n.nextSibling) return true;
return false;
};
A next sibling only proves that the parser has moved on when the parser inserted it. flush() runs for every mutation of the document, so the first mutation after such an insertion releases every host that is still open below that ancestor.
I have not tried a fix. A signal that scripts of the page can't produce by accident would close it, e.g. a marker the server writes as the last node of a host, or of its template.
This is not a regression from Stencil 4, which has no parse gate and always fails for markup that is streamed after the components are defined (#6690). It is a gap in the fix for that.
I found no existing issue for this.
- 主要言語
- TypeScript
- スター
- 13.2k
- フォーク
- 870
- 平均マージ
- 2日 54分
- マージ済み PR(30日)
- 50
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
stenciljs/core のほかの issue
-
bug: v5 dist/types/components.d.ts imports @stencil/core/runtime instead of ./stencil-public-runtimeオープン
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
メンテナーはふだん 1 日以内に返信
-
Stencil FOUC styles should use @layer to avoid cascade conflicts with React 19対応中かも @johnjenkins が 241 日前に担当しました。 オープンStencil v5
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
メンテナーはふだん 1 日以内に返信
-
feat: write reflected attributes when the prop changes, not on the next render対応中かも @johnjenkins が 241 日前に担当しました。 オープンStencil v5
難易度 4/5 3〜5日 初心者へのやさしさ 22/100
メンテナーはふだん 1 日以内に返信
-
難易度 3/5 1〜2日 初心者へのやさしさ 35/100
メンテナーはふだん 1 日以内に返信
-
feat: css source map support対応中かも @Elements2720 が 37 日前に担当しました。 オープンFeature: Want this? Upvote it!
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
stenciljs/core#6964 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
posit-dev/positron-sas-extension#196 ·
メンテナーはふだん 1 日以内に返信
-
bug composer
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
inmanta/web-console#8037 ·
メンテナーはふだん 1 日以内に返信
-
check:passed streams:add
難易度 2/5 1〜3時間 初心者へのやさしさ 67/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
メンテナーはふだん 1 日以内に返信