fix(dev): add opt-in loopback cache reset for local review#898
Open
akira69 wants to merge 1 commit intoDonkie:masterfrom
Open
fix(dev): add opt-in loopback cache reset for local review#898akira69 wants to merge 1 commit intoDonkie:masterfrom
akira69 wants to merge 1 commit intoDonkie:masterfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds an opt-in way to clear stale frontend service workers and caches on loopback hosts during local review.
Background
Spoolman already supports PWA behavior via
vite-plugin-pwa, introduced in upstream PR #762. That is useful background for why stale local frontend assets can happen, but this PR does not depend on #762 as part of a stack.Problem
Today, you can open the app locally, refresh the page, and still be looking at an older frontend bundle because the browser is serving assets from an existing service worker or cache.
That makes local review and debugging unreliable. You can think you are testing the current branch when the browser is still showing UI from an earlier run.
This PR fixes that by adding an opt-in local-review flag:
VITE_BYPASS_LOOPBACK_PWA_CACHE=true. When that flag is enabled, loopback hosts such aslocalhost, IPv4127.x.x.x, and IPv6::1clear existing service workers and Cache Storage before the app boots. If the flag is not enabled, behavior stays exactly as it is today.Why This Shape
The stale-cache problem is real, but automatically clearing caches for every localhost-style user would be too broad.
This PR keeps the workaround available for development and review while avoiding behavior changes for normal localhost users unless they explicitly opt in.
How To Use It
Build or run the frontend with:
VITE_BYPASS_LOOPBACK_PWA_CACHE=trueWhen that flag is enabled on a loopback host, the app clears service workers and Cache Storage before boot.
Implementation
VITE_BYPASS_LOOPBACK_PWA_CACHEfromimport.meta.envlocalhost,::1, and127.x.x.xaddresses as loopback hostsAlternatives Considered
Do nothing
This leaves local review vulnerable to stale frontend assets.
Document a manual workaround only
This helps contributors, but it does not make the behavior predictable or easy to reproduce consistently.
Always clear caches on localhost-style hosts
This fixes the stale-cache problem, but it changes behavior for all localhost users, not just reviewers and developers.
Disable PWA behavior in dev entirely
This may be a valid future direction, but it is a broader behavioral decision. This PR is narrower and keeps existing dev PWA capability available.
Validation
Commands:
./node_modules/.bin/eslint src/index.tsx./node_modules/.bin/prettier --check src/index.tsx README.MDVITE_APIURL=/api/v1 VITE_BYPASS_LOOPBACK_PWA_CACHE=true npm run buildTest Checklist
VITE_BYPASS_LOOPBACK_PWA_CACHE=trueclient/src/index.tsxclient/src/index.tsxandclient/README.MD