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

feat(slot-polyfill): patch insertBefore & slotted node parentNode #6096

Merged
merged 4 commits into from
Jan 16, 2025

Conversation

johnjenkins
Copy link
Contributor

@johnjenkins johnjenkins commented Jan 15, 2025

What is the current behavior?

Frameworks insert nodes into and remove nodes from Stencil components.

When shadow: false a method like stencilCmp.insertBefore(newNode, anotherSlottedNode) will either fail (because anotherSlottedNode is not a direct descendent of stencilCmp) or be incorrect (stencilCmp.insertBefore(newNode, null) will just insert a node into the start of the component which is not where the original <slot /> is)

Additionally, when deciding where to insert a node, a framework will simply do currentNode.parentNode < and insert a newNode before it.
This again, can be incorrect; if currentNode.parentNode has slot="header" but the incoming newNode has slot="footer" then newNode will be inserted into the wrong position.

GitHub Issue Number:

Closes #6043

What is the new behavior?

// stencil.config.ts
...
extras: {
  experimentalSlotFixes: true
}

Will now also patch a polyfilled Stencil component's .insertBefore() method and any slotted node's .parentNode accessor.

Any direct call to insertBefore on a component now appropriatly slots the incoming node.

Any call to a current slotted node's parentNode will return the Stencil component host.

Documentation

Does this introduce a breaking change?

  • Yes
  • No

Testing

  • New unit tests
  • New component tests

Other information

As per precedent, __insertBefore on the component and __parentNode on the slotted node, provides access to the original, unpatched method / accessor.

@johnjenkins johnjenkins changed the title feat(slot-polyfill): patch insertBefore & slotted parentNode feat(slot-polyfill): patch insertBefore & slotted node parentNode Jan 15, 2025
@johnjenkins johnjenkins marked this pull request as ready for review January 16, 2025 01:04
@johnjenkins johnjenkins requested a review from a team as a code owner January 16, 2025 01:04
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.

LGTM 👍

@christian-bromann
Copy link
Member

Will merge this once the build is 🟢 again

@christian-bromann christian-bromann merged commit efb40d5 into stenciljs:main Jan 16, 2025
72 checks passed
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: Incorrect slotting with Angular's conditional rendering, 'shadow:false' and named slots.
2 participants