Skip to content

Commit 832d66e

Browse files
committed
fix: object migration fixes
1 parent aa1e71a commit 832d66e

File tree

9 files changed

+57
-82
lines changed

9 files changed

+57
-82
lines changed

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import {
2525
QLocaleAttr,
2626
QManifestHashAttr,
2727
QScopedStyle,
28-
QSlotParent,
2928
QStyle,
3029
QStyleSelector,
3130
Q_PROPS_SEPARATOR,
@@ -232,7 +231,7 @@ export class DomContainer extends _SharedContainer implements IClientContainer {
232231
vNode =
233232
vnode_getParent(vNode) ||
234233
// If virtual node, than it could be a slot so we need to read its parent.
235-
vNode.getProp<VNode>(QSlotParent, this.vNodeLocate);
234+
vNode.getSlotParent();
236235
} else {
237236
vNode = vnode_getParent(vNode);
238237
}
@@ -275,7 +274,7 @@ export class DomContainer extends _SharedContainer implements IClientContainer {
275274
if (typeof value == 'string') {
276275
const projection = this.vNodeLocate(value);
277276
props[i + 1] = projection;
278-
(projection as VirtualVNode).getProp(QSlotParent, (id) => this.vNodeLocate(id));
277+
projection.getSlotParent();
279278
}
280279
}
281280
}

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import {
2626
QContainerAttr,
2727
QDefaultSlot,
2828
QSlot,
29-
QSlotParent,
3029
QBackRefs,
3130
QTemplate,
3231
Q_PREFIX,
@@ -450,7 +449,7 @@ export const vnode_diff = (
450449
isDev && (vNewNode as VirtualVNode).setProp(DEBUG_TYPE, VirtualType.Projection);
451450
isDev && (vNewNode as VirtualVNode).setProp('q:code', 'expectProjection');
452451
(vNewNode as VirtualVNode).setProp(QSlot, slotName);
453-
(vNewNode as VirtualVNode).setProp(QSlotParent, vParent);
452+
(vNewNode as VirtualVNode).slotParent = vParent;
454453
(vParent as VirtualVNode).setProp(slotName, vNewNode);
455454
}
456455
}
@@ -1404,9 +1403,7 @@ export function cleanup(container: ClientContainer, vNode: VNode) {
14041403
*/
14051404
if (vNode.flags & VNodeFlags.Virtual) {
14061405
// The QSlotParent is used to find the slot parent during scheduling
1407-
(vNode as VirtualVNode).getProp<string>(QSlotParent, (id) =>
1408-
vnode_locate(container.rootVNode, id)
1409-
);
1406+
vNode.getSlotParent();
14101407
}
14111408
});
14121409
return;

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,15 @@ import {
1010
/** @internal */
1111
export abstract class VNode {
1212
props: (string | null | boolean)[] | null = null;
13+
slotParent: VNode | null = null;
14+
15+
getSlotParent(): VNode | null {
16+
return this.slotParent;
17+
}
1318

1419
constructor(
1520
public flags: VNodeFlags,
16-
public parent: ElementVNode | VirtualVNode | null | undefined,
21+
public parent: ElementVNode | VirtualVNode | null,
1722
public previousSibling: VNode | null | undefined,
1823
public nextSibling: VNode | null | undefined
1924
) {}
@@ -22,9 +27,9 @@ export abstract class VNode {
2227
const type = this.flags;
2328
if ((type & VNodeFlags.ELEMENT_OR_VIRTUAL_MASK) !== 0) {
2429
type & VNodeFlags.Element && vnode_ensureElementInflated(this);
30+
this.props ||= [];
2531
const idx = mapApp_findIndx(this.props as any, key, 0);
2632
if (idx >= 0) {
27-
this.props ||= [];
2833
let value = this.props[idx + 1] as any;
2934
if (typeof value === 'string' && getObject) {
3035
this.props[idx + 1] = value = getObject(value);
@@ -90,7 +95,7 @@ export abstract class VNode {
9095
export class TextVNode extends VNode {
9196
constructor(
9297
flags: VNodeFlags,
93-
parent: ElementVNode | VirtualVNode | null | undefined,
98+
parent: ElementVNode | VirtualVNode | null,
9499
previousSibling: VNode | null | undefined,
95100
nextSibling: VNode | null | undefined,
96101
public textNode: Text | null,
@@ -104,7 +109,7 @@ export class TextVNode extends VNode {
104109
export class VirtualVNode extends VNode {
105110
constructor(
106111
flags: VNodeFlags,
107-
parent: ElementVNode | VirtualVNode | null | undefined,
112+
parent: ElementVNode | VirtualVNode | null,
108113
previousSibling: VNode | null | undefined,
109114
nextSibling: VNode | null | undefined,
110115
public firstChild: VNode | null | undefined,
@@ -118,7 +123,7 @@ export class VirtualVNode extends VNode {
118123
export class ElementVNode extends VirtualVNode {
119124
constructor(
120125
flags: VNodeFlags,
121-
parent: ElementVNode | VirtualVNode | null | undefined,
126+
parent: ElementVNode | VirtualVNode | null,
122127
previousSibling: VNode | null | undefined,
123128
nextSibling: VNode | null | undefined,
124129
firstChild: VNode | null | undefined,

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

Lines changed: 16 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,6 @@ import {
147147
QIgnoreEnd,
148148
QScopedStyle,
149149
QSlot,
150-
QSlotParent,
151150
QStyle,
152151
QStylesAllSelector,
153152
} from '../shared/utils/markers';
@@ -1150,11 +1149,7 @@ export const vnode_getDomParentVNode = (
11501149
includeProjection = true
11511150
): ElementVNode | null => {
11521151
while (vnode && !vnode_isElementVNode(vnode)) {
1153-
vnode =
1154-
vnode.parent ||
1155-
(includeProjection
1156-
? vnode.getProp(QSlotParent, (id) => (vnode_isVNode(id) ? id : null))
1157-
: null)!;
1152+
vnode = vnode.parent || (includeProjection ? vnode.getSlotParent() : null)!;
11581153
}
11591154
return vnode;
11601155
};
@@ -1672,38 +1667,27 @@ export const vnode_getProps = (vnode: ElementVNode | VirtualVNode): unknown[] =>
16721667
};
16731668

16741669
export const vnode_getParent = (vnode: VNode): VNode | null => {
1675-
return vnode.parent || null;
1670+
return vnode.parent!;
16761671
};
16771672

1678-
export const vnode_isDescendantOf = (
1679-
vnode: VNode,
1680-
ancestor: VNode,
1681-
rootVNode: ElementVNode | null
1682-
): boolean => {
1683-
let parent: VNode | null = vnode_getParentOrProjectionParent(vnode, rootVNode);
1673+
export const vnode_isDescendantOf = (vnode: VNode, ancestor: VNode): boolean => {
1674+
let parent: VNode | null = vnode_getParentOrProjectionParent(vnode);
16841675
while (parent) {
16851676
if (parent === ancestor) {
16861677
return true;
16871678
}
1688-
parent = vnode_getParentOrProjectionParent(parent, rootVNode);
1679+
parent = vnode_getParentOrProjectionParent(parent);
16891680
}
16901681
return false;
16911682
};
16921683

1693-
export const vnode_getParentOrProjectionParent = (
1694-
vnode: VNode,
1695-
rootVNode: ElementVNode | null
1696-
): VNode | null => {
1697-
if (rootVNode) {
1698-
const parentProjection: VNode | null = vnode.getProp(QSlotParent, (id) =>
1699-
vnode_locate(rootVNode, id)
1700-
);
1701-
if (parentProjection) {
1702-
// This is a projection, so we need to check the parent of the projection
1703-
return parentProjection;
1704-
}
1684+
export const vnode_getParentOrProjectionParent = (vnode: VNode): VNode | null => {
1685+
const parentProjection: VNode | null = vnode.slotParent;
1686+
if (parentProjection) {
1687+
// This is a projection, so we need to check the parent of the projection
1688+
return parentProjection;
17051689
}
1706-
return vnode_getParent(vnode);
1690+
return vnode.parent;
17071691
};
17081692

17091693
export const vnode_getNode = (vnode: VNode | null): Element | Text | null => {
@@ -1894,7 +1878,10 @@ function materializeFromVNodeData(
18941878
}
18951879
setEffectBackRefFromVNodeData(vParent, consumeValue(), container);
18961880
} else if (peek() === VNodeDataChar.SLOT_PARENT) {
1897-
vParent.setProp(QSlotParent, consumeValue());
1881+
if (!container) {
1882+
container = getDomContainer(element);
1883+
}
1884+
vParent.slotParent = vnode_locate(container!.rootVNode, consumeValue());
18981885
} else if (peek() === VNodeDataChar.CONTEXT) {
18991886
vParent.setAttr(QCtxAttr, consumeValue(), null);
19001887
} else if (peek() === VNodeDataChar.OPEN) {
@@ -1995,9 +1982,7 @@ export const vnode_getProjectionParentComponent = (
19951982
vHost &&
19961983
(vnode_isVirtualVNode(vHost) ? vHost.getProp(OnRenderProp, null) === null : true)
19971984
) {
1998-
const qSlotParent = vHost.getProp<VNode | null>(QSlotParent, (id) =>
1999-
vnode_locate(rootVNode, id)
2000-
);
1985+
const qSlotParent = vHost.getSlotParent();
20011986
const vProjectionParent = vnode_isVirtualVNode(vHost) && qSlotParent;
20021987
if (vProjectionParent) {
20031988
// We found a projection, so we need to go up one more level.

packages/qwik/src/core/client/vnode.unit.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,10 +415,10 @@ describe('vnode', () => {
415415
});
416416
it('should place attributes on Virtual', () => {
417417
parent.innerHTML = ``;
418-
document.qVNodeData.set(parent, '{?:sparent_@:key_}');
418+
document.qVNodeData.set(parent, '{@:key_}');
419419
expect(vParent).toMatchVDOM(
420420
<test>
421-
<Fragment {...({ 'q:sparent': ':sparent_' } as any)} key=":key_" />
421+
<Fragment key=":key_" />
422422
</test>
423423
);
424424
});

packages/qwik/src/core/qwik.core.api.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1845,6 +1845,8 @@ export abstract class _VNode {
18451845
// (undocumented)
18461846
getProp<T>(key: string, getObject: ((id: string) => any) | null): T | null;
18471847
// (undocumented)
1848+
getSlotParent(): _VNode | null;
1849+
// (undocumented)
18481850
nextSibling: _VNode | null | undefined;
18491851
// (undocumented)
18501852
parent: _ElementVNode | _VirtualVNode | null | undefined;
@@ -1857,6 +1859,8 @@ export abstract class _VNode {
18571859
// (undocumented)
18581860
setProp(key: string, value: any): void;
18591861
// (undocumented)
1862+
slotParent: _VNode | null;
1863+
// (undocumented)
18601864
toString(): string;
18611865
}
18621866

packages/qwik/src/core/shared/scheduler-document-position.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import { vnode_getNextSibling, vnode_getPreviousSibling, vnode_locate } from '../client/vnode';
1+
import { vnode_getNextSibling, vnode_getPreviousSibling } from '../client/vnode';
22
import type { ElementVNode, VNode } from '../client/vnode-impl';
33
import type { ISsrNode } from '../ssr/ssr-types';
4-
import { QSlotParent } from './utils/markers';
54

65
/// These global variables are used to avoid creating new arrays for each call to `vnode_documentPosition`.
76
const aVNodePath: VNode[] = [];
@@ -27,13 +26,11 @@ export const vnode_documentPosition = (
2726
let bDepth = -1;
2827
while (a) {
2928
const vNode = (aVNodePath[++aDepth] = a);
30-
a = (vNode.parent ||
31-
(rootVNode && a.getProp(QSlotParent, (id) => vnode_locate(rootVNode, id))))!;
29+
a = (vNode.parent || a.slotParent)!;
3230
}
3331
while (b) {
3432
const vNode = (bVNodePath[++bDepth] = b);
35-
b = (vNode.parent ||
36-
(rootVNode && b.getProp(QSlotParent, (id) => vnode_locate(rootVNode, id))))!;
33+
b = (vNode.parent || b.slotParent)!;
3734
}
3835

3936
while (aDepth >= 0 && bDepth >= 0) {
@@ -59,7 +56,7 @@ export const vnode_documentPosition = (
5956
return -1;
6057
}
6158
} while (cursor);
62-
if (rootVNode && b.getProp(QSlotParent, (id) => vnode_locate(rootVNode, id))) {
59+
if (b.slotParent) {
6360
// The "b" node is a projection, so we need to set it after "a" node,
6461
// because the "a" node could be a context provider.
6562
return -1;

packages/qwik/src/core/shared/scheduler-rules.ts

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,17 @@ const VISIBLE_BLOCKING_RULES: BlockingRule[] = [
2929
{
3030
blockedType: ChoreType.VISIBLE,
3131
blockingType: ChoreType.NODE_DIFF,
32-
match: (blocked, blocking, container) =>
33-
isDescendant(blocked, blocking, container) || isDescendant(blocking, blocked, container),
32+
match: (blocked, blocking) =>
33+
isDescendant(blocked, blocking) || isDescendant(blocking, blocked),
3434
},
3535
// COMPONENT blocks VISIBLE on same host
3636
// if the blocked chore is a child of the blocking chore
3737
// or the blocked chore is a sibling of the blocking chore
3838
{
3939
blockedType: ChoreType.VISIBLE,
4040
blockingType: ChoreType.COMPONENT,
41-
match: (blocked, blocking, container) =>
42-
isDescendant(blocked, blocking, container) || isDescendant(blocking, blocked, container),
41+
match: (blocked, blocking) =>
42+
isDescendant(blocked, blocking) || isDescendant(blocking, blocked),
4343
},
4444
];
4545

@@ -103,17 +103,13 @@ const BLOCKING_RULES: BlockingRule[] = [
103103
},
104104
];
105105

106-
function isDescendant(descendantChore: Chore, ancestorChore: Chore, container: Container): boolean {
106+
function isDescendant(descendantChore: Chore, ancestorChore: Chore): boolean {
107107
const descendantHost = descendantChore.$host$;
108108
const ancestorHost = ancestorChore.$host$;
109109
if (!vnode_isVNode(descendantHost) || !vnode_isVNode(ancestorHost)) {
110110
return false;
111111
}
112-
return vnode_isDescendantOf(
113-
descendantHost,
114-
ancestorHost,
115-
(container as ClientContainer).rootVNode
116-
);
112+
return vnode_isDescendantOf(descendantHost, ancestorHost);
117113
}
118114

119115
function isSameHost(a: Chore, b: Chore): boolean {
@@ -134,7 +130,7 @@ function findBlockingChoreInQueue(
134130
if (candidate.$type$ >= ChoreType.VISIBLE || candidate.$type$ === ChoreType.TASK) {
135131
continue;
136132
}
137-
if (isDescendant(chore, candidate, container)) {
133+
if (isDescendant(chore, candidate)) {
138134
return candidate;
139135
}
140136
}
@@ -152,22 +148,14 @@ export function findBlockingChore(
152148
if (blockingChoreInChoreQueue) {
153149
return blockingChoreInChoreQueue;
154150
}
155-
const blockingChoreInBlockedChores = findBlockingChoreInQueue(
156-
chore,
157-
Array.from(blockedChores),
158-
container
159-
);
160-
if (blockingChoreInBlockedChores) {
161-
return blockingChoreInBlockedChores;
162-
}
163-
const blockingChoreInRunningChores = findBlockingChoreInQueue(
164-
chore,
165-
Array.from(runningChores),
166-
container
167-
);
168-
if (blockingChoreInRunningChores) {
169-
return blockingChoreInRunningChores;
170-
}
151+
// const blockingChoreInBlockedChores = findBlockingChoreInQueue(
152+
// chore,
153+
// Array.from(blockedChores),
154+
// container
155+
// );
156+
// if (blockingChoreInBlockedChores) {
157+
// return blockingChoreInBlockedChores;
158+
// }
171159

172160
for (const rule of BLOCKING_RULES) {
173161
if (chore.$type$ !== rule.blockedType) {

packages/qwik/src/core/shared/scheduler-rules.unit.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { findBlockingChore, findBlockingChoreForVisible } from './scheduler-rule
33
import { ChoreType } from './util-chore-type';
44
import { addBlockedChore, type Chore } from './scheduler';
55
import { Task, TaskFlags } from '../use/use-task';
6-
import { ELEMENT_SEQ, QSlotParent } from './utils/markers';
6+
import { ELEMENT_SEQ } from './utils/markers';
77
import type { Container } from './types';
88
import { vnode_newVirtual } from '../client/vnode';
99
import { $, type QRL } from './qrl/qrl.public';
@@ -630,7 +630,7 @@ describe('findBlockingChore', () => {
630630
const childProjectionVNode = vnode_newVirtual();
631631
parentProjectionVNode.parent = rootVNode;
632632
parentProjectionVNode.setProp('', childProjectionVNode);
633-
childProjectionVNode.setProp(QSlotParent, parentProjectionVNode);
633+
childProjectionVNode.slotParent = parentProjectionVNode;
634634
const ancestorProjectionChore = createMockChore(ChoreType.COMPONENT, parentProjectionVNode);
635635
const descendantProjectionChore = createMockChore(ChoreType.COMPONENT, childProjectionVNode);
636636
const choreQueue = [ancestorProjectionChore];

0 commit comments

Comments
 (0)