ソースを参照

fix(frontend): resolve lazy chunk URLs against runtime base path (#4505)

* fix(frontend): reload page on Vite chunk preload error after upgrade

After a panel upgrade the embedded dist/ ships with new hashed chunk
filenames, so SPA tabs loaded before the upgrade hold references to
chunks that no longer exist on the server and lazy modals 404. Hook
`vite:preloadError` and force one full reload (guarded by a session
flag) so the browser picks up the new index.html.

* Revert "fix(frontend): reload page on Vite chunk preload error after upgrade"

This reverts commit bf0754d21e44e8645930b87728e5355248c3c081.

* fix(frontend): resolve lazy chunk URLs against runtime base path

Vite's default chunk-preload helper prepends a hardcoded `/` to asset
filenames, so dynamic chunk preloads always 404 when the panel is
served under a non-root webBasePath (e.g. /CxuVUNgm5mRLmjPhp3/). Use
experimental.renderBuiltUrl to embed window.X_UI_BASE_PATH (injected
by dist.go) as the runtime prefix, so __vite__mapDeps emits URLs like
`<basePath>assets/<file>` regardless of where the dist is mounted.
Sanaei 23 時間 前
コミット
c6123f9628
1 ファイル変更10 行追加0 行削除
  1. 10 0
      frontend/vite.config.js

+ 10 - 0
frontend/vite.config.js

@@ -152,6 +152,16 @@ export default defineConfig({
       '@': path.resolve(__dirname, 'src'),
     },
   },
+  experimental: {
+    renderBuiltUrl(filename, { hostType }) {
+      if (hostType === 'js') {
+        return {
+          runtime: `((window.X_UI_BASE_PATH||'/')+${JSON.stringify(filename)})`,
+        };
+      }
+      return undefined;
+    },
+  },
   build: {
     outDir,
     emptyOutDir: true,