Repository navigation
Description
Current Behavior
When running a SSR dev server and applying code-changes, the dev-server will be killed and respawned after each compilation. However, the related hook seems to become registered again each time a code change is made. This can be observed when adding a console.log to https://github.com/nrwl/nx/blob/master/packages/angular-rspack/src/lib/plugins/angular-ssr-dev-server.ts#L48
compiler.hooks.watchRun.tapAsync(
PLUGIN_NAME,
async (compiler, callback) => {
compiler.hooks.afterEmit.tapAsync(
PLUGIN_NAME,
async (compilation, callback) => {
...
if (this.#devServerProcess) {
this.#devServerProcess.kill();
console.log('devServerProcess killed'); // <-- this becomes logged once more per each re-compile
this.#devServerProcess = undefined;
await new Promise<void>((res) => setTimeout(res, 50)); // <-- this will increase rebuild time the more rebuilds will happen
}
...
callback();
}
);
callback();
}
);
}Killing / spawning the process incrementally will eventually lead to increasing the rebuild time, as per each "re-spawn" process a 50 tick delay will be added.
Following existing approaches applied to e.g. nested hooks in AngularRspackPlugin, a solution to avoid redundant kills/spawns could be
+ let watchRunInitialized = false;
compiler.hooks.watchRun.tapAsync(
PLUGIN_NAME,
async (compiler, callback) => {
+ if (!watchRunInitialized) {
+ watchRunInitialized = true;
compiler.hooks.afterEmit.tapAsync(
PLUGIN_NAME,
async (compilation, callback) => {
...
if (this.#devServerProcess) {
...
}
...
callback();
}
);
+ }
callback();
}
);
}Expected Behavior
Restarting the dev-server shouldn't happen redundantly by negatively affecting rebuild times.
GitHub Repo
No response
Steps to Reproduce
- Add a console.log inside the
afterEmithook inAngularSsrDevServer - Start the SSR dev server and apply code changes multiple times in a row
- Watch the log amount in terminal increasing incrementally
Nx Report
Node : 24.21.0
OS : linux-x64
Native Target : x86_64-linux
npm : 11.19.0
daemon : Available
nx : 23.1.1
@nx/js : 23.1.1
@nx/eslint : 23.1.1
@nx/workspace : 23.1.1
@nx/angular : 23.1.1
@nx/angular-rspack : 24.0.1
@nx/angular-rspack-compiler : 24.0.1
@nx/jest : 23.1.1
@nx/cypress : 23.1.1
@nx/devkit : 23.1.1
@nx/esbuild : 23.1.1
@nx/eslint-plugin : 23.1.1
@nx/module-federation : 23.1.1
@nx/node : 23.1.1
@nx/plugin : 23.1.1
@nx/rspack : 23.1.1
@nx/storybook : 23.1.1
@nx/web : 23.1.1
@nx/webpack : 23.1.1
@nx/docker : 23.1.1
typescript : 6.0.3Failure Logs
Package Manager Version
No response
Operating System
- macOS
- Linux
- Windows
- Other (Please specify)
Additional Information
No response
Activity
fix(angular): register the ssr dev server afterEmit hook only once (#…
fix(angular): register the ssr dev server afterEmit hook only once (#…