Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: patchChildSlotNodes & scopedSlotTextContentFix not being applied #6055

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

johnjenkins
Copy link
Contributor

@johnjenkins johnjenkins commented Nov 22, 2024

What is the current behavior?

GitHub Issue Number: #6054

TLDR ... customElement.childNodes, customElement.children monkey-patches are never actually switched-on in Stencil atm. scopedSlotTextContentFix doesn't fully patch the textContent.

...

Contrary to documentation, the experimentalSlotFixes or slotChildNodesFix flags have no affect on the childNodes or children accessors. The patches are only applied if the deprecated needsShadowDomShim flag is fulfilled.

This must be a mistake / a hangover from supporting legacy browsers.

Additionally scopedSlotTextContentFix alone doesn't fully patch the host.textContent accessor. It adds a half-way patch - which I believe to be more confusing than useful.

To get the full textContent patch users much add both experimentalScopedSlotChanges AND scopedSlotTextContentFix (experimentalScopedSlotChanges alone won't add ANY patch).

What is the new behavior?

Adding experimentalSlotFixes or slotChildNodesFix now patches childNodes, children and childElementCount - they only return the nodes / elements that have been slotted - not the items within the component internals. This more closely mimics shadowRoot enabled components.

I have removed the experimentalScopedSlotChanges for the textContent patch.
Users need only apply scopedSlotTextContentFix or the unified experimentalSlotFixes.

Additionally, I have rolled-in the experimentalScopedSlotChanges flag within the unified experimentalSlotFixes flag - I believe this makes sense as experimentalScopedSlotChanges will eventually be 'on' by default.

Documentation

Does this introduce a breaking change?

  • Yes
  • No

Testing

  • Added some spec tests for dom-extras.
  • Amended wdio tests (e.g. the text-content-patch test now only tests for the slotted text and doesn't return internal text)
  • I made some flaky wdio tests slightly more reliable on my local machine. Happy to remove these as out-of-scope.

Other information

Making these changes did open a slight a can of worms because the codebase has never actually dealt with host.childNodes being monkey patched; everything assumes it will return a full list of component internals...

  • Within non-shadow vdom slot handling
  • Within other monkey-patched methods
  • Within wdio tests

To fix this, using the precedent of appendChild (and similar methods) within dom-extras.ts, I have added a __childNodes accessor to return a component's 'internal' nodes.

@johnjenkins johnjenkins requested a review from a team as a code owner November 22, 2024 14:48
@johnjenkins johnjenkins changed the title fix: patchChildSlotNodes not being applied properly fix: patchChildSlotNodes not being applied Nov 22, 2024
@johnjenkins johnjenkins marked this pull request as draft November 22, 2024 15:11
@johnjenkins johnjenkins marked this pull request as ready for review November 24, 2024 01:57
@johnjenkins johnjenkins changed the title fix: patchChildSlotNodes not being applied fix: patchChildSlotNodes & scopedSlotTextContentFix not being applied Nov 24, 2024
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.

1 participant