Skip to content

Commit

Permalink
refactor: move prunePaths into its own method
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va committed Nov 30, 2023
1 parent 6eeb844 commit 601df1f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
11 changes: 1 addition & 10 deletions packages/vite/src/client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,16 +251,7 @@ async function handleMessage(payload: HMRPayload) {
break
case 'prune':
notifyListeners('vite:beforePrune', payload)
// After an HMR update, some modules are no longer imported on the page
// but they may have left behind side effects that need to be cleaned up
// (.e.g style injections)
// TODO Trigger their dispose callbacks.
payload.paths.forEach((path) => {
const fn = hmrClient.pruneMap.get(path)
if (fn) {
fn(hmrClient.dataMap.get(path))
}
})
hmrClient.prunePaths(payload.paths)
break
case 'error': {
notifyListeners('vite:error', payload)
Expand Down
13 changes: 13 additions & 0 deletions packages/vite/src/shared/hmr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,19 @@ export class HMRClient {
}
}

// After an HMR update, some modules are no longer imported on the page
// but they may have left behind side effects that need to be cleaned up
// (.e.g style injections)
// TODO Trigger their dispose callbacks.
public prunePaths(paths: string[]): void {
paths.forEach((path) => {
const fn = this.pruneMap.get(path)
if (fn) {
fn(this.dataMap.get(path))
}
})
}

protected warnFailedUpdate(err: Error, path: string | string[]): void {
if (!err.message.match('fetch')) {
this.logger.error(err)
Expand Down

0 comments on commit 601df1f

Please sign in to comment.