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

Merged

Conversation

johnjenkins
Copy link
Contributor

@johnjenkins johnjenkins commented Nov 22, 2024

What is the current behavior?

GitHub Issue Number: Fixes #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 effect 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

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
@johnjenkins
Copy link
Contributor Author

johnjenkins commented Nov 26, 2024

@christian-bromann any insight into the erroring windows unit test?
i.e. Is it genuine or just a flaky, one-off thing?
🤞for the latter as I don't have an easy way of running a comparable windows vm :D

EDIT
As per comments here < pretty sure it's my use of beforeAll (it's the only jest beforeAll in the codebase so makes sense :) - refactored)

@christian-bromann
Copy link
Member

i.e. Is it genuine or just a flaky, one-off thing?

unfortunately yes, I feel like it may be worth transitioning to Vitest but I haven't had the time to look into that nor find out why it is throwing that error.

Copy link
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.

Awesome stuff 👏

@christian-bromann christian-bromann added this pull request to the merge queue Nov 26, 2024
Merged via the queue into ionic-team:main with commit a15bc5d Nov 26, 2024
88 checks passed
@johnjenkins johnjenkins deleted the chore-remove-shadowDomShim branch November 26, 2024 19:31
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.

bug: experimentalSlotFixes (and slotChildNodesFix / scopedSlotTextContentFix) broken
2 participants