Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 11 additions & 16 deletions packages/angular/build/src/builders/dev-server/vite-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -501,35 +501,30 @@ async function invalidateUpdatedFiles(
}

// Invalidate any updated files
let destroyAngularServerAppCalled = false;
let serverApplicationChanged = false;
for (const [file, record] of generatedFiles) {
if (!record.updated) {
continue;
}
record.updated = false;

if (record.type === BuildOutputFileType.ServerApplication && !destroyAngularServerAppCalled) {
// Clear the server app cache
// This must be done before module invalidation.
const { ɵdestroyAngularServerApp } = (await server.ssrLoadModule('/main.server.mjs')) as {
ɵdestroyAngularServerApp: typeof destroyAngularServerApp;
};

ɵdestroyAngularServerApp();
destroyAngularServerAppCalled = true;
}

record.updated = false;
updatedFiles.push(file);
serverApplicationChanged ||= record.type === BuildOutputFileType.ServerApplication;

const updatedModules = server.moduleGraph.getModulesByFile(
normalizePath(join(server.config.root, file)),
);
updatedModules?.forEach((m) => server.moduleGraph.invalidateModule(m));
}

if (destroyAngularServerAppCalled) {
// Trigger module evaluation before reload to initiate dependency optimization.
await server.ssrLoadModule('/main.server.mjs');
if (serverApplicationChanged) {
// Clear the server app cache and
// trigger module evaluation before reload to initiate dependency optimization.
const { ɵdestroyAngularServerApp } = (await server.ssrLoadModule('/main.server.mjs')) as {
ɵdestroyAngularServerApp: typeof destroyAngularServerApp;
};

ɵdestroyAngularServerApp();
}

return updatedFiles;
Expand Down
Loading