Skip to content

feature: throw an error in case of afterRender misuse.  #51343

Closed

Description

@JeanMeche

Which @angular/* package(s) are relevant/related to the feature request?

core

Description

It'd be great if we could throw an error if a patched API is called within an afterRender() callback

For example :

afterRender(() => setTimeout(() => { ...}, 1000); will run into an infinte render loop

Currently, NG102 is only thrown when a new CD cycle is fired from the context of an afterRender (for example afterRender(() => cd.detectChanges())

Proposed solution

Throw an error to prevent an infinite loop.

Alternatives considered

¯\(ツ)/¯ let the dev close his browser tab and hope (s)he learns from his own mistake.

Activity

  1. added
    area: core
    on Aug 12, 2023
  2. added this to the needsTriage milestone on Aug 12, 2023
  3. changed the title [-]throw an error in case of `afterRender` misuse. [/-] [+]feature: throw an error in case of `afterRender` misuse. [/+] on Aug 12, 2023
  4. added
    feature
    on Aug 12, 2023
  5. modified the milestones: needsTriage, Backlog on Aug 12, 2023
  6. JelleBruisten commented on Aug 14, 2023

    @JelleBruisten
    Contributor

    ¯(ツ)/¯ let the dev close his browser tab and hope (s)he learns from his own mistake.

    😂

  7. alxhub commented on Aug 15, 2023

    @alxhub
    Member

    I wonder if afterRender should automatically run outside the Angular zone, so it doesn't trigger new rounds of change detection. That's worth thinking about.

  8. AndrewKushnir commented on Aug 29, 2023

    @AndrewKushnir
    Contributor

    Closing since PR #51385 is now merged.

  9. angular-automatic-lock-bot commented on Sep 29, 2023

    @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.

  10. locked and limited conversation to collaborators on Sep 29, 2023
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: corecore: lifecycle hooksfeature

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions