Skip to content

Commit 4189020

Browse files
committed
fix(serdes): dedupe root qrls
1 parent 5e69f41 commit 4189020

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

packages/qwik/src/core/shared/serdes/serdes.unit.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -958,6 +958,21 @@ describe('shared-serialization', () => {
958958
(42 chars)"
959959
`);
960960
});
961+
it('should dedupe identical root qrls', async () => {
962+
const fn = () => 'hi';
963+
const a = {};
964+
const qrl1 = inlinedQrl(fn, 'dump_qrl', [a]);
965+
const qrl2 = inlinedQrl(fn, 'dump_qrl', [a]);
966+
expect(qrl1).not.toBe(qrl2);
967+
const objs = await serialize(qrl1, qrl2);
968+
expect(_dumpState(objs)).toMatchInlineSnapshot(`
969+
"
970+
0 QRL "mock-chunk#dump_qrl[2]"
971+
1 RootRef 0
972+
2 Object []
973+
(38 chars)"
974+
`);
975+
});
961976
});
962977

963978
describe('Serialization Weak Ref', () => {

packages/qwik/src/core/shared/serdes/serialize.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,9 @@ export async function serialize(serializationContext: SerializationContext): Pro
170170
const existing = qrlMap.get(qrl);
171171
if (existing) {
172172
// We encountered the same QRL again, make it a root
173-
$addRoot$(existing);
174-
// We need to force because we might be adding the same root again
175-
if (outputAsRootRef(existing, 0)) {
176-
return;
177-
}
173+
const ref = $addRoot$(existing);
174+
output(TypeIds.RootRef, ref);
175+
return;
178176
} else {
179177
qrlMap.set(qrl, value);
180178
}

0 commit comments

Comments
 (0)