From 24cf2d98f555d8c1d006dcf7949b381eae56181b Mon Sep 17 00:00:00 2001 From: Wout Mertens Date: Mon, 7 Oct 2024 23:29:47 +0200 Subject: [PATCH] fix(sync$): serialize "minified" function --- .changeset/shaggy-apes-kneel.md | 5 +++++ .changeset/silver-countries-kiss.md | 2 +- .../src/runtime/src/router-outlet-component.tsx | 15 +++++++++------ packages/qwik/src/core/qrl/qrl.public.ts | 1 + packages/qwik/src/core/qrl/qrl.ts | 2 +- 5 files changed, 17 insertions(+), 8 deletions(-) create mode 100644 .changeset/shaggy-apes-kneel.md diff --git a/.changeset/shaggy-apes-kneel.md b/.changeset/shaggy-apes-kneel.md new file mode 100644 index 00000000000..3330fd795e9 --- /dev/null +++ b/.changeset/shaggy-apes-kneel.md @@ -0,0 +1,5 @@ +--- +'@builder.io/qwik': patch +--- + +sync$ QRLs will now be serialized into the HTML in a shorter form diff --git a/.changeset/silver-countries-kiss.md b/.changeset/silver-countries-kiss.md index 4c9e7524e0e..e83044e5f1b 100644 --- a/.changeset/silver-countries-kiss.md +++ b/.changeset/silver-countries-kiss.md @@ -1,5 +1,5 @@ --- -'@builder.io/qwik-city': minor +'@builder.io/qwik-city': patch --- Prevent unexpected caching for q-data.json diff --git a/packages/qwik-city/src/runtime/src/router-outlet-component.tsx b/packages/qwik-city/src/runtime/src/router-outlet-component.tsx index 5d2c789d221..dfb22fe3697 100644 --- a/packages/qwik-city/src/runtime/src/router-outlet-component.tsx +++ b/packages/qwik-city/src/runtime/src/router-outlet-component.tsx @@ -41,13 +41,16 @@ export const RouterOutlet = component$(() => { document:onQCInit$={spaInit} document:onQInit$={sync$(() => { // Minify window and history - ((window: ClientSPAWindow, history: History & { state?: ScrollHistoryState }) => { - if (!window._qcs && history.scrollRestoration === 'manual') { - window._qcs = true; + // Write this as minified as possible, the optimizer does not really minify this code. + ((w: ClientSPAWindow, h: History & { state?: ScrollHistoryState }) => { + if (!w._qcs && h.scrollRestoration === 'manual') { + // true + w._qcs = !0; - const scrollState = history.state?._qCityScroll; - if (scrollState) { - window.scrollTo(scrollState.x, scrollState.y); + // scrollState + const s = h.state?._qCityScroll; + if (s) { + w.scrollTo(s.x, s.y); } document.dispatchEvent(new Event('qcinit')); } diff --git a/packages/qwik/src/core/qrl/qrl.public.ts b/packages/qwik/src/core/qrl/qrl.public.ts index a8024270766..2d3aa303dc8 100644 --- a/packages/qwik/src/core/qrl/qrl.public.ts +++ b/packages/qwik/src/core/qrl/qrl.public.ts @@ -332,5 +332,6 @@ export const _qrlSync = function ( if (serializedFn === undefined) { serializedFn = fn.toString(); } + (fn as any).serialized = serializedFn; return createQRL('', SYNC_QRL, fn, null, null, null, null) as any; }; diff --git a/packages/qwik/src/core/qrl/qrl.ts b/packages/qwik/src/core/qrl/qrl.ts index 5e12afd3804..fbb7b00217b 100644 --- a/packages/qwik/src/core/qrl/qrl.ts +++ b/packages/qwik/src/core/qrl/qrl.ts @@ -199,7 +199,7 @@ export const serializeQRL = (qrl: QRLInternal, opts: QRLSerializeOptions = {}) = if (opts.$containerState$) { const fn = qrl.resolved as Function; const containerState = opts.$containerState$; - const fnStrKey = fn.toString(); + const fnStrKey = ((fn as any).serialized as string) || fn.toString(); let id = containerState.$inlineFns$.get(fnStrKey); if (id === undefined) { id = containerState.$inlineFns$.size;