Skip to content

fix(core): fix change tracking for Resource#hasValue #62595

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

lizclipse
Copy link
Contributor

When using hasValue() I would expect it to behave like any other reactive value such that changes to the internal value() that do not cause hasValue() to return anything different do not trigger change detection, but this was not the case. This change wraps the value checking in a computed such that it behaves as expected again while still preserving the type narrowing.

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • angular.dev application / infrastructure changes
  • Other... Please describe:

What is the current behavior?

Each time a resource's value changes, even if it changes from e.g. a defined to a defined value, consumers of hasValue() will re-run.

Issue Number: N/A

What is the new behavior?

Consumers of hasValue() will re-run only if it has actually changed, preventing unnecessary change detection.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

When using `hasValue()` I would expect it to behave like any other
reactive value such that changes to the internal `value()` that do not
cause `hasValue()` to return anything different do not trigger change
detection, but this was not the case. This change wraps the value
checking in a `computed` such that it behaves as expected again while
still preserving the type narrowing.
@pullapprove pullapprove bot requested a review from mmalerba July 11, 2025 17:49
@angular-robot angular-robot bot added the area: core Issues related to the framework runtime label Jul 11, 2025
@ngbot ngbot bot added this to the Backlog milestone Jul 11, 2025
@mmalerba mmalerba added action: merge The PR is ready for merge by the caretaker target: patch This PR is targeted for the next patch release labels Jul 16, 2025
@kirjs
Copy link
Contributor

kirjs commented Jul 18, 2025

This PR was merged into the repository by commit b8e415a.

The changes were merged into the following branches: main, 20.1.x

@kirjs kirjs closed this in b8e415a Jul 18, 2025
kirjs pushed a commit that referenced this pull request Jul 18, 2025
When using `hasValue()` I would expect it to behave like any other
reactive value such that changes to the internal `value()` that do not
cause `hasValue()` to return anything different do not trigger change
detection, but this was not the case. This change wraps the value
checking in a `computed` such that it behaves as expected again while
still preserving the type narrowing.

PR Close #62595
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
action: merge The PR is ready for merge by the caretaker area: core Issues related to the framework runtime target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants