Skip to content

Commit

Permalink
fix: improve new SW logic (#6641)
Browse files Browse the repository at this point in the history
  • Loading branch information
gioboa authored Jul 8, 2024
1 parent 35be2b2 commit 9cfb612
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
7 changes: 6 additions & 1 deletion packages/qwik/src/optimizer/src/plugins/vite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -570,9 +570,14 @@ export function qwikVite(qwikViteOpts: QwikVitePluginOptions = {}): any {
const fs: typeof import('fs') = await sys.dynamicImport('node:fs');
const workerScriptPath = (await this.resolve('@builder.io/qwik/qwik-prefetch.js'))!.id;
const workerScript = await fs.promises.readFile(workerScriptPath, 'utf-8');
const assetsDir = qwikPlugin.getOptions().assetsDir || '';
const useAssetsDir = !!assetsDir && assetsDir !== '_astro';
const qwikPrefetchServiceWorkerFile = 'qwik-prefetch-service-worker.js';
this.emitFile({
type: 'asset',
fileName: `qwik-prefetch-service-worker.js`,
fileName: useAssetsDir
? sys.path.join(filePath, qwikPrefetchServiceWorkerFile)
: qwikPrefetchServiceWorkerFile,
source: workerScript,
});

Expand Down
2 changes: 1 addition & 1 deletion packages/qwik/src/prefetch-service-worker/direct-fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export async function enqueueFileAndDependencies(
filenames.forEach((filename) => addDependencies(base.$graph$, fetchSet, filename));
await Promise.all(
Array.from(fetchSet).map((filename) =>
enqueueFetchIfNeeded(swState, new URL(base.$path$ + filename, swState.$url$), priority)
enqueueFetchIfNeeded(swState, new URL(base.$path$ + filename, swState.$url$.origin), priority)
)
);
taskTick(swState);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ async function processBundleGraph(
async function processBundleGraphUrl(swState: SWState, base: string, graphPath: string) {
// Call `processBundleGraph` with an empty graph so that a cache location will be allocated.
await processBundleGraph(swState, base, [], false);
const response = (await directFetch(swState, new URL(base + graphPath, swState.$url$)))!;
const response = (await directFetch(swState, new URL(base + graphPath, swState.$url$.origin)))!;
if (response && response.status === 200) {
const graph = (await response.json()) as SWGraph;
graph.push(graphPath);
Expand Down

0 comments on commit 9cfb612

Please sign in to comment.