Skip to content

Commit a1f7314

Browse files
committed
feat(cursors): pass container to vnode functions
1 parent c366b10 commit a1f7314

File tree

8 files changed

+132
-96
lines changed

8 files changed

+132
-96
lines changed

packages/qwik/src/core/client/dom-container.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,7 @@ export function getDomContainer(element: Element): IClientContainer {
7373

7474
export function getDomContainerFromQContainerElement(qContainerElement: Element): IClientContainer {
7575
const qElement = qContainerElement as ContainerElement;
76-
let container = qElement.qContainer;
77-
if (!container) {
78-
container = new DomContainer(qElement);
79-
}
80-
return container;
76+
return (qElement.qContainer ||= new DomContainer(qElement));
8177
}
8278

8379
/** @internal */

packages/qwik/src/core/client/vnode-diff.ts

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,7 @@ export const vnode_diff = (
498498
if (vProjectedNode == null) {
499499
// Nothing to project, so render content of the slot.
500500
vnode_insertBefore(
501+
container,
501502
vParent as ElementVNode | VirtualVNode,
502503
(vNewNode = vnode_newVirtual()),
503504
vCurrent && getInsertBefore()
@@ -512,6 +513,7 @@ export const vnode_diff = (
512513
} else {
513514
// move from q:template to the target node
514515
vnode_insertBefore(
516+
container,
515517
vParent as ElementVNode | VirtualVNode,
516518
(vNewNode = vProjectedNode),
517519
vCurrent && getInsertBefore()
@@ -544,7 +546,7 @@ export const vnode_diff = (
544546
continue;
545547
}
546548
cleanup(container, vNode);
547-
vnode_remove(vParent, vNode, true);
549+
vnode_remove(container, vParent, vNode, true);
548550
}
549551
vSideBuffer.clear();
550552
vSideBuffer = null;
@@ -589,7 +591,7 @@ export const vnode_diff = (
589591
cleanup(container, vChild);
590592
vChild = vChild.nextSibling as VNode | null;
591593
}
592-
vnode_truncate(vCurrent as ElementVNode | VirtualVNode, vFirstChild);
594+
vnode_truncate(container, vCurrent as ElementVNode | VirtualVNode, vFirstChild);
593595
}
594596
}
595597

@@ -604,7 +606,7 @@ export const vnode_diff = (
604606
cleanup(container, toRemove);
605607
// If we are diffing projection than the parent is not the parent of the node.
606608
// If that is the case we don't want to remove the node from the parent.
607-
vnode_remove(vParent, toRemove, true);
609+
vnode_remove(container, vParent, toRemove, true);
608610
}
609611
}
610612
}
@@ -615,7 +617,7 @@ export const vnode_diff = (
615617
cleanup(container, vCurrent);
616618
const toRemove = vCurrent;
617619
advanceToNextSibling();
618-
vnode_remove(vParent, toRemove, true);
620+
vnode_remove(container, vParent, toRemove, true);
619621
}
620622
}
621623

@@ -666,7 +668,7 @@ export const vnode_diff = (
666668
vnode_setProp(vNewNode!, HANDLER_PREFIX + ':' + scopedEvent, value);
667669
if (scope) {
668670
// window and document need attrs so qwik loader can find them
669-
vnode_setAttr(vNewNode!, key, '');
671+
vnode_setAttr(container, vNewNode!, key, '');
670672
}
671673
// register an event for qwik loader (window/document prefixed with '-')
672674
registerQwikLoaderEvent(loaderScopedEvent);
@@ -744,7 +746,7 @@ export const vnode_diff = (
744746
}
745747
}
746748

747-
vnode_insertBefore(vParent as ElementVNode, vNewNode as ElementVNode, vCurrent);
749+
vnode_insertBefore(container, vParent as ElementVNode, vNewNode as ElementVNode, vCurrent);
748750

