Skip to content

Commit 377de9a

Browse files
committed
fix: loaders serialization
1 parent 1e7f8fc commit 377de9a

File tree

8 files changed

+23
-8
lines changed

8 files changed

+23
-8
lines changed

Diff for: packages/qwik-router/src/middleware/request-handler/resolve-request-handlers.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import {
3030
import { getQwikRouterServerData } from './response-page';
3131
import type { QwikSerializer, RequestEvent, RequestEventBase, RequestHandler } from './types';
3232
import { IsQData, QDATA_JSON } from './user-response';
33+
import { _UNINITIALIZED } from '@qwik.dev/core/internal';
3334

3435
export const resolveRequestHandlers = (
3536
serverPlugins: RouteModule[] | undefined,
@@ -594,7 +595,7 @@ export async function renderQData(requestEv: RequestEvent) {
594595
const loaders: Record<string, unknown> = {};
595596
for (const loaderId in allLoaders) {
596597
const loader = allLoaders[loaderId];
597-
if (loader) {
598+
if (loader !== _UNINITIALIZED) {
598599
loaders[loaderId] = loader;
599600
}
600601
}

Diff for: packages/qwik-router/src/runtime/src/server-functions.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
_getContextEvent,
1515
_serialize,
1616
_wrapStore,
17+
_UNINITIALIZED,
1718
} from '@qwik.dev/core/internal';
1819

1920
import * as v from 'valibot';
@@ -209,10 +210,12 @@ export const routeLoaderQrl = ((
209210
For more information check: https://qwik.dev/docs/re-exporting-loaders/`);
210211
}
211212
const data = untrack(() => state[id]);
212-
if (!data && isBrowser) {
213+
if (data === _UNINITIALIZED && isBrowser) {
213214
throw loadClientData(location.url, iCtx.$hostElement$, {
214215
loaderIds: [id],
215-
}).then((data) => (state[id] = data?.loaders[id]));
216+
}).then((data) => {
217+
state[id] = data?.loaders[id];
218+
});
216219
}
217220
return _wrapStore(state, id);
218221
}

Diff for: packages/qwik/src/core/api.md

+3
Original file line numberDiff line numberDiff line change
@@ -1589,6 +1589,9 @@ export interface Tracker {
15891589
<T extends object, P extends keyof T>(obj: T, prop: P): T[P];
15901590
}
15911591

1592+
// @internal (undocumented)
1593+
export const _UNINITIALIZED: unique symbol;
1594+
15921595
// @public
15931596
export const untrack: <T>(fn: () => T) => T;
15941597

Diff for: packages/qwik/src/core/internal.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export { queueQRL as _run } from './client/queue-qrl';
55
export { scheduleTask as _task } from './use/use-task';
66
export { _wrapSignal, _wrapProp, _wrapStore } from './signal/signal-utils';
77
export { _restProps } from './shared/utils/prop';
8-
export { _IMMUTABLE } from './shared/utils/constants';
8+
export { _IMMUTABLE, _UNINITIALIZED } from './shared/utils/constants';
99
export { _CONST_PROPS, _VAR_PROPS } from './shared/utils/constants';
1010
export { _weakSerialize } from './shared/utils/serialize-utils';
1111
export { verifySerializable as _verifySerializable } from './shared/utils/serialize-utils';

Diff for: packages/qwik/src/core/shared/shared-serialization.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ import type { QRL } from './qrl/qrl.public';
5151
import { type NodePropData } from './scheduler';
5252
import { ChoreType } from './util-chore-type';
5353
import type { DeserializeContainer, HostElement, ObjToProxyMap } from './types';
54-
import { _CONST_PROPS, _VAR_PROPS } from './utils/constants';
54+
import { _CONST_PROPS, _UNINITIALIZED, _VAR_PROPS } from './utils/constants';
5555
import { isElement, isNode } from './utils/element';
5656
import { EMPTY_ARRAY, EMPTY_OBJ } from './utils/flyweight';
5757
import { ELEMENT_ID } from './utils/markers';
@@ -405,7 +405,7 @@ const inflate = (
405405
target = Object.fromEntries(
406406
objectKeys.map((v) =>
407407
// initialize values with null
408-
[v, null]
408+
[v, _UNINITIALIZED]
409409
)
410410
);
411411
break;
@@ -426,6 +426,7 @@ export const _constants = [
426426
EMPTY_OBJ,
427427
NEEDS_COMPUTATION,
428428
STORE_ALL_PROPS,
429+
_UNINITIALIZED,
429430
Slot,
430431
Fragment,
431432
NaN,
@@ -445,6 +446,7 @@ const _constantNames = [
445446
'EMPTY_OBJ',
446447
'NEEDS_COMPUTATION',
447448
'STORE_ALL_PROPS',
449+
'_UNINITIALIZED',
448450
'Slot',
449451
'Fragment',
450452
'NaN',
@@ -1134,6 +1136,8 @@ function serialize(serializationContext: SerializationContext): void {
11341136
output(TypeIds.Constant, Constants.NEEDS_COMPUTATION);
11351137
} else if (value === STORE_ALL_PROPS) {
11361138
output(TypeIds.Constant, Constants.STORE_ALL_PROPS);
1139+
} else if (value === _UNINITIALIZED) {
1140+
output(TypeIds.Constant, Constants.UNINITIALIZED);
11371141
} else {
11381142
throw qError(QError.serializeErrorUnknownType, [typeof value]);
11391143
}
@@ -1788,6 +1792,7 @@ export const enum Constants {
17881792
EMPTY_OBJ,
17891793
NEEDS_COMPUTATION,
17901794
STORE_ALL_PROPS,
1795+
UNINITIALIZED,
17911796
Slot,
17921797
Fragment,
17931798
NaN,

Diff for: packages/qwik/src/core/shared/utils/constants.ts

+3
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@ export const _VAR_PROPS = Symbol('VAR');
55

66
/** @internal @deprecated v1 compat */
77
export const _IMMUTABLE = Symbol('IMMUTABLE');
8+
9+
/** @internal */
10+
export const _UNINITIALIZED = Symbol('UNINITIALIZED');

Diff for: scripts/qwik-router.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ async function buildVite(config: BuildConfig) {
8282
'typescript',
8383
'vite-imagetools',
8484
'svgo',
85+
'@qwik.dev/core',
8586
];
8687

8788
const swRegisterPath = join(config.srcQwikRouterDir, 'runtime', 'src', 'sw-register.ts');
@@ -102,7 +103,6 @@ async function buildVite(config: BuildConfig) {
102103
format: 'esm',
103104
external,
104105
alias: {
105-
'@qwik.dev/core': 'noop',
106106
'@qwik.dev/core/optimizer': 'noop',
107107
},
108108
plugins: [serviceWorkerRegisterBuild(swRegisterCode)],

Diff for: starters/e2e/qwikrouter/nav.e2e.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
scrollTo,
1111
} from "./util.js";
1212

13-
test.describe("actions", () => {
13+
test.describe("nav", () => {
1414
test.describe("mpa", () => {
1515
test.use({ javaScriptEnabled: false });
1616
tests();

0 commit comments

Comments
 (0)