Skip to content

Commit 3f0f2a3

Browse files
committed
fixup qrl run error handling
1 parent 431c2cd commit 3f0f2a3

File tree

4 files changed

+32
-19
lines changed

4 files changed

+32
-19
lines changed

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

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
/** @file Public APIs for the SSR */
22

33
import { assertTrue } from '../shared/error/assert';
4+
import { QError, qError } from '../shared/error/error';
5+
import { ERROR_CONTEXT, isRecoverable } from '../shared/error/error-handling';
46
import { getPlatform } from '../shared/platform/platform';
57
import type { QRL } from '../shared/qrl/qrl.public';
6-
import { ERROR_CONTEXT, isRecoverable } from '../shared/error/error-handling';
7-
import type { ContextId } from '../use/use-context';
8+
import { ChoreType } from '../shared/scheduler';
9+
import { _SharedContainer } from '../shared/shared-container';
10+
import { inflateQRL, parseQRL, wrapDeserializerProxy } from '../shared/shared-serialization';
11+
import { QContainerValue, type HostElement, type ObjToProxyMap } from '../shared/types';
812
import { EMPTY_ARRAY } from '../shared/utils/flyweight';
913
import {
1014
ELEMENT_PROPS,
1115
ELEMENT_SEQ,
1216
ELEMENT_SEQ_IDX,
13-
getQFuncs,
1417
OnRenderProp,
15-
Q_PROPS_SEPARATOR,
1618
QBaseAttr,
1719
QContainerAttr,
1820
QContainerSelector,
@@ -23,19 +25,18 @@ import {
2325
QStyle,
2426
QStyleSelector,
2527
QSubscribers,
28+
Q_PROPS_SEPARATOR,
2629
USE_ON_LOCAL_SEQ_IDX,
30+
getQFuncs,
2731
} from '../shared/utils/markers';
2832
import { isPromise } from '../shared/utils/promises';
2933
import { isSlotProp } from '../shared/utils/prop';
3034
import { qDev } from '../shared/utils/qdev';
31-
import { ChoreType } from '../shared/scheduler';
3235
import {
3336
convertScopedStyleIdsToArray,
3437
convertStyleIdsToString,
3538
} from '../shared/utils/scoped-styles';
36-
import { _SharedContainer } from '../shared/shared-container';
37-
import { inflateQRL, parseQRL, wrapDeserializerProxy } from '../shared/shared-serialization';
38-
import { QContainerValue, type HostElement, type ObjToProxyMap } from '../shared/types';
39+
import type { ContextId } from '../use/use-context';
3940
import { processVNodeData } from './process-vnode-data';
4041
import {
4142
VNodeFlags,
@@ -65,7 +66,6 @@ import {
6566
vnode_setProp,
6667
type VNodeJournal,
6768
} from './vnode';
68-
import { QError, qError } from '../shared/error/error';
6969

7070
/** @public */
7171
export function getDomContainer(element: Element | VNode): IClientContainer {
@@ -190,7 +190,7 @@ export class DomContainer extends _SharedContainer implements IClientContainer {
190190
}
191191

192192
handleError(err: any, host: HostElement): void {
193-
if (qDev) {
193+
if (qDev && host) {
194194
// Clean vdom
195195
if (typeof document !== 'undefined') {
196196
const vHost = host as VirtualVNode;
@@ -215,7 +215,7 @@ export class DomContainer extends _SharedContainer implements IClientContainer {
215215
throw err;
216216
}
217217
}
218-
const errorStore = this.resolveContext(host, ERROR_CONTEXT);
218+
const errorStore = host && this.resolveContext(host, ERROR_CONTEXT);
219219
if (!errorStore) {
220220
throw err;
221221
}

packages/qwik/src/core/client/queue-qrl.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ export const queueQRL = (...args: unknown[]) => {
2323
throw qError(QError.schedulerNotFound);
2424
}
2525

26-
return scheduler(ChoreType.RUN_QRL, null, runQrl, args);
26+
return scheduler(ChoreType.RUN_QRL, el, runQrl, args);
2727
};

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,7 @@ export const vnode_diff = (
766766
if (qrl) {
767767
const value = container.$scheduler$(
768768
ChoreType.RUN_QRL,
769-
null,
769+
element,
770770
qrl as QRLInternal<(...args: unknown[]) => unknown>,
771771
[event, element]
772772
) as unknown;

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

+19-6
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ import {
8989
type ElementVNode,
9090
type VirtualVNode,
9191
} from '../client/types';
92-
import { VNodeJournalOpCode, vnode_isVNode, vnode_setAttr } from '../client/vnode';
92+
import { VNodeJournalOpCode, vnode_isVNode, vnode_locate, vnode_setAttr } from '../client/vnode';
9393
import { vnode_diff } from '../client/vnode-diff';
9494
import { triggerEffects, type ComputedSignal, type WrappedSignal } from '../signal/signal';
9595
import { isSignal, type Signal } from '../signal/signal.public';
@@ -214,7 +214,7 @@ export const createScheduler = (
214214
): ValueOrPromise<void>;
215215
function schedule(
216216
type: ChoreType.RUN_QRL,
217-
ignore: null,
217+
host: Element,
218218
target: QRLInternal<(...args: unknown[]) => unknown>,
219219
args: unknown[]
220220
): ValueOrPromise<void>;
@@ -240,7 +240,7 @@ export const createScheduler = (
240240
///// IMPLEMENTATION /////
241241
function schedule(
242242
type: ChoreType,
243-
hostOrTask: HostElement | Task | null = null,
243+
hostOrTask: HostElement | Task | Element | null = null,
244244
targetOrQrl: ChoreTarget | string | null = null,
245245
payload: any = null
246246
): ValueOrPromise<any> {
@@ -325,9 +325,8 @@ export const createScheduler = (
325325
qrlRuns.length
326326
) {
327327
return Promise.all(qrlRuns)
328-
.catch((e) => {
329-
// TODO test this and add host prop to error
330-
container.handleError(e, null!);
328+
.catch(() => {
329+
// they are already handled by the qrl runs
331330
})
332331
.then(() => drainUpTo(runUptoChore, isServer));
333332
}
@@ -430,9 +429,23 @@ export const createScheduler = (
430429
qrlRuns.splice(qrlRuns.indexOf(handled), 1);
431430
})
432431
.catch((error) => {
432+
// TODO test this
433+
const host = isDomContainer(container)
434+
? vnode_locate(container.rootVNode, chore.$host$ as any as Element)
435+
: null!;
433436
container.handleError(error, host);
434437
});
438+
// Don't wait for the promise to resolve
439+
// TODO come up with a better solution, we also want concurrent signal handling with tasks but serial tasks
435440
qrlRuns.push(handled);
441+
DEBUG &&
442+
debugTrace('execute.DONE (but still running)', chore, currentChore, choreQueue);
443+
chore.$returnValue$ = handled;
444+
chore.$resolve$?.(handled);
445+
currentChore = null;
446+
chore.$executed$ = true;
447+
// early out so we don't call after()
448+
return;
436449
}
437450
returnValue = null;
438451
}

0 commit comments

Comments
 (0)