Skip to content

Commit

Permalink
chore: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va committed Jan 10, 2024
1 parent c209f01 commit f0df3e1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 23 deletions.
30 changes: 27 additions & 3 deletions packages/vite/src/node/server/hmr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,7 @@ export function updateModules(
? isExplicitImportRequired(acceptedVia.url)
: false,
isWithinCircularImport,
ssrInvalidates: [
...moduleGraph.getSSRInvalidatedImporters(acceptedVia),
].map((m) => m.file!),
ssrInvalidates: getSSRInvalidatedImporters(acceptedVia),
}),
),
)
Expand Down Expand Up @@ -227,6 +225,32 @@ export function updateModules(
})
}

function populateSSRImporters(
module: ModuleNode,
timestamp: number,
seen: Set<ModuleNode>,
) {
module.ssrImportedModules.forEach((importer) => {
if (seen.has(importer)) {
return
}
if (
importer.lastHMRTimestamp === timestamp ||
importer.lastInvalidationTimestamp === timestamp
) {
seen.add(importer)
populateSSRImporters(importer, timestamp, seen)
}
})
return seen
}

function getSSRInvalidatedImporters(module: ModuleNode) {
return [
...populateSSRImporters(module, module.lastHMRTimestamp, new Set()),
].map((m) => m.file!)
}

export async function handleFileAddUnlink(
file: string,
server: ViteDevServer,
Expand Down
20 changes: 0 additions & 20 deletions packages/vite/src/node/server/moduleGraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,26 +216,6 @@ export class ModuleGraph {
})
}

getSSRInvalidatedImporters(
mod: ModuleNode,
timestamp = mod.lastHMRTimestamp,
seen: Set<ModuleNode> = new Set(),
): Set<ModuleNode> {
mod.ssrImportedModules.forEach((importer) => {
if (seen.has(importer)) {
return
}
if (
importer.lastHMRTimestamp === timestamp ||
importer.lastInvalidationTimestamp === timestamp
) {
seen.add(importer)
return this.getSSRInvalidatedImporters(importer, timestamp, seen)
}
})
return seen
}

invalidateAll(): void {
const timestamp = Date.now()
const seen = new Set<ModuleNode>()
Expand Down

0 comments on commit f0df3e1

Please sign in to comment.