Skip to content

Commit

Permalink
fix(renderer): fix missing slot ref callback handling
Browse files Browse the repository at this point in the history
fixes one of the issues raised in ionic-team#5335

adds a new internal variable which is stored during vnode rendering to reuse it within the relocatedNodes logic
  • Loading branch information
yigityuce committed Feb 7, 2024
1 parent 147dfe6 commit 8016227
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/declarations/stencil-private.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1331,6 +1331,12 @@ export interface RenderNode extends HostElement {
*/
host?: Element;

/**
* On Ref Function:
* Callback function to be called when the slotted node ref is ready.
*/
['s-rf']?: (elm: Element) => unknown;

/**
* Is initially hidden
* Whether this node was originally rendered with the `hidden` attribute.
Expand Down
1 change: 1 addition & 0 deletions src/runtime/dom-extras.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export const patchCloneNode = (HostElementPrototype: HTMLElement) => {
's-ol',
's-nr',
's-si',
's-rf',
];

for (; i < srcNode.childNodes.length; i++) {
Expand Down
5 changes: 5 additions & 0 deletions src/runtime/vdom/vdom-render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ const createElm = (oldParentVNode: d.VNode, newParentVNode: d.VNode, childIndex:
// remember the slot name, or empty string for default slot
elm['s-sn'] = newVNode.$name$ || '';

// remember the ref callback function
elm['s-rf'] = newVNode.$attrs$?.ref;

// check if we've got an old vnode for this slot
oldVNode = oldParentVNode && oldParentVNode.$children$ && oldParentVNode.$children$[childIndex];
if (oldVNode && oldVNode.$tag$ === newVNode.$tag$ && oldParentVNode.$elm$) {
Expand Down Expand Up @@ -1094,6 +1097,8 @@ render() {
}
}
}

nodeToRelocate && typeof slotRefNode['s-rf'] === 'function' && slotRefNode['s-rf'](nodeToRelocate);
} else {
// this node doesn't have a slot home to go to, so let's hide it
if (nodeToRelocate.nodeType === NODE_TYPE.ElementNode) {
Expand Down

0 comments on commit 8016227

Please sign in to comment.