From af01769e01a39932cd47fc169ec5d74d02c304f6 Mon Sep 17 00:00:00 2001 From: Shai Reznik Date: Tue, 3 Dec 2024 01:22:50 +0200 Subject: [PATCH 1/6] add ALL dynamic imports to bundle graph --- packages/qwik/src/optimizer/src/plugins/vite.ts | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/packages/qwik/src/optimizer/src/plugins/vite.ts b/packages/qwik/src/optimizer/src/plugins/vite.ts index 158188f6836..9232f6a4615 100644 --- a/packages/qwik/src/optimizer/src/plugins/vite.ts +++ b/packages/qwik/src/optimizer/src/plugins/vite.ts @@ -1171,18 +1171,16 @@ export function convertManifestToBundleGraph(manifest: QwikManifest): QwikBundle let didAdd = false; for (const depName of bundle.dynamicImports || []) { // If we dynamically import a qrl segment that is not a handler, we'll probably need it soon - const dep = graph[depName]; + // const dep = graph[depName]; if (!graph[depName]) { // external dependency continue; } - if (dep.isTask) { - if (!didAdd) { - deps.add(''); - didAdd = true; - } - deps.add(depName); + if (!didAdd) { + deps.add(''); + didAdd = true; } + deps.add(depName); } map.set(bundleName, { index, deps }); bundleGraph.push(bundleName); From 41562a1a6412a3bab2dc1c5b593c2e5d18de97bf Mon Sep 17 00:00:00 2001 From: Shai Reznik Date: Mon, 16 Dec 2024 14:30:52 +0200 Subject: [PATCH 2/6] infra: added qwik city buildtime folder to 'watch mode" --- scripts/build.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/build.ts b/scripts/build.ts index 11862ab3b34..0f97273f2fe 100644 --- a/scripts/build.ts +++ b/scripts/build.ts @@ -186,6 +186,7 @@ export async function build(config: BuildConfig) { [join(config.srcQwikDir, 'prefetch-service-worker')]: () => submoduleQwikPrefetch(config), [join(config.srcQwikDir, 'server')]: () => submoduleServer(config), [join(config.srcQwikCityDir, 'runtime/src')]: () => buildQwikCity(config), + [join(config.srcQwikCityDir, 'buildtime')]: () => buildQwikCity(config), }); } } catch (e: any) { From b380bdb78ed36885fbcec7929568e20d95be5af0 Mon Sep 17 00:00:00 2001 From: wuls Date: Thu, 19 Dec 2024 13:41:30 +0800 Subject: [PATCH 3/6] feat: Rename "Prefetch SW" to "Preloader" --- .../advanced/speculative-module-fetching/index.mdx | 2 +- packages/qwik/src/core/components/prefetch.ts | 4 ++-- .../qwik/src/prefetch-service-worker/process-message.ts | 2 +- packages/qwik/src/server/prefetch-utils.ts | 2 +- scripts/submodule-qwikprefetch.ts | 6 +++--- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/docs/src/routes/docs/(qwikcity)/advanced/speculative-module-fetching/index.mdx b/packages/docs/src/routes/docs/(qwikcity)/advanced/speculative-module-fetching/index.mdx index 7bd9ed28371..c749ac82a7e 100644 --- a/packages/docs/src/routes/docs/(qwikcity)/advanced/speculative-module-fetching/index.mdx +++ b/packages/docs/src/routes/docs/(qwikcity)/advanced/speculative-module-fetching/index.mdx @@ -195,5 +195,5 @@ Note that this process is only for testing the speculative module fetching, and The service worker in Qwik core, which uses the `` and `` components in `root.tsx` has a debug mode. -To see the service worker logs, add `window.qwikPrefetchSW.push(['verbose', '', []])` to the JavaScript console and press the `Enter` key. +To see the service worker logs, add `window.qwikPreloader.push(['verbose', '', []])` to the JavaScript console and press the `Enter` key. diff --git a/packages/qwik/src/core/components/prefetch.ts b/packages/qwik/src/core/components/prefetch.ts index aa6f3c0d74f..e764a07e029 100644 --- a/packages/qwik/src/core/components/prefetch.ts +++ b/packages/qwik/src/core/components/prefetch.ts @@ -72,7 +72,7 @@ export const PrefetchServiceWorker = (opts: { JSON.stringify(resolvedOpts.base), JSON.stringify(resolvedOpts.manifestHash), 'navigator.serviceWorker', - 'window.qwikPrefetchSW||(window.qwikPrefetchSW=[])', + 'window.qwikPreloader||(window.qwikPreloader=[])', resolvedOpts.verbose, ].join(','), ');', @@ -149,7 +149,7 @@ export const PrefetchGraph = ( resolvedOpts.base, `q-bundle-graph-${resolvedOpts.manifestHash}.json`, ]); - const code = `(window.qwikPrefetchSW||(window.qwikPrefetchSW=[])).push(${args})`; + const code = `(window.qwikPreloader||(window.qwikPreloader=[])).push(${args})`; const props = { dangerouslySetInnerHTML: code, nonce: opts.nonce, diff --git a/packages/qwik/src/prefetch-service-worker/process-message.ts b/packages/qwik/src/prefetch-service-worker/process-message.ts index 23b530522a7..93a9145aaab 100644 --- a/packages/qwik/src/prefetch-service-worker/process-message.ts +++ b/packages/qwik/src/prefetch-service-worker/process-message.ts @@ -57,7 +57,7 @@ export type SWMessages = SWMsgBundleGraph | SWMsgBundleGraphUrl | SWMsgPrefetch export const log = (...args: any[]) => { // eslint-disable-next-line no-console - console.log('⚙️ Prefetch SW:', ...args); + console.log('⚙️ Preloader:', ...args); }; export const processMessage = async (state: SWState, msg: SWMessages) => { diff --git a/packages/qwik/src/server/prefetch-utils.ts b/packages/qwik/src/server/prefetch-utils.ts index 868d505dcc3..1f6d85e3f0e 100644 --- a/packages/qwik/src/server/prefetch-utils.ts +++ b/packages/qwik/src/server/prefetch-utils.ts @@ -24,7 +24,7 @@ export function prefetchUrlsEventScript(base: string, prefetchResources: Prefetc bundles: flattenPrefetchResources(prefetchResources).map((u) => u.split('/').pop()!), }; const args = JSON.stringify(['prefetch', base, ...data.bundles!]); - return `(window.qwikPrefetchSW||(window.qwikPrefetchSW=[])).push(${args});`; + return `(window.qwikPreloader||(window.qwikPreloader=[])).push(${args});`; } export function flattenPrefetchResources(prefetchResources: PrefetchResource[]) { diff --git a/scripts/submodule-qwikprefetch.ts b/scripts/submodule-qwikprefetch.ts index 0bc74185d90..0586844c314 100644 --- a/scripts/submodule-qwikprefetch.ts +++ b/scripts/submodule-qwikprefetch.ts @@ -18,15 +18,15 @@ import { writePackageJson } from './package-json'; * provides a utility function. */ export async function submoduleQwikPrefetch(config: BuildConfig) { - const prefetchSwDir = join(config.srcQwikDir, 'prefetch-service-worker'); + const PreloaderDir = join(config.srcQwikDir, 'prefetch-service-worker'); const input: InputOptions = { - input: join(prefetchSwDir, 'entry.ts'), + input: join(PreloaderDir, 'entry.ts'), plugins: [ { name: 'qwikPrefetchTranspile', resolveId(id) { if (!id.endsWith('.ts')) { - return join(prefetchSwDir, id + '.ts'); + return join(PreloaderDir, id + '.ts'); } return null; }, From 0b368e33b9046836806c8d9c257b0597c94aa378 Mon Sep 17 00:00:00 2001 From: Shai Reznik Date: Tue, 3 Dec 2024 01:22:50 +0200 Subject: [PATCH 4/6] add ALL dynamic imports to bundle graph --- packages/qwik/src/optimizer/src/plugins/vite.ts | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/packages/qwik/src/optimizer/src/plugins/vite.ts b/packages/qwik/src/optimizer/src/plugins/vite.ts index 158188f6836..9232f6a4615 100644 --- a/packages/qwik/src/optimizer/src/plugins/vite.ts +++ b/packages/qwik/src/optimizer/src/plugins/vite.ts @@ -1171,18 +1171,16 @@ export function convertManifestToBundleGraph(manifest: QwikManifest): QwikBundle let didAdd = false; for (const depName of bundle.dynamicImports || []) { // If we dynamically import a qrl segment that is not a handler, we'll probably need it soon - const dep = graph[depName]; + // const dep = graph[depName]; if (!graph[depName]) { // external dependency continue; } - if (dep.isTask) { - if (!didAdd) { - deps.add(''); - didAdd = true; - } - deps.add(depName); + if (!didAdd) { + deps.add(''); + didAdd = true; } + deps.add(depName); } map.set(bundleName, { index, deps }); bundleGraph.push(bundleName); From 8b34bba5ad945a6b7b6ec7879b37b4df6dde1231 Mon Sep 17 00:00:00 2001 From: Shai Reznik Date: Mon, 16 Dec 2024 14:30:52 +0200 Subject: [PATCH 5/6] infra: added qwik city buildtime folder to 'watch mode" --- scripts/build.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/build.ts b/scripts/build.ts index 11862ab3b34..0f97273f2fe 100644 --- a/scripts/build.ts +++ b/scripts/build.ts @@ -186,6 +186,7 @@ export async function build(config: BuildConfig) { [join(config.srcQwikDir, 'prefetch-service-worker')]: () => submoduleQwikPrefetch(config), [join(config.srcQwikDir, 'server')]: () => submoduleServer(config), [join(config.srcQwikCityDir, 'runtime/src')]: () => buildQwikCity(config), + [join(config.srcQwikCityDir, 'buildtime')]: () => buildQwikCity(config), }); } } catch (e: any) { From a11810a46a258f34c7e1c53c7ef24108d7e90dea Mon Sep 17 00:00:00 2001 From: Shai Reznik Date: Tue, 24 Dec 2024 02:40:50 +0200 Subject: [PATCH 6/6] fixed dynamic imports unit test --- packages/qwik/src/optimizer/src/plugins/vite.unit.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/qwik/src/optimizer/src/plugins/vite.unit.ts b/packages/qwik/src/optimizer/src/plugins/vite.unit.ts index f9444683d36..4dad670fda8 100644 --- a/packages/qwik/src/optimizer/src/plugins/vite.unit.ts +++ b/packages/qwik/src/optimizer/src/plugins/vite.unit.ts @@ -478,6 +478,15 @@ suite('convertManifestToBundleGraph', () => { }, } as Record, } as QwikManifest; - expect(convertManifestToBundleGraph(manifest)).toEqual(['a.js', 2, 'b.js', 'c.js']); + expect(convertManifestToBundleGraph(manifest)).toEqual([ + 'a.js', + 4, + -1, + 7, + 'b.js', + -1, + 7, + 'c.js', + ]); }); });