Skip to content

fix: recover from stale UI bundle after upgrade instead of showing 50X - #1619

Open
rstrzelecki-inne-projekty wants to merge 1 commit into
apache:mainfrom
rstrzelecki-inne-projekty:fix/stale-chunk-reload
Open

rstrzelecki-inne-projekty wants to merge 1 commit into
apache:mainfrom
rstrzelecki-inne-projekty:fix/stale-chunk-reload

Conversation

@rstrzelecki-inne-projekty

Copy link
Copy Markdown

Proposed Changes

Problem. After an upgrade, every browser tab that was opened before it still runs the previous UI bundle. When the user navigates to a route whose page chunk has not been loaded yet, the bundle requests the old hashed file (e.g. /static/js/6487.02e56745.chunk.js), which no longer exists. gin's StaticFS falls through to NoRoute, which answers with index.html and HTTP 200, so the browser tries to parse HTML as JavaScript, the lazy import() rejects and the route errorElement renders the "HTTP 50X" error page. The API is fine the whole time; only a hard refresh fixes the tab, which is confusing for users right after every deploy.

Changes.

  • internal/router/ui.go: a request for a missing file under /static/ (honouring baseURLPath) now answers 404 instead of index.html — in both the embedded-build handler and the ANSWER_STATIC_PATH handler. Unit test added (ui_test.go).
  • ui/src/router/index.tsx: when the lazy page import fails, the tab reloads once (a sessionStorage flag prevents a loop; it is cleared after the next successful import), so the new index.html and chunks are picked up automatically instead of showing the 50X page.

How to reproduce: open the site, deploy a new build (chunk hashes change), then navigate in the old tab to a page you have not visited yet → "HTTP 50X". With this change the tab reloads itself and shows the page.

Tested on a production instance (2.0.2 + this patch): simulated by rewriting a chunk URL to a non-existent hash — the tab reloaded once and rendered the page; SPA routes (/questions, /users/...) still get index.html, existing assets still return 200.

Checklist

  • Go code builds and go test ./internal/router/ passes
  • pnpm lint / tsc --noEmit clean for the UI change

🤖 Generated with Claude Code

https://claude.ai/code/session_0181uZ2px83HmPo3HKSEzWQR

After an upgrade a tab that still runs the previous bundle requests
hashed chunks that no longer exist. The router fell through to NoRoute
and answered with index.html (200), so the browser tried to parse HTML as
JavaScript, the lazy import failed and the route errorElement rendered
the "HTTP 50X" page until the user hard-refreshed.

- server: a missing file under /static answers 404 instead of index.html
  (both the embedded build and ANSWER_STATIC_PATH handlers)
- ui: when a lazy page import fails, reload the tab once (guarded by a
  sessionStorage flag that is cleared after the next successful import)
  so the new index.html and chunks are picked up automatically

🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_0181uZ2px83HmPo3HKSEzWQR

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0181uZ2px83HmPo3HKSEzWQR
rstrzelecki-inne-projekty pushed a commit to rstrzelecki-inne-projekty/answer that referenced this pull request Sep 15, 2026
…me as upstream PR apache#1619)

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0181uZ2px83HmPo3HKSEzWQR
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.

2 participants