Skip to content

Events are replayed on already destroyed components #59841

Closed

Description

@jsaguet

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

core

Is this a regression?

No

Description

In an SSR Angular app with withEventReplay() enabled and a lot of elements to hydrate, components can be interacted with before hydration ends.

In that case, if a component is destroyed by a click happening on it (because it triggers a router navigation for example) before hydration completes, the click event on that element will be replayed even though the element is already destroyed.

This behavior makes the app throw errors like NG0953 if the click listener emits to an output for example.

Please provide a link to a minimal reproduction of the bug

https://github.com/jsaguet/ng0953-ssr

Please provide the exception or error you saw

NG0953: Unexpected emit for destroyed `OutputRef`. The owning directive/component is destroyed.

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

Angular CLI: 19.1.5
Node: 22.13.0
Package Manager: npm 10.9.2
OS: win32 x64

Angular: 19.1.4
... animations, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, platform-server
... router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1901.5
@angular-devkit/build-angular   19.1.5
@angular-devkit/core            19.1.5
@angular-devkit/schematics      19.1.5
@angular/cli                    19.1.5
@angular/ssr                    19.1.5
@schematics/angular             19.1.5
rxjs                            7.8.1
typescript                      5.6.3
zone.js                         0.15.0

Anything else?

In the repro app, you need to click on the square to make it disappear, the error NG0953 should happen at the end of the artificial 2s delay, when hydration ends.

Activity

  1. added
    area: core
    on Feb 3, 2025
  2. modified the milestone: needsTriage on Feb 3, 2025
  3. added a commit that references this issue on Feb 25, 2025
    85a37a7
  4. added a commit that references this issue on Feb 27, 2025
    330c24a
  5. added a commit that references this issue on Feb 27, 2025
    0dbf693
  6. modified the milestones: needsTriage, on Feb 27, 2025
  7. angular-automatic-lock-bot commented on Mar 30, 2025

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  8. locked and limited conversation to collaborators on Mar 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

area: corecore: event dispatchstate: has PR

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions