Skip to content

Commit

Permalink
fix some e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Varixo committed Aug 27, 2024
1 parent ddfe999 commit 4d9ac35
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 36 deletions.
56 changes: 23 additions & 33 deletions packages/qwik/src/core/use/use-task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,12 @@ export const useTaskQrl = (qrl: QRL<TaskFn>, opts?: UseTaskOptions): void => {
}
};

export const runTask2 = (task: Task, container: Container2, host: HostElement) => {
export const runTask2 = (
task: Task,
container: Container2,
host: HostElement,
isRerunning = false
): ValueOrPromise<void> => {
task.$flags$ &= ~TaskFlags.DIRTY;
const iCtx = newInvokeContext(container.$locale$, host as fixMeAny, undefined, TaskEvent);
iCtx.$container2$ = container;
Expand Down Expand Up @@ -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<unknown>,
container: Container2,
host: HostElement
): ValueOrPromise<void> => {
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<unknown>;

const handleError = (reason: unknown) => container.handleError(reason, host);
const result = safeCall(
taskFn,
(returnValue) =>
untrack(() => {
const signal = task.$state$! as SignalInternal<unknown>;
signal[QObjectSignalFlags] &= ~SIGNAL_UNASSIGNED;
signal.untrackedValue = returnValue;
signal[QObjectManagerSymbol].$notifySubs$();
}),
handleError
const result: ValueOrPromise<void> = safeCall(
() => taskFn(taskApi),
cleanup,
(err: unknown) => {
if (isPromise(err)) {
return err.then(() => runTask2(task, container, host, true));
} else {
return handleError(err);
}
}
);
return result;
};
Expand Down Expand Up @@ -678,13 +664,17 @@ export const runResource = <T>(
promise.catch(ignoreErrorToPreventNodeFromCrashing);
});

const promise = safeCall(
const promise: ValueOrPromise<void> = 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);
}
}
);

Expand Down
23 changes: 21 additions & 2 deletions packages/qwik/src/core/v2/shared/shared-serialization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand All @@ -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)) {
Expand Down
1 change: 1 addition & 0 deletions packages/qwik/src/core/v2/signal/v2-signal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,7 @@ export class ComputedSignal2<T> extends Signal2<T> {
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.');
Expand Down
1 change: 0 additions & 1 deletion packages/qwik/src/core/v2/tests/use-context.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down

0 comments on commit 4d9ac35

Please sign in to comment.