Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(sync$): serialize "minified" function #6944

Merged
merged 1 commit into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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