Skip to content

Commit 35099bd

Browse files
committed
feat(cursors): fix test utils and marking parents as dirty for operation
1 parent e07af2b commit 35099bd

File tree

4 files changed

+30
-29
lines changed

4 files changed

+30
-29
lines changed

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,9 +1135,9 @@ export const vnode_insertBefore = (
11351135

11361136
const parentIsDeleted = parent.flags & VNodeFlags.Deleted;
11371137

1138+
let adjustedInsertBefore: VNode | null = null;
11381139
// if the parent is deleted, then we don't need to insert the new child
11391140
if (!parentIsDeleted) {
1140-
let adjustedInsertBefore: VNode | null = null;
11411141
if (insertBefore == null) {
11421142
if (vnode_isVirtualVNode(parent)) {
11431143
// If `insertBefore` is null, than we need to insert at the end of the list.
@@ -1153,17 +1153,6 @@ export const vnode_insertBefore = (
11531153
adjustedInsertBefore = insertBefore;
11541154
}
11551155
adjustedInsertBefore && vnode_ensureInflatedIfText(adjustedInsertBefore);
1156-
1157-
// Here we know the insertBefore node
1158-
if (domChildren && domChildren.length) {
1159-
for (const child of domChildren) {
1160-
addVNodeOperation(child, {
1161-
operationType: VNodeOperationType.InsertOrMove,
1162-
parent: parentNode!,
1163-
target: vnode_getNode(adjustedInsertBefore),
1164-
});
1165-
}
1166-
}
11671156
}
11681157

11691158
// link newChild into the previous/next list
@@ -1185,6 +1174,17 @@ export const vnode_insertBefore = (
11851174
if (parentIsDeleted) {
11861175
// if the parent is deleted, then the new child is also deleted
11871176
newChild.flags |= VNodeFlags.Deleted;
1177+
} else {
1178+
// Here we know the insertBefore node
1179+
if (domChildren && domChildren.length) {
1180+
for (const child of domChildren) {
1181+
addVNodeOperation(child, {
1182+
operationType: VNodeOperationType.InsertOrMove,
1183+
parent: parentNode!,
1184+
target: vnode_getNode(adjustedInsertBefore),
1185+
});
1186+
}
1187+
}
11881188
}
11891189
};
11901190

packages/qwik/src/core/shared/vnode/vnode-dirty.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,16 @@ export function addVNodeOperation(
5454
): void {
5555
vNode.operation = operation;
5656

57+
let child: VNode = vNode;
5758
let parent: VNode | null = vNode.parent || vNode.slotParent;
58-
while (parent && !(parent.dirty & ChoreBits.DIRTY_MASK)) {
59+
while (
60+
parent &&
61+
!(parent.dirty & ChoreBits.DIRTY_MASK && parent.dirtyChildren?.includes(child))
62+
) {
5963
parent.dirtyChildren ||= [];
60-
parent.dirtyChildren.push(vNode);
64+
parent.dirtyChildren.push(child);
6165
parent.dirty |= ChoreBits.CHILDREN;
66+
child = parent;
6267
parent = parent.parent || parent.slotParent;
6368
}
6469
}

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@ export abstract class VNode extends BackRef {
2020
super();
2121
}
2222

23-
toString(): string {
24-
if (isDev) {
25-
return vnode_toString.call(this);
26-
}
27-
return String(this);
28-
}
23+
// TODO: this creates debug issues
24+
// toString(): string {
25+
// if (isDev) {
26+
// return vnode_toString.call(this);
27+
// }
28+
// return String(this);
29+
// }
2930
}

packages/qwik/src/testing/element-fixture.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ import { QFuncsPrefix, QInstanceAttr } from '../core/shared/utils/markers';
88
import { delay } from '../core/shared/utils/promises';
99
import { invokeApply, newInvokeContextFromTuple } from '../core/use/use-core';
1010
import { createWindow } from './document';
11-
import { getTestPlatform } from './platform';
1211
import type { MockDocument, MockWindow } from './types';
13-
import { ChoreType } from '../core/shared/util-chore-type';
1412

1513
/**
1614
* Creates a simple DOM structure for testing components.
@@ -132,9 +130,8 @@ export async function trigger(
132130
const attrName = prefix + fromCamelToKebabCase(eventName);
133131
await dispatch(element, attrName, event, scope);
134132
}
135-
const waitForQueueChore = container?.$scheduler$(ChoreType.WAIT_FOR_QUEUE);
136-
if (waitForIdle && waitForQueueChore) {
137-
await waitForQueueChore.$returnValue$;
133+
if (waitForIdle && container) {
134+
await container.$renderPromise$;
138135
}
139136
}
140137

@@ -198,10 +195,8 @@ export const dispatch = async (
198195

199196
export async function advanceToNextTimerAndFlush(container: Container) {
200197
vi.advanceTimersToNextTimer();
201-
const waitForQueueChore = container.$scheduler$(ChoreType.WAIT_FOR_QUEUE);
202-
await getTestPlatform().flush();
203-
if (waitForQueueChore) {
204-
await waitForQueueChore.$returnValue$;
198+
if (container) {
199+
await container.$renderPromise$;
205200
}
206201
}
207202

0 commit comments

Comments
 (0)