Skip to content

fix(dev): add opt-in loopback cache reset for local review#15

Open
akira69 wants to merge 35 commits intomasterfrom
wip/local-cache-bypass-split
Open

fix(dev): add opt-in loopback cache reset for local review#15
akira69 wants to merge 35 commits intomasterfrom
wip/local-cache-bypass-split

Conversation

@akira69
Copy link
Copy Markdown
Owner

@akira69 akira69 commented Mar 30, 2026

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 Donkie#762. That is useful background for why stale local frontend assets can happen, but this PR does not depend on Donkie#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 as localhost, IPv4 127.x.x.x, and IPv6 ::1 clear 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=true

When that flag is enabled on a loopback host, the app clears service workers and Cache Storage before boot.

Implementation

  • read VITE_BYPASS_LOOPBACK_PWA_CACHE from import.meta.env
  • normalize the browser hostname before evaluation
  • treat localhost, ::1, and 127.x.x.x addresses as loopback hosts
  • clear service workers and Cache Storage only when both conditions are true:
    • the opt-in flag is enabled
    • the current hostname is a loopback host

Alternatives Considered

  1. Do nothing
    This leaves local review vulnerable to stale frontend assets.

  2. Document a manual workaround only
    This helps contributors, but it does not make the behavior predictable or easy to reproduce consistently.

  3. 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.

  4. 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.MD
  • VITE_APIURL=/api/v1 VITE_BYPASS_LOOPBACK_PWA_CACHE=true npm run build

Test Checklist

  • Loopback cache reset is opt-in via VITE_BYPASS_LOOPBACK_PWA_CACHE=true
  • IPv4 and IPv6 loopback hosts are both covered when the flag is enabled
  • Non-loopback app bootstrap remains unchanged
  • File-scoped ESLint passes for client/src/index.tsx
  • Prettier check passes for client/src/index.tsx and client/README.MD
  • Frontend build passes with the opt-in flag enabled

Added information about improvements and new features for label printing.
Removed outdated project description and features.
git merge --no-ff feat/manufacturer-logo-labels
git push origin master
 enter a commit message to explain why this merge is necessary,
feat: improved labels with manufacturer logo
- Resolve follow-up issues after the logo + spool_count work.
- Fix vendor logo sync edge cases and improve reliability for non-default refs/base paths.
- Add/complete spool_count filtering support and related query behavior.
- Normalize table UX updates: column controls, clear-filter state handling, resizable/auto-fit columns, sticky Actions behavior, and filtering consistency fixes.
- Include targeted UI consistency fixes from review/testing without changing feature scope.
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 44fdbfbc68

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread client/src/index.tsx Outdated
@akira69 akira69 changed the title fix(dev): isolate localhost cache bypass fix(dev): clear stale frontend caches on loopback hosts Mar 30, 2026
@akira69 akira69 changed the title fix(dev): clear stale frontend caches on loopback hosts fix(dev): add opt-in loopback cache reset for local review Mar 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant