Skip to content

Commit

Permalink
docs: add about vite:preloadError (#15222)
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red authored Dec 2, 2023
1 parent 1df1fd1 commit 019c6b2
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions docs/guide/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,18 @@ This strategy is also provided as a `splitVendorChunk({ cache: SplitVendorChunkC
You should use `build.rollupOptions.output.manualChunks` function form when using this plugin. If the object form is used, the plugin won't have any effect.
:::

## Load Error Handling

Vite emits `vite:preloadError` event when it fails to load dynamic imports. `event.payload` contains the original import error. If you call `event.preventDefault()`, the error will not be thrown.

```js
window.addEventListener('vite:preloadError', (event) => {
window.reload() // for example, refresh the page
})
```

When a new deployment occurs, the hosting service may delete the assets from previous deployments. As a result, a user who visited your site before the new deployment might encounter an import error. This error happens because the assets running on that user's device are outdated and it tries to import the corresponding old chunk, which is deleted. This event is useful for addressing this situation.

## Rebuild on files changes

You can enable rollup watcher with `vite build --watch`. Or, you can directly adjust the underlying [`WatcherOptions`](https://rollupjs.org/configuration-options/#watch) via `build.watch`:
Expand Down

0 comments on commit 019c6b2

Please sign in to comment.