Skip to content

Commit 4cd9f86

Browse files
committed
wip
1 parent 5063e1c commit 4cd9f86

File tree

8 files changed

+38
-50
lines changed

8 files changed

+38
-50
lines changed

packages/qwik-city/src/buildtime/vite/get-route-imports.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ export function getRouteImports(routes: BuildRoute[], manifest: QwikManifest) {
1212
: [];
1313
const routeAndLayoutPaths = [routePath, ...layoutPaths];
1414

15-
const imports = [];
15+
const bundles = [];
1616

1717
for (const [bundleName, bundle] of Object.entries(manifest.bundles)) {
1818
if (isBundlePartOfRoute(bundle, routeAndLayoutPaths)) {
19-
imports.push(bundleName);
19+
bundles.push(bundleName);
2020
}
2121
}
22-
if (imports.length > 0) {
23-
result[route.routeName] = { imports };
22+
if (bundles.length > 0) {
23+
result[route.routeName] = { dynamicImports: bundles };
2424
}
2525
});
2626
for (const bundleName of Object.keys(manifest.bundles)) {

packages/qwik-city/src/buildtime/vite/get-route-imports.unit.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@ describe('modifyBundleGraph', () => {
5656
expect(actualResult).toMatchInlineSnapshot(`
5757
{
5858
"/": {
59-
"imports": [
59+
"dynamicImports": [
6060
"fake-bundle1.js",
6161
],
6262
},
6363
"/subroute": {
64-
"imports": [
64+
"dynamicImports": [
6565
"fake-bundle-part-of-sub-route.js",
6666
"fake-bundle-part-of-layout.js",
6767
],
@@ -102,7 +102,7 @@ describe('modifyBundleGraph', () => {
102102
expect(actualResult).toMatchInlineSnapshot(`
103103
{
104104
"/": {
105-
"imports": [
105+
"dynamicImports": [
106106
"fake-bundle1.js",
107107
"fake-bundle2.js",
108108
],

packages/qwik-labs/src-vite/insights/index.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { type QwikVitePlugin } from '@builder.io/qwik/optimizer';
1+
import { type QwikVitePlugin, type SmartEntryStrategy } from '@builder.io/qwik/optimizer';
22
import { existsSync, mkdirSync } from 'node:fs';
33
import { readFile, writeFile } from 'node:fs/promises';
44
import { join, resolve } from 'node:path';
@@ -63,9 +63,6 @@ export async function qwikInsights(qwikInsightsOpts: {
6363
throw new Error('Missing vite-plugin-qwik');
6464
}
6565
const opts = qwikVitePlugin.api.getOptions();
66-
if (opts.entryStrategy.type !== 'smart') {
67-
return;
68-
}
6966
if (isProd) {
7067
try {
7168
const qManifest: InsightManifest = { manual: {}, prefetch: [] };
@@ -85,9 +82,12 @@ export async function qwikInsights(qwikInsightsOpts: {
8582
}
8683

8784
if (data) {
88-
opts.entryStrategy.manual = { ...data.manual, ...opts.entryStrategy.manual };
85+
(opts.entryStrategy as SmartEntryStrategy).manual = {
86+
...data.manual,
87+
...(opts.entryStrategy as SmartEntryStrategy).manual,
88+
};
8989

90-
qwikVitePlugin.api.registerBundleGraphAdder(() => {
90+
qwikVitePlugin.api.registerBundleGraphAdder((manifest) => {
9191
const result: Record<
9292
string,
9393
{ imports?: string[] | undefined; dynamicImports?: string[] | undefined }
@@ -101,7 +101,7 @@ export async function qwikInsights(qwikInsightsOpts: {
101101
if (!route.endsWith('/')) {
102102
route += '/';
103103
}
104-
result[route] = { imports: item.symbols };
104+
result[route] = { ...manifest.bundles[route], imports: item.symbols };
105105
}
106106
}
107107
return result;

packages/qwik/src/core/preloader.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ const preloadStr = 'preload';
5858

5959
let highCount = 0;
6060
let lowCount = 0;
61-
const max = 11;
6261
/**
6362
* This is called when a bundle is queued or finished loading.
6463
*
@@ -68,11 +67,11 @@ const max = 11;
6867
* We make sure to first empty the high priority items, first-in-last-out.
6968
*/
7069
const trigger = () => {
71-
while (highCount < max && high.length) {
70+
while (highCount < 8 && high.length) {
7271
const bundle = high.pop()!;
7372
preloadOne(bundle!, true);
7473
}
75-
while (highCount + lowCount < max && low.length) {
74+
while (highCount + lowCount < 4 && low.length) {
7675
const bundle = low.pop()!;
7776
preloadOne(bundle!);
7877
}
@@ -127,7 +126,8 @@ const preloadOne = (bundle: BundleImport, priority?: boolean) => {
127126
preload(bundle.$imports$, priority);
128127
preload(bundle.$dynamicImports$);
129128
} else {
130-
preload([...bundle.$imports$, ...bundle.$dynamicImports$]);
129+
// only preload direct imports, low priority
130+
preload(bundle.$imports$);
131131
}
132132
};
133133

@@ -154,7 +154,7 @@ const ensureBundle = (name: string) => {
154154
return bundle;
155155
};
156156

157-
const parseBundleGraph = (text: string, base: string) => {
157+
const parseBundleGraph = (text: string) => {
158158
const graph = JSON.parse(text) as QwikBundleGraph;
159159
let i = 0;
160160
// All existing loading bundles need imports processed
@@ -225,7 +225,7 @@ const loadBundleGraph = (basePath: string, manifestHash: string) => {
225225
// TODO check TTI, maybe inject fetch link with timeout so we don't do the fetch directly
226226
fetch(`${basePath}q-bundle-graph-${manifestHash}.json`)
227227
.then((res) => res.text())
228-
.then((text) => parseBundleGraph(text, basePath))
228+
.then((text) => parseBundleGraph(text))
229229
// We warn because it's not critical, and in the CI tests Windows serves up a HTML file instead the bundle graph sometimes, which breaks the tests that don't expect error logs
230230
.catch(console.warn);
231231
};

packages/qwik/src/core/qrl/qrl-class.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ export const createQRL = <TYPE>(
231231
seal(qrl);
232232
}
233233
console.warn('QRL created', symbol);
234-
preload(hash, true);
234+
preload(hash);
235235
return qrl;
236236
};
237237

packages/qwik/src/optimizer/src/plugins/bundle-graph.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export function convertManifestToBundleGraph(
6161

6262
// We only include dynamic imports that have qrl segments
6363
// If the dev wants to include other dynamic imports, they can just make a qrl()
64-
const dynamicImports = bundle.dynamicImports?.filter((dep) => graph[dep]) || [];
64+
const dynamicImports = bundle.dynamicImports?.filter((dep) => graph[dep]?.hasSegments) || [];
6565

6666
// Overwrite so we don't mutate
6767
graph[bundleName] = {

packages/qwik/src/optimizer/src/plugins/bundle-graph.unit.ts

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ describe('convertManifestToBundleGraph', () => {
4444
version: '1.0.0',
4545
} as QwikManifest;
4646

47-
test.skip('trivial example', () => {
47+
test('trivial example', () => {
4848
expect(convertManifestToBundleGraph(fakeManifest)).toEqual([
4949
'app.js', // 0
5050
2,
@@ -101,7 +101,7 @@ describe('convertManifestToBundleGraph', () => {
101101
]);
102102
});
103103

104-
test.skip('adder', () => {
104+
test('adder', () => {
105105
expect(
106106
convertManifestToBundleGraph(
107107
fakeManifest,
@@ -156,35 +156,27 @@ describe('convertManifestToBundleGraph', () => {
156156
expect(convertManifestToBundleGraph(manifest)).toMatchInlineSnapshot(`
157157
[
158158
"app.js",
159-
30,
160-
31,
159+
22,
160+
23,
161161
-1,
162162
19,
163163
"app.tsx_App_component_div_div_div_div_div_div_button_onClick_1_WC1qsF4RHoU.js",
164164
0,
165165
"app.tsx_App_component_div_div_div_div_div_div_button_onClick_2_cibDwmrlmRI.js",
166166
0,
167167
"app.tsx_App_component_div_div_div_div_div_div_button_onClick_3_dHjr9JWbW34.js",
168-
30,
168+
22,
169169
"app.tsx_App_component_div_div_div_div_div_div_button_onClick_4_5fYbrS6ABNA.js",
170-
30,
170+
22,
171171
"app.tsx_App_component_div_div_div_div_div_div_button_onClick_5_rpMfjSetIeI.js",
172-
30,
172+
22,
173173
"app.tsx_App_component_div_div_div_div_div_div_button_onClick_wEyctjlC58Q.js",
174174
0,
175175
"app.tsx_App_component_div_table_tbody_tr_td_a_onClick_DDeCLEw4BYU.js",
176-
30,
176+
22,
177177
"app.tsx_App_component_jn5XSz7NZ88.js",
178-
30,
179-
31,
180-
-1,
181-
5,
182-
7,
183-
9,
184-
11,
185-
13,
186-
15,
187-
17,
178+
22,
179+
23,
188180
"core.js",
189181
"preload-helper.js",
190182
"root.js",

packages/qwik/src/server/prefetch-implementation.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -143,26 +143,22 @@ function linkJsImplementation(
143143
}
144144
const manifestHash = manifest.manifestHash;
145145
const urls = flattenPrefetchResources(prefetchResources);
146-
const fetchPriority = prefetchImpl.linkFetchPriority;
147-
const forceLow = fetchPriority === 'low';
148146
const prio = [];
149-
const low = [];
150147
for (const [url, priority] of urls) {
151-
if (!priority || forceLow) {
152-
low.push(url);
153-
} else {
148+
// we only want the static imports, the rest will follow as needed
149+
if (priority) {
154150
prio.push(url);
155151
}
156152
}
157153

158154
// TODO modulepreload the preloader before ssr, optional because we can't predict if we need it
159-
if (urls.size) {
160-
// We mark all the urls as low priority, so that newly needed urls are loaded first
155+
if (prio.length) {
156+
// We mark all the urls as low priority, so that newly needed resources are loaded first
161157
// We use a Promise so the script doesn't block the initial page load
162158
const script = `
163159
import("${base}${preloadChunk}").then(({l,p})=>{
164160
l(${JSON.stringify(base)},${JSON.stringify(manifestHash)});
165-
p(${JSON.stringify([...prio, ...low])});
161+
p(${JSON.stringify(prio.slice(0, 10))});
166162
})
167163
`.replaceAll(/^\s+|\s*\n/gm, '');
168164

@@ -174,7 +170,7 @@ function linkJsImplementation(
174170
href: `${base}q-bundle-graph-${manifestHash}.json`,
175171
as: 'fetch',
176172
crossorigin: 'anonymous',
177-
fetchpriority: prefetchImpl.linkFetchPriority || undefined,
173+
fetchpriority: 'low',
178174
})
179175
);
180176
prefetchNodes.push(

0 commit comments

Comments
 (0)