Skip to content

Feature request: passiveRead (or peek) for non-computation-triggering Signal access #67741

@Akxe

Description

@Akxe

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

core

Description

Current Signal reads always pull. In Angular, reading a Signal (even via untracked) forces a recomputation if the producer is "dirty." This makes it impossible to observe a Signal without potentially triggering expensive work or side effects (e.g., httpResource fetching).

Proposed solution

Introduce a passiveRead(signal) utility.

  • Behaviour: It returns a wrapper object (e.g., { hasValue: true, value: T } | { hasValue: false, value: undefined }).
  • Reactive Graph: If used inside an effect or computed, it adds the caller to the dependency graph (so the effect re-runs when the signal changes), but it never triggers a re-computation of the source signal if it is currently dirty.
  • Return Value: It will return the signal's current value unless the value has not yet been computed

Use Case: Conditional Observer Syncing
In complex scenarios, offent including external libraries, the developer need to sync data and options to the library, but it would be beneficial if it could be done in a way that would not make all of the options/data computed unless the resulting values is actually needed.

Use Case: toLazyObservable
This would provide a solution to #55337

effect(() => {
  const result = passiveRead(myResource.value);

  if (!result.hasValue) {
  // If result.hasValue is false, no computation was forced.
    return;
  }

  // result.hasValue is true only if the signal is being also observed by some other non-passive observers
  console.log('Passive Update:', result.value);
});

Alternatives considered

I do not think there is a workaround.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: coreIssues related to the framework runtimecross-cutting: signalsfeatureLabel used to distinguish feature request from other issues

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions