You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
bug: mock-doc does not retarget composed events at shadow boundaries #7012
I have searched for existing issues that already report this problem, without success.
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:
constpage=awaitnewSpecPage({components: [EventWrapperComponent,EventInnerComponent],html: '<event-wrapper-component></event-wrapper-component>',});lettarget: any;page.root.addEventListener('customclick',(ev: any)=>(target=ev.target));constinner=page.root.shadowRoot.querySelector('event-inner-component');inner.dispatchEvent(newCustomEvent('customclick',{bubbles: true,composed: true}));expect(target).toBe(inner);// passes on main, a browser gives you page.root
Code Reproduction URL
#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.
Activity
test(mock-doc): pin the original target inside the dispatching shadow…