feat(slot-polyfill): patch insertBefore & slotted node parentNode #6096
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What is the current behavior?
Frameworks insert nodes into and remove nodes from Stencil components.
When
shadow: false
a method likestencilCmp.insertBefore(newNode, anotherSlottedNode)
will either fail (becauseanotherSlottedNode
is not a direct descendent ofstencilCmp
) 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 anewNode
before it.This again, can be incorrect; if
currentNode.parentNode
hasslot="header"
but the incomingnewNode
hasslot="footer"
thennewNode
will be inserted into the wrong position.GitHub Issue Number:
Closes #6043
What is the new behavior?
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?
Testing
Other information
As per precedent,
__insertBefore
on the component and__parentNode
on the slotted node, provides access to the original, unpatched method / accessor.