Skip to content

Commit b0b61a7

Browse files
authored
Merge pull request #7610 from QwikDev/tweak-preloader
2 parents adf20ca + 0dae1e2 commit b0b61a7

File tree

20 files changed

+240
-122
lines changed

20 files changed

+240
-122
lines changed

packages/docs/src/repl/worker/repl-request-handler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ const injectDevHtml = (clientId: string, html?: string) => {
133133
});
134134
135135
document.addEventListener('qsymbol', (ev) => {
136-
const symbolName = ev.detail;
136+
const symbolName = ev.detail?.symbol;
137137
sendToServerWindow({
138138
kind: 'symbol',
139139
scope: 'client',

packages/docs/src/root.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,5 +76,7 @@ export default component$(() => {
7676

7777
export function collectSymbols() {
7878
(window as any).symbols = [];
79-
document.addEventListener('qsymbol', (e) => (window as any).symbols.push((e as any).detail));
79+
document.addEventListener('qsymbol', (e) =>
80+
(window as any).symbols.push((e as any).detail.symbol)
81+
);
8082
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@
166166
}
167167
],
168168
"kind": "Interface",
169-
"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\n[base?](#)\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\n[containerAttributes?](#)\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\n[containerTagName?](#)\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\n[locale?](#)\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\n[prefetchStrategy?](#)\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\n[preloader?](#)\n\n\n</td><td>\n\n\n</td><td>\n\n[PreloaderOptions](#preloaderoptions) \\| boolean\n\n\n</td><td>\n\n_(Optional)_\n\n\n</td></tr>\n<tr><td>\n\n[qwikLoader?](#)\n\n\n</td><td>\n\n\n</td><td>\n\n[QwikLoaderOptions](#qwikloaderoptions)\n\n\n</td><td>\n\n_(Optional)_ Specifies if the Qwik Loader script is added to the document or not.\n\nDefaults to `{ include: true }`<!-- -->.\n\n\n</td></tr>\n<tr><td>\n\n[qwikPrefetchServiceWorker?](#)\n\n\n</td><td>\n\n\n</td><td>\n\nQwikPrefetchServiceWorkerOptions\n\n\n</td><td>\n\n_(Optional)_\n\n\n</td></tr>\n<tr><td>\n\n[serverData?](#)\n\n\n</td><td>\n\n\n</td><td>\n\nRecord&lt;string, any&gt;\n\n\n</td><td>\n\n_(Optional)_\n\n\n</td></tr>\n<tr><td>\n\n[snapshot?](#)\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>",
169+
"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\n[base?](#)\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\n[containerAttributes?](#)\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\n[containerTagName?](#)\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\n[locale?](#)\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\n[prefetchStrategy?](#)\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\n[preloader?](#)\n\n\n</td><td>\n\n\n</td><td>\n\n[PreloaderOptions](#preloaderoptions) \\| false\n\n\n</td><td>\n\n_(Optional)_\n\n\n</td></tr>\n<tr><td>\n\n[qwikLoader?](#)\n\n\n</td><td>\n\n\n</td><td>\n\n[QwikLoaderOptions](#qwikloaderoptions)\n\n\n</td><td>\n\n_(Optional)_ Specifies if the Qwik Loader script is added to the document or not.\n\nDefaults to `{ include: true }`<!-- -->.\n\n\n</td></tr>\n<tr><td>\n\n[qwikPrefetchServiceWorker?](#)\n\n\n</td><td>\n\n\n</td><td>\n\nQwikPrefetchServiceWorkerOptions\n\n\n</td><td>\n\n_(Optional)_\n\n\n</td></tr>\n<tr><td>\n\n[serverData?](#)\n\n\n</td><td>\n\n\n</td><td>\n\nRecord&lt;string, any&gt;\n\n\n</td><td>\n\n_(Optional)_\n\n\n</td></tr>\n<tr><td>\n\n[snapshot?](#)\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>",
170170
"editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/server/types.ts",
171171
"mdFile": "qwik.renderoptions.md"
172172
},

packages/docs/src/routes/api/qwik-server/index.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,7 @@ _(Optional)_
715715
716716
</td><td>
717717
718-
[PreloaderOptions](#preloaderoptions) \| boolean
718+
[PreloaderOptions](#preloaderoptions) \| false
719719
720720
</td><td>
721721

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2194,7 +2194,7 @@
21942194
}
21952195
],
21962196
"kind": "TypeAlias",
2197-
"content": "Emitted by qwik-loader when a module was lazily loaded\n\n\n```typescript\nexport type QwikSymbolEvent = CustomEvent<{\n symbol: string;\n element: Element;\n reqTime: number;\n}>;\n```",
2197+
"content": "Emitted by qwik-loader when a module was lazily loaded\n\n\n```typescript\nexport type QwikSymbolEvent = CustomEvent<{\n symbol: string;\n element: Element;\n reqTime: number;\n qBase?: string;\n qManifest?: string;\n qVersion?: string;\n href?: string;\n}>;\n```",
21982198
"editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik/src/core/render/jsx/types/jsx-qwik-events.ts",
21992199
"mdFile": "qwik.qwiksymbolevent.md"
22002200
},

packages/docs/src/routes/api/qwik/index.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4383,6 +4383,10 @@ export type QwikSymbolEvent = CustomEvent<{
43834383
symbol: string;
43844384
element: Element;
43854385
reqTime: number;
4386+
qBase?: string;
4387+
qManifest?: string;
4388+
qVersion?: string;
4389+
href?: string;
43864390
}>;
43874391
```
43884392

packages/docs/src/routes/docs/(qwikcity)/guides/bundle/index.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ To collect symbol usage from a running application:
139139
```html
140140
<script>
141141
window.symbols = [];
142-
document.addEventListener('qsymbol', (e) => window.symbols.push(e.detail));
142+
document.addEventListener('qsymbol', (e) => window.symbols.push(e.detail.symbol));
143143
</script>
144144
```
145145
2. Perform some set of operations mimicking user behavior.

packages/qwik/src/core/preloader/bundle-graph.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { isBrowser } from '@builder.io/qwik/build';
2-
import { config, doc } from './constants';
2+
import { config, isJSRegex } from './constants';
33
import { adjustProbabilities, bundles, log, shouldResetFactor, trigger } from './queue';
44
import type { BundleGraph, BundleImport, ImportProbability } from './types';
55
import { BundleImportState_None, BundleImportState_Alias } from './types';
@@ -8,15 +8,9 @@ export let base: string | undefined;
88
export let graph: BundleGraph;
99

1010
const makeBundle = (name: string, deps?: ImportProbability[]) => {
11-
const url = name.endsWith('.js')
12-
? doc
13-
? new URL(`${base}${name}`, doc.baseURI).toString()
14-
: name
15-
: null;
1611
return {
1712
$name$: name,
18-
$url$: url,
19-
$state$: url ? BundleImportState_None : BundleImportState_Alias,
13+
$state$: isJSRegex.test(name) ? BundleImportState_None : BundleImportState_Alias,
2014
$deps$: shouldResetFactor ? deps?.map((d) => ({ ...d, $factor$: 1 })) : deps,
2115
$inverseProbability$: 1,
2216
$createdTs$: Date.now(),
@@ -37,7 +31,11 @@ export const parseBundleGraph = (serialized: (string | number)[]) => {
3731
if (idx < 0) {
3832
probability = -idx / 10;
3933
} else {
40-
deps.push({ $name$: serialized[idx] as string, $probability$: probability, $factor$: 1 });
34+
deps.push({
35+
$name$: serialized[idx] as string,
36+
$importProbability$: probability,
37+
$factor$: 1,
38+
});
4139
}
4240
i++;
4341
}

packages/qwik/src/core/preloader/constants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,5 @@ export const rel =
1919

2020
// Global state
2121
export const loadStart = Date.now();
22+
23+
export const isJSRegex = /\.[mc]?js$/;

packages/qwik/src/core/preloader/preloader.unit.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,5 @@ test('preloader script', () => {
2121
* dereference objects etc, but that actually results in worse compression
2222
*/
2323
const compressed = compress(Buffer.from(preLoader), { mode: 1, quality: 11 });
24-
expect(compressed.length).toBe(1722);
25-
expect(preLoader.length).toBe(5107);
24+
expect([compressed.length, preLoader.length]).toEqual([1878, 5614]);
2625
});

0 commit comments

Comments
 (0)