Skip to content

Angular's global patching in @angular/platform-server causes issues for other code expecting node's native event types #71977

Open

Description

@eblocha

Which @angular/* package(s) are the source of the bug?

platform-server

Is this a regression?

No

Description

Relevant issue: #64175

Since Angular patches globalThis with domino.impl, node's Event and CustomEvent constructors are overwritten with non-intrinsic versions.

This causes issues for libraries like p-queue, which are implemented by extending EventTarget. When p-queue calls this.dispatchEvent(new CustomEvent()), node throws a TypeError

import '@angular/compiler';
import { Component, provideZonelessChangeDetection } from '@angular/core';
import { bootstrapApplication } from '@angular/platform-browser';
import { renderApplication, provideServerRendering } from '@angular/platform-server';
import PQueue from 'p-queue';

class App {
  result = 'pending';

  constructor() {
    // p-queue 10 extends node's `EventTarget` and calls `this.dispatchEvent(new CustomEvent(...))`.
    // Once Angular's server platform has installed domino's globals, `CustomEvent` is domino's
    // implementation, which node's `EventTarget#dispatchEvent` rejects.
    const queue = new PQueue({ concurrency: 1 });
    queue.add(() => 1);
    this.result = 'ok';
  }
}

Component({ selector: 'app-root', template: `<p>{{ result }}</p>` })(App);

const html = await renderApplication(
  (context) =>
    bootstrapApplication(
      App,
      { providers: [provideZonelessChangeDetection(), provideServerRendering()] },
      context,
    ),
  { document: '<html><body><app-root></app-root></body></html>' },
);
console.log(html);

Please provide a link to a minimal reproduction of the bug

https://github.com/eblocha/angular-ssr-globals-clobbering

Please provide the exception or error you saw

TypeError [ERR_INVALID_ARG_TYPE]: The "event" argument must be an instance of Event. Received an instance of CustomEvent

Please provide the environment you discovered this bug in (run ng version)


Anything else?

This is also relevant to #67785 as Astro recently updated to p-queue 10, which is when I noticed this error.

Activity

  1. added this to the needsTriage milestone on Nov 11, 2026
  2. eblocha commented on Nov 11, 2026

    @eblocha
    Author

    Tangential, but SSR may be a good case for shadow realms: https://github.com/tc39/proposal-shadowrealm

  3. SkyZeroZx commented on Nov 12, 2026

    @SkyZeroZx
    Contributor

    I'm unsure about this. I think it's quite unlikely to change that behavior, since Domino is tightly coupled to DOM emulation in Angular SSR as it works today.
    A workaround like using isPlatformBrowser to execute that logic only in the browser is an alternative ( But it's not recommended anymore) , O better way is extracting that logic into a service using DI for the browser and server Providing platform-specific implementations would be a better approach

  4. eblocha commented on Nov 12, 2026

    @eblocha
    Author

    In my case, the code is intended to run on the server, not the browser. The repro is just a minimal example that will trigger it. Specifically, I hit this when Astro runs image optimization after rendering all the pages, but you could imagine an application server that uses p-queue for some task before or after calling renderApplication.

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

    area: serverIssues related to server-side rendering

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions