Skip to content

Commit 8e07b9b

Browse files
authored
Merge pull request #8518 from QwikDev/cleanup-preloader-queue
refactor: cleanup preloader
2 parents 005e34e + 767bfc1 commit 8e07b9b

22 files changed

Lines changed: 131 additions & 772 deletions

File tree

.changeset/sweet-paths-retire.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
'@qwik.dev/core': major
3+
---
4+
5+
We removed the following `renderToStream` APIs:
6+
- `preloads.ssrPreloadProbability` and `preloads.preloadProbability` APIs because the number of simultaneous idle preloads should be easy to determine for the developer.
7+
- `preloads.debug` API because it hasn't really proved useful after a full year of modulepreloads.
8+
- the deprecated Service Worker `prefetchStrategy` API.

e2e/qwik-e2e/apps/preloader-test/src/entry.ssr.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ import Root from './root';
1515
export default function (opts: RenderToStreamOptions) {
1616
return renderToStream(<Root />, {
1717
preloader: {
18-
debug: false,
19-
ssrPreloads: 0,
18+
ssrPreloads: 5,
2019
maxIdlePreloads: 1,
2120
},
2221
...opts,
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<!DOCTYPE html><html lang="en" q:render="static-ssr" q:route="/" q:container="paused" q:runtime="2" q:base="/build/" q:locale="" q:manifest-hash="MANIFEST_HASH" q:instance="[instance]" :><head :><link rel="modulepreload" href="/build/q-xxxxxxxx.js" :><script async type="module" src="/build/q-xxxxxxxx.js" :></script><link rel="modulepreload" href="/build/q-xxxxxxxx.js" :><link rel="preload" href="/assets/xxxxxxxx-bundle-graph.json" as="fetch" crossorigin="anonymous" :><script type="module" async crossorigin="anonymous" :>let b=fetch("/assets/xxxxxxxx-bundle-graph.json");import("/build/q-xxxxxxxx.js").then(({l})=>l("/build/",b));</script><link rel="modulepreload" href="/build/q-xxxxxxxx.js" :><meta : charset="utf-8"><meta : name="viewport" content="width=device-width, initial-scale=1.0"><link : rel="canonical" href="https://snapshot.qwik.dev/"><title :="r5_0">Qwik Router SSG Snapshot</title><meta name="description" content="Deterministic SSG snapshot fixture" :="r5_1"><style :="ji2uyl-0" q:style="ji2uyl-0">@layer qwik{@supports selector(html:active-view-transition-type(type)){html:active-view-transition-type(qwik-navigation){:root{view-transition-name:none}}}@supports not selector(html:active-view-transition-type(type)){:root{view-transition-name:none}}}</style></head><body :><main :="q1_2"><h1 :>SSG Snapshot Fixture</h1><p : id="tags">routeLoader$ | useResource$ | useSignal</p><section : id="loader-json">{&quot;heading&quot;:&quot;SSG Snapshot Fixture&quot;,&quot;stats&quot;:[2,3,5,8],&quot;tags&quot;:[&quot;routeLoader$&quot;,&quot;useResource$&quot;,&quot;useSignal&quot;],&quot;profile&quot;:{&quot;name&quot;:&quot;router-state&quot;,&quot;status&quot;:&quot;stable&quot;}}</section><section : id="summary-json">{&quot;total&quot;:18,&quot;selectedCount&quot;:2,&quot;clicks&quot;:2}</section><section :="q1_0" id="resource-json">{&quot;headline&quot;:&quot;router-state:stable&quot;,&quot;selected&quot;:[&quot;alpha&quot;,&quot;beta&quot;],&quot;weighted&quot;:[2,6,15,32],&quot;summary&quot;:{&quot;total&quot;:18,&quot;selectedCount&quot;:2,&quot;clicks&quot;:2}}</section></main><script q-d:qinit="q-xxxxxxxx.js#_run#1" q-d:qrouterpopstate="q-xxxxxxxx.js#_run#2" q:p="3" :="Fn_1" q-d:qcinit="q-xxxxxxxx.js#_run#4"></script>[state omitted]
22
[vnode map omitted]
3-
<script type="module" async="true" q:type="preload" :>window.addEventListener('load',f=>{f=_=>import("/build/q-xxxxxxxx.js").then(({p})=>p(["q-xxxxxxxx.js","q-xxxxxxxx.js","q-xxxxxxxx.js","q-xxxxxxxx.js","q-xxxxxxxx.js","q-xxxxxxxx.js","q-xxxxxxxx.js"]));try{requestIdleCallback(f,{timeout:2000})}catch(e){setTimeout(f,200)}})</script><script q:func="qwik/json" :>document["qFuncs_xxxxxx"]=[()=>{((w,h)=>{if(!w._qcs){w._qcs=!0;const s=h.state?._qRouterScroll;if(s){h.scrollRestoration="manual";w.scrollTo(s.x,s.y);}document.dispatchEvent(new Event("qcinit"));}})(window,history);},(p0)=>p0.url.href,(p0)=>p0.value.heading]</script><script :>(window._qwikEv||(window._qwikEv=[])).push("d:qinit","d:qrouterpopstate","d:qcinit")</script></body></html>
3+
<script type="module" async="true" q:type="preload" :>["q-xxxxxxxx.js","q-xxxxxxxx.js","q-xxxxxxxx.js","q-xxxxxxxx.js","q-xxxxxxxx.js","q-xxxxxxxx.js"].map((l,e)=>{e=document.createElement('link');e.rel='modulepreload';e.href="/build/"+l;document.head.appendChild(e)});window.addEventListener('load',f=>{f=_=>import("/build/q-xxxxxxxx.js").then(({p})=>p(["q-xxxxxxxx.js","q-xxxxxxxx.js","q-xxxxxxxx.js","q-xxxxxxxx.js","q-xxxxxxxx.js","q-xxxxxxxx.js","q-xxxxxxxx.js"]));try{requestIdleCallback(f,{timeout:2000})}catch(e){setTimeout(f,200)}})</script><script q:func="qwik/json" :>document["qFuncs_xxxxxx"]=[()=>{((w,h)=>{if(!w._qcs){w._qcs=!0;const s=h.state?._qRouterScroll;if(s){h.scrollRestoration="manual";w.scrollTo(s.x,s.y);}document.dispatchEvent(new Event("qcinit"));}})(window,history);},(p0)=>p0.url.href,(p0)=>p0.value.heading]</script><script :>(window._qwikEv||(window._qwikEv=[])).push("d:qinit","d:qrouterpopstate","d:qcinit")</script></body></html>

packages/docs/src/entry.ssr.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { createRenderer } from '@qwik.dev/router';
22
import Root from './root';
33

44
// You can pass these as query parameters, as well as `preloadDebug`
5-
const preloaderSettings = ['ssrPreloads', 'ssrPreloadProbability', 'maxIdlePreloads'] as const;
5+
const preloaderSettings = ['ssrPreloads', 'maxIdlePreloads'] as const;
66

77
export default createRenderer((opts) => {
88
const { serverData } = opts;
@@ -16,9 +16,6 @@ export default createRenderer((opts) => {
1616
...(typeof opts.preloader === 'object' ? opts.preloader : undefined),
1717
},
1818
};
19-
if (searchParams.has('preloaderDebug')) {
20-
newOpts.preloader!.debug = true;
21-
}
2219
for (const type of preloaderSettings) {
2320
if (searchParams.has(type)) {
2421
newOpts.preloader[type] = Number(searchParams.get(type));

packages/docs/src/repl/bundler/repl-ssr-worker.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ async function executeSSR(message: InitSSRMessage): Promise<{ html: string; even
109109
const ssrResult = await render({
110110
base: baseUrl,
111111
manifest,
112-
prefetchStrategy: null,
113112
preloader: false,
114113
});
115114

packages/docs/src/routes/api/qwik-server/api.json

Lines changed: 2 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -86,20 +86,6 @@
8686
"editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/server/types.ts",
8787
"mdFile": "core.inorderstreaming.md"
8888
},
89-
{
90-
"name": "PrefetchImplementation",
91-
"id": "prefetchimplementation",
92-
"hierarchy": [
93-
{
94-
"name": "PrefetchImplementation",
95-
"id": "prefetchimplementation"
96-
}
97-
],
98-
"kind": "Interface",
99-
"content": "> Warning: This API is now obsolete.\n> \n> Use `preloader` instead\n> \n\n\n```typescript\nexport interface PrefetchImplementation \n```\n\n\n<table><thead><tr><th>\n\nProperty\n\n\n</th><th>\n\nModifiers\n\n\n</th><th>\n\nType\n\n\n</th><th>\n\nDescription\n\n\n</th></tr></thead>\n<tbody><tr><td>\n\nlinkFetchPriority?\n\n\n</td><td>\n\n\n</td><td>\n\n'auto' \\| 'low' \\| 'high' \\| null\n\n\n</td><td>\n\n_(Optional)_\n\n\n</td></tr>\n<tr><td>\n\nlinkInsert?\n\n\n</td><td>\n\n\n</td><td>\n\n'js-append' \\| 'html-append' \\| null\n\n\n</td><td>\n\n_(Optional)_\n\n\n</td></tr>\n<tr><td>\n\nlinkRel?\n\n\n</td><td>\n\n\n</td><td>\n\n'prefetch' \\| 'preload' \\| 'modulepreload' \\| null\n\n\n</td><td>\n\n_(Optional)_\n\n\n</td></tr>\n<tr><td>\n\nprefetchEvent?\n\n\n</td><td>\n\n\n</td><td>\n\n'always' \\| null\n\n\n</td><td>\n\n_(Optional)_\n\n\n</td></tr>\n<tr><td>\n\nworkerFetchInsert?\n\n\n</td><td>\n\n\n</td><td>\n\n'always' \\| 'no-link-support' \\| null\n\n\n</td><td>\n\n_(Optional)_\n\n\n</td></tr>\n</tbody></table>",
100-
"editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/server/types.ts",
101-
"mdFile": "core.prefetchimplementation.md"
102-
},
10389
{
10490
"name": "PrefetchResource",
10591
"id": "prefetchresource",
@@ -114,20 +100,6 @@
114100
"editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/server/types.ts",
115101
"mdFile": "core.prefetchresource.md"
116102
},
117-
{
118-
"name": "PrefetchStrategy",
119-
"id": "prefetchstrategy",
120-
"hierarchy": [
121-
{
122-
"name": "PrefetchStrategy",
123-
"id": "prefetchstrategy"
124-
}
125-
],
126-
"kind": "Interface",
127-
"content": "```typescript\nexport interface PrefetchStrategy \n```\n\n\n<table><thead><tr><th>\n\nProperty\n\n\n</th><th>\n\nModifiers\n\n\n</th><th>\n\nType\n\n\n</th><th>\n\nDescription\n\n\n</th></tr></thead>\n<tbody><tr><td>\n\nimplementation?\n\n\n</td><td>\n\n\n</td><td>\n\n[PrefetchImplementation](#prefetchimplementation)\n\n\n</td><td>\n\n_(Optional)_\n\n\n</td></tr>\n<tr><td>\n\nsymbolsToPrefetch?\n\n\n</td><td>\n\n\n</td><td>\n\n[SymbolsToPrefetch](#symbolstoprefetch)\n\n\n</td><td>\n\n_(Optional)_\n\n\n</td></tr>\n</tbody></table>",
128-
"editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/server/types.ts",
129-
"mdFile": "core.prefetchstrategy.md"
130-
},
131103
{
132104
"name": "PreloaderOptions",
133105
"id": "preloaderoptions",
@@ -138,7 +110,7 @@
138110
}
139111
],
140112
"kind": "Interface",
141-
"content": "```typescript\nexport interface PreloaderOptions \n```\n\n\n<table><thead><tr><th>\n\nProperty\n\n\n</th><th>\n\nModifiers\n\n\n</th><th>\n\nType\n\n\n</th><th>\n\nDescription\n\n\n</th></tr></thead>\n<tbody><tr><td>\n\ndebug?\n\n\n</td><td>\n\n\n</td><td>\n\nboolean\n\n\n</td><td>\n\n_(Optional)_ Log preloader debug information to the console.\n\nDefaults to `false`\n\n\n</td></tr>\n<tr><td>\n\nmaxIdlePreloads?\n\n\n</td><td>\n\n\n</td><td>\n\nnumber\n\n\n</td><td>\n\n_(Optional)_ Maximum number of simultaneous preload links that the preloader will maintain. If you set this higher, the browser will have all JS files in memory sooner, but it will contend with other resource downloads. Furthermore, if a bundle suddenly becomes more likely, it will have to wait longer to be preloaded.\n\nBundles that reach 100% probability (static imports of other bundles) will always be preloaded immediately, no limit.\n\nDefaults to `25`\n\n\n</td></tr>\n<tr><td>\n\npreloadProbability?\n\n\n</td><td>\n\n\n</td><td>\n\nnumber\n\n\n</td><td>\n\n_(Optional)_\n\n\n</td></tr>\n<tr><td>\n\nssrPreloadProbability?\n\n\n</td><td>\n\n\n</td><td>\n\nnumber\n\n\n</td><td>\n\n_(Optional)_ The minimum probability for a bundle to be added as a preload link during SSR.\n\nDefaults to `0.7` (70% probability)\n\nThis makes sure that the most likely bundles are preloaded ahead of time.\n\n\n</td></tr>\n<tr><td>\n\nssrPreloads?\n\n\n</td><td>\n\n\n</td><td>\n\nnumber\n\n\n</td><td>\n\n_(Optional)_ Maximum number of preload links to add during SSR. These instruct the browser to preload likely bundles before the preloader script is active. This most likely includes the core and the preloader script itself. Setting this to 0 will disable all preload links.\n\nPreload links can delay LCP, which is a Core Web Vital, but it can increase TTI, which is not a Core Web Vital but more noticeable to the user.\n\nDefaults to `5`\n\n\n</td></tr>\n</tbody></table>",
113+
"content": "```typescript\nexport interface PreloaderOptions \n```\n\n\n<table><thead><tr><th>\n\nProperty\n\n\n</th><th>\n\nModifiers\n\n\n</th><th>\n\nType\n\n\n</th><th>\n\nDescription\n\n\n</th></tr></thead>\n<tbody><tr><td>\n\nmaxIdlePreloads?\n\n\n</td><td>\n\n\n</td><td>\n\nnumber\n\n\n</td><td>\n\n_(Optional)_ Maximum number of simultaneous preload links that the preloader will maintain. If you set this higher, the browser will have all JS files in memory sooner, but it will contend with other resource downloads. Furthermore, if a bundle suddenly becomes more likely, it will have to wait longer to be preloaded.\n\nBundles that reach 100% probability (static imports of other bundles) will always be preloaded immediately, no limit.\n\nDefaults to `25`\n\n\n</td></tr>\n<tr><td>\n\nssrPreloads?\n\n\n</td><td>\n\n\n</td><td>\n\nnumber\n\n\n</td><td>\n\n_(Optional)_ Maximum number of preload links to add during SSR. These instruct the browser to preload likely bundles before the preloader script is active. This most likely includes the core and the preloader script itself. Setting this to 0 will disable all preload links.\n\nPreload links can delay LCP, which is a Core Web Vital, but it can increase TTI, which is not a Core Web Vital but more noticeable to the user.\n\nDefaults to `5`\n\n\n</td></tr>\n</tbody></table>",
142114
"editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/server/types.ts",
143115
"mdFile": "core.preloaderoptions.md"
144116
},
@@ -180,7 +152,7 @@
180152
}
181153
],
182154
"kind": "Interface",
183-
"content": "```typescript\nexport interface RenderOptions extends SerializeDocumentOptions \n```\n**Extends:** [SerializeDocumentOptions](#serializedocumentoptions)\n\n\n<table><thead><tr><th>\n\nProperty\n\n\n</th><th>\n\nModifiers\n\n\n</th><th>\n\nType\n\n\n</th><th>\n\nDescription\n\n\n</th></tr></thead>\n<tbody><tr><td>\n\nbase?\n\n\n</td><td>\n\n\n</td><td>\n\nstring \\| ((options: [RenderOptions](#renderoptions)<!-- -->) =&gt; string)\n\n\n</td><td>\n\n_(Optional)_ Specifies the root of the JS files of the client build. Setting a base, will cause the render of the `q:base` attribute in the `q:container` element.\n\n\n</td></tr>\n<tr><td>\n\ncontainerAttributes?\n\n\n</td><td>\n\n\n</td><td>\n\nRecord&lt;string, string&gt;\n\n\n</td><td>\n\n_(Optional)_\n\n\n</td></tr>\n<tr><td>\n\ncontainerTagName?\n\n\n</td><td>\n\n\n</td><td>\n\nstring\n\n\n</td><td>\n\n_(Optional)_ When set, the app is serialized into a fragment. And the returned html is not a complete document. Defaults to `html`\n\n\n</td></tr>\n<tr><td>\n\nlocale?\n\n\n</td><td>\n\n\n</td><td>\n\nstring \\| ((options: [RenderOptions](#renderoptions)<!-- -->) =&gt; string)\n\n\n</td><td>\n\n_(Optional)_ Language to use when rendering the document.\n\n\n</td></tr>\n<tr><td>\n\nprefetchStrategy?\n\n\n</td><td>\n\n\n</td><td>\n\n[PrefetchStrategy](#prefetchstrategy) \\| null\n\n\n</td><td>\n\n_(Optional)_\n\n\n</td></tr>\n<tr><td>\n\npreloader?\n\n\n</td><td>\n\n\n</td><td>\n\n[PreloaderOptions](#preloaderoptions) \\| false\n\n\n</td><td>\n\n_(Optional)_ Specifies how preloading is handled. This ensures that code is instantly available when needed.\n\n\n</td></tr>\n<tr><td>\n\nqwikLoader?\n\n\n</td><td>\n\n\n</td><td>\n\n[QwikLoaderOptions](#qwikloaderoptions)\n\n\n</td><td>\n\n_(Optional)_ Specifies how the Qwik Loader is included in the document. This enables interactivity and lazy loading.\n\n`module`<!-- -->: Use a `<script>` tag to load the Qwik Loader. Subsequent page loads will have the script cached and instantly running.\n\n`inline`<!-- -->: This embeds the Qwik Loader script directly in the document. This adds about 3kB before compression, which typically is reduced to about 1.6kB with gzip.\n\n`never`<!-- -->: Do not include the Qwik Loader script. This is mostly useful when embedding multiple containers on the same page.\n\nDefaults to `module`<!-- -->.\n\nNote that the Qwik Loader is absolutely required for Qwik to work. There must be an instance of it loaded for any interactivity to happen.\n\n\n</td></tr>\n<tr><td>\n\nserverData?\n\n\n</td><td>\n\n\n</td><td>\n\nRecord&lt;string, any&gt;\n\n\n</td><td>\n\n_(Optional)_ Metadata that can be retrieved during SSR with `useServerData()`<!-- -->.\n\n\n</td></tr>\n<tr><td>\n\nsnapshot?\n\n\n</td><td>\n\n\n</td><td>\n\nboolean\n\n\n</td><td>\n\n_(Optional)_ Defaults to `true`\n\n\n</td></tr>\n</tbody></table>",
155+
"content": "```typescript\nexport interface RenderOptions extends SerializeDocumentOptions \n```\n**Extends:** [SerializeDocumentOptions](#serializedocumentoptions)\n\n\n<table><thead><tr><th>\n\nProperty\n\n\n</th><th>\n\nModifiers\n\n\n</th><th>\n\nType\n\n\n</th><th>\n\nDescription\n\n\n</th></tr></thead>\n<tbody><tr><td>\n\nbase?\n\n\n</td><td>\n\n\n</td><td>\n\nstring \\| ((options: [RenderOptions](#renderoptions)<!-- -->) =&gt; string)\n\n\n</td><td>\n\n_(Optional)_ Specifies the root of the JS files of the client build. Setting a base, will cause the render of the `q:base` attribute in the `q:container` element.\n\n\n</td></tr>\n<tr><td>\n\ncontainerAttributes?\n\n\n</td><td>\n\n\n</td><td>\n\nRecord&lt;string, string&gt;\n\n\n</td><td>\n\n_(Optional)_\n\n\n</td></tr>\n<tr><td>\n\ncontainerTagName?\n\n\n</td><td>\n\n\n</td><td>\n\nstring\n\n\n</td><td>\n\n_(Optional)_ When set, the app is serialized into a fragment. And the returned html is not a complete document. Defaults to `html`\n\n\n</td></tr>\n<tr><td>\n\nlocale?\n\n\n</td><td>\n\n\n</td><td>\n\nstring \\| ((options: [RenderOptions](#renderoptions)<!-- -->) =&gt; string)\n\n\n</td><td>\n\n_(Optional)_ Language to use when rendering the document.\n\n\n</td></tr>\n<tr><td>\n\npreloader?\n\n\n</td><td>\n\n\n</td><td>\n\n[PreloaderOptions](#preloaderoptions) \\| false\n\n\n</td><td>\n\n_(Optional)_ Specifies how preloading is handled. This ensures that code is instantly available when needed.\n\n\n</td></tr>\n<tr><td>\n\nqwikLoader?\n\n\n</td><td>\n\n\n</td><td>\n\n[QwikLoaderOptions](#qwikloaderoptions)\n\n\n</td><td>\n\n_(Optional)_ Specifies how the Qwik Loader is included in the document. This enables interactivity and lazy loading.\n\n`module`<!-- -->: Use a `<script>` tag to load the Qwik Loader. Subsequent page loads will have the script cached and instantly running.\n\n`inline`<!-- -->: This embeds the Qwik Loader script directly in the document. This adds about 3kB before compression, which typically is reduced to about 1.6kB with gzip.\n\n`never`<!-- -->: Do not include the Qwik Loader script. This is mostly useful when embedding multiple containers on the same page.\n\nDefaults to `module`<!-- -->.\n\nNote that the Qwik Loader is absolutely required for Qwik to work. There must be an instance of it loaded for any interactivity to happen.\n\n\n</td></tr>\n<tr><td>\n\nserverData?\n\n\n</td><td>\n\n\n</td><td>\n\nRecord&lt;string, any&gt;\n\n\n</td><td>\n\n_(Optional)_ Metadata that can be retrieved during SSR with `useServerData()`<!-- -->.\n\n\n</td></tr>\n<tr><td>\n\nsnapshot?\n\n\n</td><td>\n\n\n</td><td>\n\nboolean\n\n\n</td><td>\n\n_(Optional)_ Defaults to `true`\n\n\n</td></tr>\n</tbody></table>",
184156
"editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/server/types.ts",
185157
"mdFile": "core.renderoptions.md"
186158
},
@@ -366,20 +338,6 @@
366338
"editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/server/types.ts",
367339
"mdFile": "core.streamingoptions.md"
368340
},
369-
{
370-
"name": "SymbolsToPrefetch",
371-
"id": "symbolstoprefetch",
372-
"hierarchy": [
373-
{
374-
"name": "SymbolsToPrefetch",
375-
"id": "symbolstoprefetch"
376-
}
377-
],
378-
"kind": "TypeAlias",
379-
"content": "Auto: Prefetch all possible QRLs used by the document. Default\n\n\n```typescript\nexport type SymbolsToPrefetch = 'auto' | ((opts: {\n manifest: ServerQwikManifest;\n}) => PrefetchResource[]);\n```\n**References:** [PrefetchResource](#prefetchresource)",
380-
"editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/server/types.ts",
381-
"mdFile": "core.symbolstoprefetch.md"
382-
},
383341
{
384342
"name": "versions",
385343
"id": "versions",

0 commit comments

Comments
 (0)