Skip to content

fix(mock-doc): ensure event bubbling follows shadow DOM boundaries#6301

Merged
christian-bromann merged 2 commits intostenciljs:mainfrom
stout-ni:fix/mock-doc-event
Jun 16, 2025
Merged

fix(mock-doc): ensure event bubbling follows shadow DOM boundaries#6301
christian-bromann merged 2 commits intostenciljs:mainfrom
stout-ni:fix/mock-doc-event

Conversation

@stout-ni
Copy link
Copy Markdown
Contributor

@stout-ni stout-ni commented Jun 15, 2025

What is the current behavior?

MockDoc bubbles DOM events to parentElement every time during simulation, completely ignoring the special boundary rules of the Shadow DOM. For example, with the following DOM structure:

parent-host (Shadow Host)
  └── #shadow-root (Shadow Root) 
      └── child-host

When the event bubbles from the child-host, its parentElement is null, but its container is the shadow-root, and shadow-root.host points to the parent-host.

GitHub Issue Number: #5676

What is the new behavior?

According to the W3C specification, when the event is set to composed: true, it can cross Shadow DOM boundaries.

Therefore, for the DOM structure example above, the correct bubbling path should be: child → shadow-root → shadow-host → parent.

Documentation

Does this introduce a breaking change?

  • Yes
  • No

Testing

Test Coverage:

Added consistency test: New test src/mock-doc/test/shadow-dom-event-bubbling.spec.ts.

Test Results:

✅ All 3 tests in the modified test file pass

Manual Verification:

In this minimal reproducible example, after linking @stencil/core and re-running npm run test, the previously failing test case my-parent: logs 3 separate steps to the console has now succeeded.

Other information

@stout-ni stout-ni requested a review from a team as a code owner June 15, 2025 08:50
@stout-ni stout-ni closed this Jun 16, 2025
@stout-ni stout-ni reopened this Jun 16, 2025
Copy link
Copy Markdown
Member

@christian-bromann christian-bromann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants