From 4d9ac35377f29a7d9897c7ddeecc24ce1552cbc0 Mon Sep 17 00:00:00 2001 From: Varixo Date: Tue, 27 Aug 2024 09:28:18 +0200 Subject: [PATCH] fix some e2e tests --- packages/qwik/src/core/use/use-task.ts | 56 ++++++++----------- .../core/v2/shared/shared-serialization.ts | 23 +++++++- packages/qwik/src/core/v2/signal/v2-signal.ts | 1 + .../src/core/v2/tests/use-context.spec.tsx | 1 - 4 files changed, 45 insertions(+), 36 deletions(-) diff --git a/packages/qwik/src/core/use/use-task.ts b/packages/qwik/src/core/use/use-task.ts index 4b6a8e00c0a..15962e0fdcc 100644 --- a/packages/qwik/src/core/use/use-task.ts +++ b/packages/qwik/src/core/use/use-task.ts @@ -347,7 +347,12 @@ export const useTaskQrl = (qrl: QRL, opts?: UseTaskOptions): void => { } }; -export const runTask2 = (task: Task, container: Container2, host: HostElement) => { +export const runTask2 = ( + task: Task, + container: Container2, + host: HostElement, + isRerunning = false +): ValueOrPromise => { task.$flags$ &= ~TaskFlags.DIRTY; const iCtx = newInvokeContext(container.$locale$, host as fixMeAny, undefined, TaskEvent); iCtx.$container2$ = container; @@ -393,35 +398,16 @@ export const runTask2 = (task: Task, container: Container2, host: HostElement) = const taskApi: TaskCtx = { track, cleanup }; cleanupTask(task); - const result = safeCall(() => taskFn(taskApi), cleanup, handleError); - return result; -}; - -export const runComputed2 = ( - task: TaskDescriptor | ComputedDescriptor, - container: Container2, - host: HostElement -): ValueOrPromise => { - assertSignal(task.$state$); - task.$flags$ &= ~TaskFlags.DIRTY; - const iCtx = newInvokeContext(container.$locale$, host as fixMeAny, undefined, ComputedEvent); - iCtx.$subscriber$ = [SubscriptionType.HOST, task]; - - const taskFn = task.$qrl$.getFn(iCtx, () => { - container.$subsManager$.$clearSub$(task); - }) as ComputedFn; - - const handleError = (reason: unknown) => container.handleError(reason, host); - const result = safeCall( - taskFn, - (returnValue) => - untrack(() => { - const signal = task.$state$! as SignalInternal; - signal[QObjectSignalFlags] &= ~SIGNAL_UNASSIGNED; - signal.untrackedValue = returnValue; - signal[QObjectManagerSymbol].$notifySubs$(); - }), - handleError + const result: ValueOrPromise = safeCall( + () => taskFn(taskApi), + cleanup, + (err: unknown) => { + if (isPromise(err)) { + return err.then(() => runTask2(task, container, host, true)); + } else { + return handleError(err); + } + } ); return result; }; @@ -678,13 +664,17 @@ export const runResource = ( promise.catch(ignoreErrorToPreventNodeFromCrashing); }); - const promise = safeCall( + const promise: ValueOrPromise = safeCall( () => Promise.resolve(taskFn(opts)), (value) => { setState(true, value); }, - (reason) => { - setState(false, reason); + (err) => { + if (isPromise(err)) { + return err.then(() => runResource(task, container, host)); + } else { + setState(false, err); + } } ); diff --git a/packages/qwik/src/core/v2/shared/shared-serialization.ts b/packages/qwik/src/core/v2/shared/shared-serialization.ts index 069ac25f511..b13f7ac0138 100644 --- a/packages/qwik/src/core/v2/shared/shared-serialization.ts +++ b/packages/qwik/src/core/v2/shared/shared-serialization.ts @@ -1416,7 +1416,8 @@ export const canSerialize2 = (value: any): boolean => { value == null || typeof value === 'string' || typeof value === 'number' || - typeof value === 'boolean' + typeof value === 'boolean' || + typeof value === 'bigint' ) { return true; } else if (typeof value === 'object') { @@ -1441,12 +1442,30 @@ export const canSerialize2 = (value: any): boolean => { return true; } else if (isTask(value)) { return true; - } else if (value instanceof Error) { + } else if (isPropsProxy(value)) { return true; } else if (isPromise(value)) { return true; } else if (isJSXNode(value)) { return true; + } else if (value instanceof Error) { + return true; + } else if (value instanceof URL) { + return true; + } else if (value instanceof Date) { + return true; + } else if (value instanceof RegExp) { + return true; + } else if (value instanceof URLSearchParams) { + return true; + } else if (value instanceof FormData) { + return true; + } else if (value instanceof Set) { + return true; + } else if (value instanceof Map) { + return true; + } else if (value instanceof Uint8Array) { + return true; } } else if (typeof value === 'function') { if (isQrl(value) || isQwikComponent(value)) { diff --git a/packages/qwik/src/core/v2/signal/v2-signal.ts b/packages/qwik/src/core/v2/signal/v2-signal.ts index 9f28ace94b4..ab3c2d1cbfa 100644 --- a/packages/qwik/src/core/v2/signal/v2-signal.ts +++ b/packages/qwik/src/core/v2/signal/v2-signal.ts @@ -410,6 +410,7 @@ export class ComputedSignal2 extends Signal2 { computeQrl.resolved, 'Computed signals must run sync. Expected the QRL to be resolved at this point.' ); + throwIfQRLNotResolved(computeQrl); const ctx = tryGetInvokeContext(); assertDefined(computeQrl, 'Signal is marked as dirty, but no compute function is provided.'); diff --git a/packages/qwik/src/core/v2/tests/use-context.spec.tsx b/packages/qwik/src/core/v2/tests/use-context.spec.tsx index cc7fb41a6ff..0c062ffcbc2 100644 --- a/packages/qwik/src/core/v2/tests/use-context.spec.tsx +++ b/packages/qwik/src/core/v2/tests/use-context.spec.tsx @@ -25,7 +25,6 @@ import { createDocument, emulateExecutionOfQwikFuncs, } from '@builder.io/qwik/testing'; -import '../../../testing/vdom-diff.unit-util'; import { renderToString2 } from 'packages/qwik/src/server/v2-ssr-render2'; import type { Signal2 } from '../signal/v2-signal.public';