Skip to content

Commit 28de164

Browse files
authored
Merge pull request #7933 from QwikDev/v2-eager-deserialize
chore(serdes): eager deserialization
2 parents 8e108d2 + dd1f32d commit 28de164

File tree

8 files changed

+486
-491
lines changed

8 files changed

+486
-491
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/client/vnode.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1577,14 +1577,30 @@ function setEffectBackRefFromVNodeData(
15771577
value: string | number,
15781578
container: ClientContainer
15791579
) {
1580-
const deserializedSubMap = container.$getObjectById$(value);
15811580
if (!(vParent as any)[_EFFECT_BACK_REF]) {
1581+
// get data lazily
1582+
// this is because effects back refs can point to vnodes which are not yet materialized
1583+
// (are after the current vnode)
15821584
Object.defineProperty(vParent, _EFFECT_BACK_REF, {
1583-
value: deserializedSubMap,
1585+
get() {
1586+
const subMap = container.$getObjectById$(value);
1587+
(vParent as any)[_EFFECT_BACK_REF] = subMap;
1588+
return subMap;
1589+
},
1590+
set(value: unknown) {
1591+
Object.defineProperty(vParent, _EFFECT_BACK_REF, {
1592+
value,
1593+
writable: true,
1594+
enumerable: true,
1595+
configurable: true,
1596+
});
1597+
},
1598+
enumerable: true,
1599+
configurable: true,
15841600
});
15851601
} else {
1586-
const subMap = (vParent as any)[_EFFECT_BACK_REF] as Map<string, any>;
1587-
mergeMaps(subMap, deserializedSubMap);
1602+
const subMap = (vParent as any)[_EFFECT_BACK_REF];
1603+
mergeMaps(subMap, container.$getObjectById$(value));
15881604
}
15891605
}
15901606

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)

0 commit comments

Comments
 (0)