Skip to content

Prevent failed dynamic import - #1007

Open
saadabdali wants to merge 2 commits into
devfrom
sa/bugfix-1002
Open

saadabdali wants to merge 2 commits into
devfrom
sa/bugfix-1002

Conversation

@saadabdali

@saadabdali saadabdali commented Aug 13, 2026

Copy link
Copy Markdown
Collaborator

Closes #1002, addressing the recurring PostHog error TypeError: Failed to fetch dynamically imported module.

Dynamic loading is an area where I don't have a ton of expertise, so relied a lot on Claude for assistance figuring out how this works.

Cause, as I understand it:

  • Certain assets get a dynamic hashed route with each deploy.
  • The app loads a listing of those routes, but fetches the actual modules lazily (only when each one is needed).
  • When there's a deploy, the route to each module changes (gets a new hash). If the user doesn't hard-reload, then the next time they need to load an unloaded module, they'll attempt to fetch it from the stale route, causing this error.

Fix: When we hit this preload error, attempt to reload the routes listing.

  • we listen for vite:preloadError
  • if we hit that error, try to fully reload the page (which should fetch the new URL and then allow us to grab the resource from its updated location)
  • track last reload time (to prevent an infinite loop if the resource is actually unloadable)

@saadabdali
saadabdali marked this pull request as ready for review August 13, 2026 23:41
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.

Investigate error: TypeError

2 participants