Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: invalidate new worker and its dependencies (fix #1873) #1896

Merged
merged 4 commits into from Aug 23, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 18 additions & 0 deletions packages/vite-node/src/client.ts
Expand Up @@ -91,6 +91,24 @@ export class ModuleCacheMap extends Map<string, ModuleCache> {
}
return invalidated
}

/**
* Invalidate dependency modules of the given modules, down to the bottom-level dependencies
*/
invalidateSubDepTree(ids: string[] | Set<string>, invalidated = new Set<string>()) {
for (const _id of ids) {
const id = this.normalizePath(_id)
if (invalidated.has(id))
continue
invalidated.add(id)
const subIds = Array.from(super.entries())
.filter(([,mod]) => mod.importers?.has(id))
.map(([key]) => key)
subIds.length && this.invalidateSubDepTree(subIds, invalidated)
super.delete(id)
}
return invalidated
}
}

export class ViteNodeRunner {
Expand Down
10 changes: 5 additions & 5 deletions packages/web-worker/src/pure.ts
Expand Up @@ -133,11 +133,11 @@ export function defineWebWorker() {

runner.executeFile(fsPath)
.then(() => {
invalidates.forEach((fsPath) => {
// worker should be new every time
moduleCache.delete(fsPath)
moduleCache.delete(`mock:${fsPath}`)
})
// worker should be new every time, invalidate its sub dependency
sheremet-va marked this conversation as resolved.
Show resolved Hide resolved
moduleCache.invalidateSubDepTree(
invalidates.reduce(
(acc, fsPath) => acc.concat([fsPath, `mock:${fsPath}`]), [] as string[],
))
const q = this.messageQueue
this.messageQueue = null
if (q)
Expand Down