Skip to content

OrderNot attempted

Recovering from a missing chunk

An old tab hits a chunk that a deploy removed, and the app has a guarded vite:preloadError handler. Order the steps.

Drag the rows, or use the arrows, to put them in order from first to last.

  1. The new entry code imports the chunk under its new name and the route renders
  2. The page reloads and the browser revalidates the HTML, getting the new version
  3. The handler finds no recent reload timestamp in sessionStorage, stores one and calls event.preventDefault()
  4. The import rejects and Vite dispatches vite:preloadError on window
  5. The old entry code imports the chunk by its old hashed name and gets a 404
  6. The user clicks a link to a route they haven't opened yet
Show answer & explanation

Correct order:

  1. The user clicks a link to a route they haven't opened yet
  2. The old entry code imports the chunk by its old hashed name and gets a 404
  3. The import rejects and Vite dispatches vite:preloadError on window
  4. The handler finds no recent reload timestamp in sessionStorage, stores one and calls event.preventDefault()
  5. The page reloads and the browser revalidates the HTML, getting the new version
  6. The new entry code imports the chunk under its new name and the route renders

A reload is the real fix because only the new HTML knows the new file names. preventDefault() stops the error from being thrown while the reload happens, and the stored timestamp stops a second reload if the new build fails the same way.