749751
return needsQDispatchEventPatch;
750752
}
@@ -829,7 +831,7 @@ export const vnode_diff = (
829831
const setAttribute = (vnode: ElementVNode, key: string, value: any) => {
830832
const serializedValue =
831833
value != null ? serializeAttribute(key, value, scopedStyleIdPrefix) : null;
832-
vnode_setAttr(vnode, key, serializedValue);
834+
vnode_setAttr(container, vnode, key, serializedValue);
833835
};
834836

835837
const record = (key: string, value: any) => {
@@ -1092,7 +1094,12 @@ export const vnode_diff = (
10921094
}
10931095
}
10941096
}
1095-
vnode_insertBefore(parentForInsert as ElementVNode | VirtualVNode, buffered, vCurrent);
1097+
vnode_insertBefore(
1098+
container,
1099+
parentForInsert as ElementVNode | VirtualVNode,
1100+
buffered,
1101+
vCurrent
1102+
);
10961103
vCurrent = buffered;
10971104
vNewNode = null;
10981105
return;
@@ -1117,6 +1124,7 @@ export const vnode_diff = (
11171124

11181125
const createNew = () => {
11191126
vnode_insertBefore(
1127+
container,
11201128
vParent as VirtualVNode,
11211129
(vNewNode = vnode_newVirtual()),
11221130
vCurrent && getInsertBefore()
@@ -1259,6 +1267,7 @@ export const vnode_diff = (
12591267
clearAllEffects(container, host);
12601268
}
12611269
vnode_insertBefore(
1270+
container,
12621271
vParent as VirtualVNode,
12631272
(vNewNode = vnode_newVirtual()),
12641273
vCurrent && getInsertBefore()
@@ -1272,6 +1281,7 @@ export const vnode_diff = (
12721281

12731282
function insertNewInlineComponent() {
12741283
vnode_insertBefore(
1284+
container,
12751285
vParent as VirtualVNode,
12761286
(vNewNode = vnode_newVirtual()),
12771287
vCurrent && getInsertBefore()
@@ -1289,13 +1299,14 @@ export const vnode_diff = (
12891299
const type = vnode_getType(vCurrent);
12901300
if (type === 3 /* Text */) {
12911301
if (text !== vnode_getText(vCurrent as TextVNode)) {
1292-
vnode_setText(vCurrent as TextVNode, text);
1302+
vnode_setText(container, vCurrent as TextVNode, text);
12931303
return;
12941304
}
12951305
return;
12961306
}
12971307
}
12981308
vnode_insertBefore(
1309+
container,
12991310
vParent as VirtualVNode,
13001311
(vNewNode = vnode_newText(container.document.createTextNode(text), text)),
13011312
vCurrent
@@ -1542,7 +1553,7 @@ export function cleanup(container: ClientContainer, vNode: VNode) {
15421553
projectionChild = projectionChild.nextSibling as VNode | null;
15431554
}
15441555

1545-
cleanupStaleUnclaimedProjection(projection);
1556+
cleanupStaleUnclaimedProjection(container, projection);
15461557
}
15471558
}
15481559
}
@@ -1615,7 +1626,7 @@ export function cleanup(container: ClientContainer, vNode: VNode) {
16151626
} while (true as boolean);
16161627
}
16171628

1618-
function cleanupStaleUnclaimedProjection(projection: VNode) {
1629+
function cleanupStaleUnclaimedProjection(container: ClientContainer, projection: VNode) {
16191630
// we are removing a node where the projection would go after slot render.
16201631
// This is not needed, so we need to cleanup still unclaimed projection
16211632
const projectionParent = projection.parent;
@@ -1626,7 +1637,7 @@ function cleanupStaleUnclaimedProjection(projection: VNode) {
16261637
vnode_getElementName(projectionParent as ElementVNode) === QTemplate
16271638
) {
16281639
// if parent is the q:template element then projection is still unclaimed - remove it
1629-
vnode_remove(projectionParent as ElementVNode | VirtualVNode, projection, true);
1640+
vnode_remove(container, projectionParent as ElementVNode | VirtualVNode, projection, true);
16301641
}
16311642
}
16321643
}

packages/qwik/src/core/client/vnode-namespace.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
import type { ElementVNode } from '../shared/vnode/element-vnode';
2424
import type { VNode } from '../shared/vnode/vnode';
2525
import type { TextVNode } from '../shared/vnode/text-vnode';
26+
import type { Container } from '../shared/types';
2627

2728
export const isForeignObjectElement = (elementName: string) => {
2829
return isDev ? elementName.toLowerCase() === 'foreignobject' : elementName === 'foreignObject';
@@ -51,6 +52,7 @@ export const vnode_getElementNamespaceFlags = (element: Element) => {
5152
};
5253

5354
export function vnode_getDomChildrenWithCorrectNamespacesToInsert(
55+
container: Container,
5456
domParentVNode: ElementVNode,
5557
newChild: VNode
5658
): (ElementVNode | TextVNode)[] {
@@ -62,11 +64,11 @@ export function vnode_getDomChildrenWithCorrectNamespacesToInsert(
6264
let domChildren: (ElementVNode | TextVNode)[] = [];
6365
if (elementNamespace === HTML_NS) {
6466
// parent is in the default namespace, so just get the dom children. This is the fast path.
65-
domChildren = vnode_getDOMChildNodes(newChild, true);
67+
domChildren = vnode_getDOMChildNodes(container, newChild, true);
6668
} else {
6769
// parent is in a different namespace, so we need to clone the children with the correct namespace.
6870
// The namespace cannot be changed on nodes, so we need to clone these nodes
69-
const children = vnode_getDOMChildNodes(newChild, true);
71+
const children = vnode_getDOMChildNodes(container, newChild, true);
7072

7173
for (let i = 0; i < children.length; i++) {
7274
const childVNode = children[i];

0 commit comments

Comments
 (0)