mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #3370] [Issue]: Stale-chunk dynamic-import failures ('Failed to fetch dynamically imported module') aren't auto-recovered #1822
Labels
No labels
android
bug
bugfix
ci
client
code freeze pause
container
dependencies
docs
documentation
duplicate
enhancement
feature
feature
feature
feature-creep
fixed-in-refactor
fixed-in-staging
good first issue
help wanted
in-pr
in-pr
needs-codeowner-decision
normal-scope
old-codebase
old-codebase
pull-request
qol
question
refactor
regression
revisit later
roadmap
scope-risk
scope-risk
server
server
shared
soup
upstream
windows
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Pasta-Devs/Marinara-Engine#1822
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @kolacheee on GitHub (Jul 8, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/3370
Originally assigned to: @SpicyMarinara, @kolacheee on GitHub.
Summary
When a lazy-loaded route/chunk fails to load — e.g. after an update the running page references a hashed chunk (
CharacterEditor-<hash>.js) that the new build deleted, or a stale service-worker precache serves an old one — the app shows "Failed to fetch dynamically imported module: …/assets/CharacterEditor-.js" and stays broken. There is no automatic recovery for this specific failure, so users hit it repeatedly across updates until they manually clear the service worker / site data.Expected behavior
A failed dynamic import (stale/missing chunk) should trigger a one-time automatic recovery — clear the service worker + caches and reload so the browser fetches the current build — instead of surfacing the error. (The app already does exactly this for version skew via
recoverFromVersionSkew→forceRefreshSpa.)Actual behavior
The app registers no
vite:preloadErrorhandler, so a failedimport()is not recovered — it surfaces to the user as "Failed to fetch dynamically imported module." The existingrecoverFromVersionSkewonly fires on a health-check client/server version mismatch, which does not cover a bare chunk-load failure: the client and server can report the same version yet the page still references a stale/missing chunk from a sticky SW precache.Steps to reproduce
clean:stale-client.Environment
start.bat)Logs, screenshots, or video
Additional context
Root cause: the PWA precaches JS chunks (
packages/client/vite.config.ts—globPatterns: ["**/*.{js,css,png,svg,ico,woff2}"],registerType: "autoUpdate") and lazy routes are code-split (CharacterEditor = lazy(() => import(...))inAppShell). After an update, a running page or a stale SW can reference a chunk hash the new build deleted → theimport()404s. Vite fires avite:preloadErrorwindow event for exactly this, but the app has no listener (grep -r "vite:preloadError" packages/client/src→ none). The recovery primitive already exists:forceRefreshSpa(packages/client/src/lib/browser-runtime.ts) unregisters the service worker, clears all caches, and reloads with a cache-busting query param.Suggested fix: register a
vite:preloadErrorlistener that callsforceRefreshSpa, guarded by a short cooldown (a sessionStorage timestamp) so a genuinely broken build — or a page that re-triggers the same import immediately after reload — can't reload-loop: after one attempt within the window, let Vite rethrow so the app's error boundary Reload button shows.Template check