Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Rename "Prefetch SW" to "Preloader" #7178

Draft
wants to merge 7 commits into
base: pr-fix-buffering
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<PrefetchServiceWorker />` and `<PrefetchGraph />` 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.

4 changes: 2 additions & 2 deletions packages/qwik/src/core/components/prefetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(','),
');',
Expand Down Expand Up @@ -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,
Expand Down
12 changes: 5 additions & 7 deletions packages/qwik/src/optimizer/src/plugins/vite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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('<dynamic>');
didAdd = true;
}
deps.add(depName);
if (!didAdd) {
deps.add('<dynamic>');
didAdd = true;
}
deps.add(depName);
}
map.set(bundleName, { index, deps });
bundleGraph.push(bundleName);
Expand Down
11 changes: 10 additions & 1 deletion packages/qwik/src/optimizer/src/plugins/vite.unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,15 @@ suite('convertManifestToBundleGraph', () => {
},
} as Record<string, QwikBundle>,
} 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',
]);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/qwik/src/server/prefetch-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[]) {
Expand Down
1 change: 1 addition & 0 deletions scripts/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions scripts/submodule-qwikprefetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
},
Expand Down
Loading