bug: mock-doc does not retarget composed events at shadow boundaries

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

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

まだ誰も着手していません。

評価

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

調査の方向性

Start by running the repro in src/testing/test/shadow-dom-events.spec.tsx with the fixture in src/testing/test/__fixtures__/shadow-events.tsx, which shows an outer listener receiving the inner element as event.target. The body says a fix already exists in #7008, so check that PR first, since the work is under way. Done means outer listeners see the shadow host as event.target, inner listeners still see the original target, and any existing spec expectations that depended on the old value are updated.

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

説明

Prerequisites
Stencil Version

4.45.3 (current main)

Current Behavior

When a composed event bubbles out of a shadow tree in mock-doc, listeners outside that tree see the element the event was dispatched on as event.target. A browser retargets the event to the shadow host at every boundary it crosses.

Expected Behavior

Listeners outside a shadow tree see the shadow host as event.target, like in a browser. Listeners inside the tree keep seeing the original target.

System Info
Not environment specific, mock-doc behavior.
Steps to Reproduce

Two nested shadow components, event-wrapper-component renders event-inner-component:

const page = await newSpecPage({
  components: [EventWrapperComponent, EventInnerComponent],
  html: '<event-wrapper-component></event-wrapper-component>',
});
let target: any;
page.root.addEventListener('customclick', (ev: any) => (target = ev.target));

const inner = page.root.shadowRoot.querySelector('event-inner-component');
inner.dispatchEvent(new CustomEvent('customclick', { bubbles: true, composed: true }));

expect(target).toBe(inner); // passes on main, a browser gives you page.root
Code Reproduction URL

https://github.com/stenciljs/core/pull/7008 (src/testing/test/shadow-dom-events.spec.tsx and src/testing/test/__fixtures__/shadow-events.tsx)

Additional Information

This is not #4618. That one asks whether the event reaches the wrapper at all, and it does since #6301.

Fixing this changes what existing spec tests observe. A test that currently expects the inner element as event.target on an outer listener will fail afterwards, even though the new value is the correct one.

I have a fix in #7008.

主要言語
TypeScript
スター
13.2k
フォーク
865
平均マージ
2日 16時間
マージ済み PR(30日)
29

環境構築

はじめの一歩

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

stenciljs/core のほかの issue

stenciljs/core の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

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

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