[PR #6679] [MERGED] fix: recover panel navigation after stale chunk failures #6406

Closed
opened 2026-11-02 04:08:32 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/6679
Author: @mvanhorn
Created: 9/29/2026
Status: ✅ Merged
Merged: 10/2/2026
Merged by: @MHSanaei

Base: main ← Head: fix/6673-panel-stale-chunk-recovery


📝 Commits (1)

  • 8c0d09b fix: recover panel navigation after stale chunk failures

📊 Changes

2 files changed (+310 additions, -0 deletions)

View changed files

📝 frontend/src/main.tsx (+26 -0)
➕ frontend/src/test/chunk-recovery.test.tsx (+284 -0)

📄 Description

Summary

Add a vite:preloadError listener directly in frontend/src/main.tsx, registered before the router is rendered, to reload the current URL once when a lazy chunk fails; preserve the custom panel base path, pathname, query, and fragment by using location.reload(). Before reloading, persist a sessionStorage guard scoped to the panel base path and the current entry bundle URL (import.meta.url), and also mark the attempt in memory so concurrent chunk failures cannot schedule repeated reloads. Do not clear the persisted marker on bootstrap: a repeat failure from the same bundle must propagate normally, and inaccessible storage must fail safely without automatic reload; prevent the event's default behavior only when committing to the guarded reload.

After upgrading to 3.8.5, the reporter sees React Router's default error screen when visiting Inbounds, Hosts, Outbound, and Routing because dynamically imported JavaScript chunks cannot be fetched. The automated analysis identifies stale entry code referencing removed hashed chunks, and a human contributor reports that the remote panel loads normally for them. Local frontend/src/routes.tsx confirms these pages use lazy imports and Outbound/Routing share XrayPage; internal/web/controller/dist.go already serves HTML with no-store headers, while the service worker does not cache requests. Stale-tab recovery is a concrete local improvement, but the reporter has not confirmed that a refresh resolves their particular failure, so reproduce the upgrade scenario before claiming a complete fix.

Closes #6673

Why

Add a vite:preloadError listener directly in frontend/src/main.tsx, registered before the router is rendered, to reload the current URL once when a lazy chunk fails; preserve the custom panel base path, pathname, query, and fragment by using location.reload(). Before reloading, persist a sessionStorage guard scoped to the panel base path and the current entry bundle URL (import.meta.url), and also mark the attempt in memory so concurrent chunk failures cannot schedule repeated reloads. Do not clear the persisted marker on bootstrap: a repeat failure from the same bundle must propagate normally, and inaccessible storage must fail safely without automatic reload; prevent the event's default behavior only when committing to the guarded reload.

Type of change

  • Bug fix
  • New feature
  • Refactoring (no behavior change)
  • Documentation
  • Tests only
  • Build / CI / tooling
  • Other

Areas affected

  • Frontend (UI / panel pages)
  • Backend (API endpoints, login, settings)
  • Xray config generation
  • Subscription (share links / Clash / JSON)
  • Statistics / traffic counters
  • Database / migrations
  • Install / upgrade script
  • Docker image
  • Multi-node (sub-nodes)
  • Telegram bot

How was this tested?

A cancelable vite:preloadError event causes one reload and persists its guard before reloading; repeated events in the same document cause no additional reload.
Re-import/bootstrap with the same entry identity and retained sessionStorage does not reload again on a persistent failure and leaves the error unsuppressed.
Another panel base path has its own guard, and a later entry bundle has a fresh recovery allowance; guard identity uses the actual production entry URL, not a development-only path.
Throwing storage reads or writes leave the normal error path intact and do not crash bootstrap or create a reload loop. Ordinary runtime errors and successful navigation do not trigger recovery.
In a real browser, open build A without visiting Inbounds/Hosts/Xray, replace the running server with build B whose lazy chunks changed, then navigate. Confirm the old chunk fails, the document reloads once, and the requested route succeeds under a non-root base path. Repeat with a persistently unavailable chunk and verify recovery stops once each encountered entry bundle has spent its allowance.
Write the focused Vitest regression first under the existing components/jsdom project; verify reload with a controlled browser global, not a new production injection interface. Run the focused test, then frontend typecheck, lint, format:check, test, build, and build-storybook; follow the repository's make verify gate before submission and restart the Go server after rebuilding embedded HTML. Do not commit generated build output.

Screenshots / recordings

No user-visible surface changes in this PR, so there is nothing to show.

Breaking changes

Covered in the summary above.

Checklist

  • I tested the change locally and confirmed the described behavior.
  • I added or updated tests for the new behavior (when applicable).
  • go build ./... and the test suite pass locally.
    Not run: no test command resolved in this workspace, so nothing was executed to pass.
  • For frontend changes: npm run lint, npm run typecheck, and npm run build pass.
    Not run: no test command resolved in this workspace, so nothing was executed to pass.
  • I updated the Wiki / README / API docs if user-facing behavior changed.
  • My commits follow the project's existing message style.
  • I have no unrelated changes mixed into this PR.

AI disclosure

AI was used for assistance.

  • Tools: an AI coding assistant.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/MHSanaei/3x-ui/pull/6679 **Author:** [@mvanhorn](https://github.com/mvanhorn) **Created:** 9/29/2026 **Status:** ✅ Merged **Merged:** 10/2/2026 **Merged by:** [@MHSanaei](https://github.com/MHSanaei) **Base:** `main` ← **Head:** `fix/6673-panel-stale-chunk-recovery` --- ### 📝 Commits (1) - [`8c0d09b`](https://github.com/MHSanaei/3x-ui/commit/8c0d09be535fe9a1a6d0697152a1e7bd9abad545) fix: recover panel navigation after stale chunk failures ### 📊 Changes **2 files changed** (+310 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `frontend/src/main.tsx` (+26 -0) ➕ `frontend/src/test/chunk-recovery.test.tsx` (+284 -0) </details> ### 📄 Description ## Summary Add a `vite:preloadError` listener directly in `frontend/src/main.tsx`, registered before the router is rendered, to reload the current URL once when a lazy chunk fails; preserve the custom panel base path, pathname, query, and fragment by using `location.reload()`. Before reloading, persist a sessionStorage guard scoped to the panel base path and the current entry bundle URL (`import.meta.url`), and also mark the attempt in memory so concurrent chunk failures cannot schedule repeated reloads. Do not clear the persisted marker on bootstrap: a repeat failure from the same bundle must propagate normally, and inaccessible storage must fail safely without automatic reload; prevent the event's default behavior only when committing to the guarded reload. After upgrading to 3.8.5, the reporter sees React Router's default error screen when visiting Inbounds, Hosts, Outbound, and Routing because dynamically imported JavaScript chunks cannot be fetched. The automated analysis identifies stale entry code referencing removed hashed chunks, and a human contributor reports that the remote panel loads normally for them. Local `frontend/src/routes.tsx` confirms these pages use lazy imports and Outbound/Routing share XrayPage; `internal/web/controller/dist.go` already serves HTML with no-store headers, while the service worker does not cache requests. Stale-tab recovery is a concrete local improvement, but the reporter has not confirmed that a refresh resolves their particular failure, so reproduce the upgrade scenario before claiming a complete fix. Closes #6673 ## Why Add a `vite:preloadError` listener directly in `frontend/src/main.tsx`, registered before the router is rendered, to reload the current URL once when a lazy chunk fails; preserve the custom panel base path, pathname, query, and fragment by using `location.reload()`. Before reloading, persist a sessionStorage guard scoped to the panel base path and the current entry bundle URL (`import.meta.url`), and also mark the attempt in memory so concurrent chunk failures cannot schedule repeated reloads. Do not clear the persisted marker on bootstrap: a repeat failure from the same bundle must propagate normally, and inaccessible storage must fail safely without automatic reload; prevent the event's default behavior only when committing to the guarded reload. ## Type of change - [x] Bug fix - [ ] New feature - [ ] Refactoring (no behavior change) - [ ] Documentation - [ ] Tests only - [ ] Build / CI / tooling - [ ] Other ## Areas affected - [ ] Frontend (UI / panel pages) - [ ] Backend (API endpoints, login, settings) - [ ] Xray config generation - [ ] Subscription (share links / Clash / JSON) - [ ] Statistics / traffic counters - [ ] Database / migrations - [ ] Install / upgrade script - [ ] Docker image - [ ] Multi-node (sub-nodes) - [ ] Telegram bot ## How was this tested? A cancelable `vite:preloadError` event causes one reload and persists its guard before reloading; repeated events in the same document cause no additional reload. Re-import/bootstrap with the same entry identity and retained sessionStorage does not reload again on a persistent failure and leaves the error unsuppressed. Another panel base path has its own guard, and a later entry bundle has a fresh recovery allowance; guard identity uses the actual production entry URL, not a development-only path. Throwing storage reads or writes leave the normal error path intact and do not crash bootstrap or create a reload loop. Ordinary runtime errors and successful navigation do not trigger recovery. In a real browser, open build A without visiting Inbounds/Hosts/Xray, replace the running server with build B whose lazy chunks changed, then navigate. Confirm the old chunk fails, the document reloads once, and the requested route succeeds under a non-root base path. Repeat with a persistently unavailable chunk and verify recovery stops once each encountered entry bundle has spent its allowance. Write the focused Vitest regression first under the existing components/jsdom project; verify reload with a controlled browser global, not a new production injection interface. Run the focused test, then frontend typecheck, lint, format:check, test, build, and build-storybook; follow the repository's `make verify` gate before submission and restart the Go server after rebuilding embedded HTML. Do not commit generated build output. ## Screenshots / recordings No user-visible surface changes in this PR, so there is nothing to show. ## Breaking changes Covered in the summary above. ## Checklist - [x] I tested the change locally and confirmed the described behavior. - [x] I added or updated tests for the new behavior (when applicable). - [ ] `go build ./...` and the test suite pass locally. Not run: no test command resolved in this workspace, so nothing was executed to pass. - [ ] For frontend changes: `npm run lint`, `npm run typecheck`, and `npm run build` pass. Not run: no test command resolved in this workspace, so nothing was executed to pass. - [x] I updated the Wiki / README / API docs if user-facing behavior changed. - [x] My commits follow the project's existing message style. - [ ] I have no unrelated changes mixed into this PR. **AI disclosure** AI was used for assistance. - Tools: an AI coding assistant. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 04:08:32 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
MHSanaei/3x-ui#6406
No description provided.