Skip to content

@ngrx/component does not work in SSR + zoneless #4902

@JelleBruisten

Description

@JelleBruisten

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

component

Minimal reproduction of the bug/regression with instructions

When using ngrxLet in a angular app with both SSR and zoneless, you're faced with an error:

uncaughtException ReferenceError: requestAnimationFrame is not defined.

I made a quick example:
https://github.com/JelleBruisten/ngrxlet-zoneless-ssr

It looks like due that when zoneless we use the AnimationFrameTickScheduler

@Injectable({
  providedIn: 'root',
  useFactory: () => {
    const zone = inject(NgZone);
    return isNgZone(zone)
      ? new NoopTickScheduler()
      : inject(AnimationFrameTickScheduler);
  },
})
export abstract class TickScheduler {
  abstract schedule(): void;
}

And within AnimationFrameTickScheduler we use this, but requestAnimationFrame does not exist in node during the server render:

  schedule(): void {
    if (!this.isScheduled) {
      this.isScheduled = true;
      requestAnimationFrame(() => {
        this.appRef.tick();
        this.isScheduled = false;
      });
    }
  }

We're throwing an error

Expected behavior

To schedule using a different mechanism maybe setTimeout while on server?

Versions of NgRx, Angular, Node, affected browser(s) and operating system(s)

ngrx: 19.2.1 ( did try it with latest 20.0.0-rc... )
angular: v20

Other information

No response

I would be willing to submit a PR to fix this issue

  • Yes
  • No

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions