Skip to content

Commit 7277738

Browse files
bartlomiejuclaude
andcommitted
fix: address review feedback
- Normalize registered pathnames when comparing (strip leading /) to prevent double-registration of files with inconsistent path formats - Remove brittle workbox assertion from build test - Remove permanently-ignored dev server test (dead code) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent e716def commit 7277738

3 files changed

Lines changed: 8 additions & 43 deletions

File tree

packages/plugin-vite/src/plugins/server_snapshot.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -319,13 +319,16 @@ export function serverSnapshot(options: ResolvedFreshViteConfig): Plugin[] {
319319
}
320320
}
321321

322-
// Scan client output directory for any additional files generated by Vite plugins
323-
// (e.g., vite-plugin-pwa generates sw.js, manifest.webmanifest, etc.)
324-
// that weren't captured in the Vite manifest or public directory
322+
// Scan client output directory for any additional files generated
323+
// by Vite plugins (e.g., vite-plugin-pwa generates sw.js,
324+
// manifest.webmanifest) that aren't in the Vite manifest or
325+
// public directory.
325326
if (await fsAdapter.isDirectory(clientOutDir)) {
326-
// Create a Set of already-registered pathnames for fast lookup
327+
// Normalize registered pathnames (strip leading /) for comparison
327328
const registeredPaths = new Set(
328-
staticFiles.map((f) => f.pathname),
329+
staticFiles.map((f) =>
330+
f.pathname.startsWith("/") ? f.pathname.slice(1) : f.pathname
331+
),
329332
);
330333

331334
const clientFiles = await fsAdapter.walk(

packages/plugin-vite/tests/build_test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,6 @@ Deno.test({
707707

708708
const swContent = await swRes.text();
709709
expect(swContent.length).toBeGreaterThan(0);
710-
expect(swContent).toContain("workbox"); // Service worker should contain workbox code
711710

712711
// Test that manifest is accessible
713712
const manifestRes = await fetch(`${address}/manifest.webmanifest`);

packages/plugin-vite/tests/dev_server_test.ts

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -608,40 +608,3 @@ Deno.test({
608608
sanitizeOps: false,
609609
sanitizeResources: false,
610610
});
611-
612-
Deno.test({
613-
name: "vite dev - vite-plugin-pwa files are accessible",
614-
// Ignored: Known limitation - Vite plugin-generated files (like service workers)
615-
// are not accessible in dev mode due to middleware ordering. Fresh's middleware
616-
// runs before Vite plugin middlewares, blocking requests before plugins can serve them.
617-
// This is a dev-only issue; production builds work correctly.
618-
// Fixing this would require architectural changes to Fresh's dev server middleware.
619-
ignore: true,
620-
fn: async () => {
621-
const fixture = path.join(FIXTURE_DIR, "vite_plugin_pwa");
622-
await withDevServer(fixture, async (address) => {
623-
// Test that service worker is accessible
624-
const swRes = await fetch(`${address}/sw.js`);
625-
expect(swRes.status).toEqual(200);
626-
expect(swRes.headers.get("content-type")).toMatch(/javascript/);
627-
628-
const swContent = await swRes.text();
629-
expect(swContent.length).toBeGreaterThan(0);
630-
631-
// Test that manifest is accessible
632-
const manifestRes = await fetch(`${address}/manifest.webmanifest`);
633-
expect(manifestRes.status).toEqual(200);
634-
expect(manifestRes.headers.get("content-type")).toMatch(/json/);
635-
636-
const manifestContent = await manifestRes.json();
637-
expect(manifestContent.name).toEqual("Fresh PWA Test");
638-
639-
// Test that registerSW.js is accessible
640-
const registerRes = await fetch(`${address}/registerSW.js`);
641-
expect(registerRes.status).toEqual(200);
642-
expect(registerRes.headers.get("content-type")).toMatch(/javascript/);
643-
});
644-
},
645-
sanitizeOps: false,
646-
sanitizeResources: false,
647-
});

0 commit comments

Comments
 (0)