Skip to content

Commit

Permalink
fix(sync$): serialize "minified" function
Browse files Browse the repository at this point in the history
  • Loading branch information
wmertens committed Oct 7, 2024
1 parent 3c2163f commit 24cf2d9
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/shaggy-apes-kneel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@builder.io/qwik': patch
---

sync$ QRLs will now be serialized into the HTML in a shorter form
2 changes: 1 addition & 1 deletion .changeset/silver-countries-kiss.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
'@builder.io/qwik-city': minor
'@builder.io/qwik-city': patch
---

Prevent unexpected caching for q-data.json
15 changes: 9 additions & 6 deletions packages/qwik-city/src/runtime/src/router-outlet-component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
}
Expand Down
1 change: 1 addition & 0 deletions packages/qwik/src/core/qrl/qrl.public.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,5 +332,6 @@ export const _qrlSync = function <TYPE extends Function>(
if (serializedFn === undefined) {
serializedFn = fn.toString();
}
(fn as any).serialized = serializedFn;
return createQRL<TYPE>('', SYNC_QRL, fn, null, null, null, null) as any;
};
2 changes: 1 addition & 1 deletion packages/qwik/src/core/qrl/qrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 24cf2d9

Please sign in to comment.