Visitar URL original
angular-rspack: AngularSsrDevServer process killed/spawned incrementally per each rebuild · Issue #37587 · nrwl/nx · GitHub
Skip to content

angular-rspack: AngularSsrDevServer process killed/spawned incrementally per each rebuild #37587

Closed

Description

@vz-tl

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 afterEmit hook in AngularSsrDevServer
  • 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.3

Failure Logs

Package Manager Version

No response

Operating System

  • macOS
  • Linux
  • Windows
  • Other (Please specify)

Additional Information

No response

Activity

  1. added theissue type on Oct 25, 2026
  2. added a commit that references this issue on Oct 26, 2026
    71277c1
  3. added a commit that references this issue on Oct 26, 2026
    a40366d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions