fix(ui): bypass service worker for Vite development modules

Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
DottaandPaperclip committed 2026-09-23 05:55:35 -07:00
1 parent 766369c68f
commit e211fd3beb
2 files changed
+20

No files matched your search

+9
View File
@@ -50,6 +50,15 @@ self.addEventListener("fetch", (event) => {
return;
}
// Vite development modules use the browser's conditional-response cache.
// Passing their requests through fetch/respondWith can return a bodyless 304
// to the module loader on reload and leave the app root empty. They are not
// build assets and have no offline contract, so leave them to the browser.
if (url.origin === self.location.origin &&
/^\/(?:@fs|@vite|@id|src|node_modules)\//.test(url.pathname)) {
return;
}
// Network-first; only public build assets can use an offline fallback.
event.respondWith(
fetch(request)
@@ -22,6 +22,17 @@ function worker() {
}
describe("service worker privacy boundaries", () => {
it.each([
"/@fs/tmp/runner/vite-cache/deps/@assistant-ui_react.js?v=fixture",
"/@vite/client", "/@id/__x00__virtual:module", "/src/main.tsx", "/node_modules/.vite/deps/react.js",
])("leaves conditional Vite module request %s to the browser", pathname => {
const w = worker();
w.fetch.mockResolvedValue(new Response(null, { status: 304 }));
expect(w.request("default", pathname)).not.toHaveBeenCalled();
expect(w.fetch).not.toHaveBeenCalled();
expect(w.put).not.toHaveBeenCalled();
expect(w.match).not.toHaveBeenCalled();
});
it("bypasses both caching and offline fallback for a no-store request outside /api", () => {
const w = worker();
expect(w.request("no-store")).not.toHaveBeenCalled();