Skip to content

Commit

Permalink
fix(runtime): add missing insertBefore patches
Browse files Browse the repository at this point in the history
  • Loading branch information
yigityuce committed May 10, 2024
1 parent f434429 commit 8777dc8
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/runtime/connected-callback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { createTime } from './profile';
import { HYDRATE_ID, NODE_TYPE, PLATFORM_FLAGS } from './runtime-constants';
import { addStyle } from './styles';
import { attachToAncestor } from './update-component';
import { insertBefore } from './vdom/vdom-render';

export const connectedCallback = (elm: d.HostElement) => {
if ((plt.$flags$ & PLATFORM_FLAGS.isTmpDisconnected) === 0) {
Expand Down Expand Up @@ -128,5 +129,5 @@ const setContentReference = (elm: d.HostElement) => {
BUILD.isDebug ? `content-ref (host=${elm.localName})` : '',
) as any);
contentRefElm['s-cn'] = true;
elm.insertBefore(contentRefElm, elm.firstChild);
insertBefore(elm, contentRefElm, elm.firstChild);
};
2 changes: 1 addition & 1 deletion src/runtime/dom-extras.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ export const patchTextContent = (hostElementPrototype: HTMLElement): void => {
this.__textContent = value;
const contentRefElm = this['s-cr'];
if (contentRefElm) {
this.insertBefore(contentRefElm, this.firstChild);
insertBefore(this, contentRefElm, this.firstChild);
}
}
},
Expand Down
5 changes: 3 additions & 2 deletions src/runtime/vdom/vdom-annotations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
SLOT_NODE_ID,
TEXT_NODE_ID,
} from '../runtime-constants';
import { insertBefore } from './vdom-render';

/**
* Updates the DOM generated on the server with annotations such as node attributes and
Expand Down Expand Up @@ -58,7 +59,7 @@ export const insertVdomAnnotations = (doc: Document, staticComponents: string[])
}
const commentBeforeTextNode = doc.createComment(childId);
commentBeforeTextNode.nodeValue = `${TEXT_NODE_ID}.${childId}`;
nodeRef.parentNode?.insertBefore(commentBeforeTextNode, nodeRef);
insertBefore(nodeRef.parentNode, commentBeforeTextNode, nodeRef);
}
}

Expand Down Expand Up @@ -220,7 +221,7 @@ const insertChildVNodeAnnotations = (
const textNodeId = `${TEXT_NODE_ID}.${childId}`;

const commentBeforeTextNode = doc.createComment(textNodeId);
parentNode?.insertBefore(commentBeforeTextNode, childElm);
insertBefore(parentNode, commentBeforeTextNode, childElm);
}
} else if (childElm.nodeType === NODE_TYPE.CommentNode) {
if (childElm['s-sr']) {
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/vdom/vdom-render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -930,7 +930,7 @@ export const insertBefore = (parent: Node, newNode: Node, reference?: Node): Nod
return inserted;
};

const findParentScopeId = (element: any): any => {
const findParentScopeId = (element: d.RenderNode): string | undefined => {
return element
? element['s-rsc'] || element['s-si'] || element['s-sc'] || findParentScopeId(element.parentElement)
: undefined;
Expand Down

0 comments on commit 8777dc8

Please sign in to comment.