Skip to content

Commit 56619f0

Browse files
committed
refactor(serdes): preload computed qrls
instead of creating the qrl
1 parent 8562782 commit 56619f0

File tree

5 files changed

+19
-23
lines changed

5 files changed

+19
-23
lines changed

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

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/** @file Public APIs for the SSR */
22

3+
// @ts-expect-error we don't have types for the preloader
4+
import { p as preload } from '@qwik.dev/core/preloader';
35
import { assertTrue } from '../shared/error/assert';
46
import { QError, qError } from '../shared/error/error';
57
import { ERROR_CONTEXT, isRecoverable } from '../shared/error/error-handling';
6-
import { type QRLInternal } from '../shared/qrl/qrl-class';
78
import type { QRL } from '../shared/qrl/qrl.public';
8-
import { ChoreType } from '../shared/util-chore-type';
99
import { _SharedContainer } from '../shared/shared-container';
1010
import {
1111
getObjectById,
@@ -21,21 +21,21 @@ import {
2121
ELEMENT_SEQ,
2222
ELEMENT_SEQ_IDX,
2323
OnRenderProp,
24+
QBackRefs,
2425
QBaseAttr,
2526
QContainerAttr,
2627
QContainerSelector,
2728
QCtxAttr,
2829
QInstanceAttr,
30+
QLocaleAttr,
31+
QManifestHashAttr,
2932
QScopedStyle,
3033
QSlotParent,
3134
QStyle,
3235
QStyleSelector,
33-
QBackRefs,
3436
Q_PROPS_SEPARATOR,
3537
USE_ON_LOCAL_SEQ_IDX,
3638
getQFuncs,
37-
QLocaleAttr,
38-
QManifestHashAttr,
3939
} from '../shared/utils/markers';
4040
import { isSlotProp } from '../shared/utils/prop';
4141
import { qDev } from '../shared/utils/qdev';
@@ -55,6 +55,7 @@ import {
5555
type VNode,
5656
type VirtualVNode,
5757
} from './types';
58+
import { mapArray_get, mapArray_has, mapArray_set } from './util-mapArray';
5859
import {
5960
VNodeJournalOpCode,
6061
vnode_applyJournal,
@@ -72,7 +73,6 @@ import {
7273
vnode_setProp,
7374
type VNodeJournal,
7475
} from './vnode';
75-
import { mapArray_get, mapArray_has, mapArray_set } from './util-mapArray';
7676

7777
/** @public */
7878
export function getDomContainer(element: Element | VNode): IClientContainer {
@@ -117,7 +117,7 @@ export class DomContainer extends _SharedContainer implements IClientContainer {
117117
public $qFuncs$: Array<(...args: unknown[]) => unknown>;
118118
public $instanceHash$: string;
119119
public $forwardRefs$: Array<number> | null = null;
120-
public $initialQRLsIndexes$: Array<number> | null = null;
120+
public $initialQRLs$: Array<string> | null = null;
121121
public vNodeLocate: (id: string | Element) => VNode = (id) => vnode_locate(this.rootVNode, id);
122122

123123
private $stateData$: unknown[];
@@ -359,15 +359,14 @@ export class DomContainer extends _SharedContainer implements IClientContainer {
359359
* ```
360360
*/
361361
private $scheduleInitialQRLs$(): void {
362-
if (this.$initialQRLsIndexes$) {
363-
for (const index of this.$initialQRLsIndexes$) {
364-
this.$scheduler$(
365-
ChoreType.QRL_RESOLVE,
366-
null,
367-
this.$getObjectById$(index) as QRLInternal<(...args: unknown[]) => unknown>
368-
);
362+
if (this.$initialQRLs$) {
363+
for (const qrl of this.$initialQRLs$) {
364+
const match = /#(.*)_([a-zA-Z0-9]+)(\[|$)/.exec(qrl);
365+
if (match) {
366+
preload(match[2], 0.3);
367+
}
369368
}
370-
this.$initialQRLsIndexes$ = null;
369+
this.$initialQRLs$ = null;
371370
}
372371
}
373372
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ export interface ClientContainer extends Container {
1818
rootVNode: ElementVNode;
1919
$journal$: VNodeJournal;
2020
$forwardRefs$: Array<number> | null;
21-
$initialQRLsIndexes$: Array<number> | null;
2221
$flushEpoch$: number;
2322
parseQRL<T = unknown>(qrl: string): QRL<T>;
2423
$setRawState$(id: number, vParent: ElementVNode | VirtualVNode): void;

packages/qwik/src/core/qwik.core.api.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ export interface ClientContainer extends Container {
4141
$flushEpoch$: number;
4242
// (undocumented)
4343
$forwardRefs$: Array<number> | null;
44-
// (undocumented)
45-
$initialQRLsIndexes$: Array<number> | null;
4644
// Warning: (ae-forgotten-export) The symbol "VNodeJournal" needs to be exported by the entry point index.d.ts
4745
//
4846
// (undocumented)
@@ -218,7 +216,7 @@ class DomContainer extends _SharedContainer implements ClientContainer {
218216
// (undocumented)
219217
$getObjectById$: (id: number | string) => unknown;
220218
// (undocumented)
221-
$initialQRLsIndexes$: Array<number> | null;
219+
$initialQRLs$: Array<string> | null;
222220
// (undocumented)
223221
$instanceHash$: string;
224222
// (undocumented)

packages/qwik/src/core/shared/shared-serialization.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1673,7 +1673,7 @@ export function _createDeserializeContainer(
16731673
$storeProxyMap$: new WeakMap(),
16741674
element: null,
16751675
$forwardRefs$: null,
1676-
$initialQRLsIndexes$: null,
1676+
$initialQRLs$: null,
16771677
$scheduler$: null,
16781678
};
16791679
preprocessState(stateData, container);
@@ -1784,8 +1784,8 @@ export function preprocessState(data: unknown[], container: DeserializeContainer
17841784
} else if (isForwardRefsMap(data[i] as TypeIds)) {
17851785
container.$forwardRefs$ = data[i + 1] as number[];
17861786
} else if (isPreloadQrlType(data[i] as TypeIds)) {
1787-
container.$initialQRLsIndexes$ ||= [];
1788-
container.$initialQRLsIndexes$.push(i / 2);
1787+
const qrl = data[i + 1] as string;
1788+
(container.$initialQRLs$ ||= []).push(qrl);
17891789
}
17901790
}
17911791
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export interface DeserializeContainer {
1111
$state$?: unknown[];
1212
$storeProxyMap$: ObjToProxyMap;
1313
$forwardRefs$: Array<number> | null;
14-
$initialQRLsIndexes$: Array<number> | null;
14+
$initialQRLs$: Array<string> | null;
1515
readonly $scheduler$: Scheduler | null;
1616
}
1717

0 commit comments

Comments
 (0)