Skip to content

Commit

Permalink
feat: minify scroll restoration shim
Browse files Browse the repository at this point in the history
  • Loading branch information
thejackshelton committed Oct 5, 2024
1 parent 7de4674 commit 0166876
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/qwik-city/src/runtime/src/spa-shim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ import { getPlatform } from '@builder.io/qwik';

import init from './spa-init';

const SPA_SHIM_MINFIED = `const shim=async(t,o,n)=>{if(!window._qcs&&"manual"===history.scrollRestoration){window._qcs=!0;const s=history.state?._qCityScroll;s&&window.scrollTo(s.x,s.y);const i=document.currentScript;if(i){const s=i?.closest("[q\\:container]"),c=new URL(o,new URL(t,document.baseURI));if(isDev){const t=new Function("url","return import(url)");(await t(c.href))[n](s)}else(await import(c.href))[n](s)}}};`;

export default (base: string) => {
if (isServer) {
const [symbol, bundle] = getPlatform().chunkForSymbol(init.getSymbol(), null, init.dev?.file)!;
const args = [base, bundle, symbol].map((x) => JSON.stringify(x)).join(',');
return `(${shim.toString()})(${args});`;
return isDev ? `(${shim.toString()})(${args})` : SPA_SHIM_MINFIED;
}
};

Expand Down

0 comments on commit 0166876

Please sign in to comment.