withPreviousValueOnLoading: computed value remains undefined after initial request resolves
Which @ngrx/* package(s) are the source of the bug?
signals
Minimal reproduction of the bug/regression with instructions
Description
When using extendResource with withPreviousValueOnLoading(), a computed signal that reads resource.value() during the initial loading state remains undefined after the request resolves.
The resource status becomes resolved, and reading resource.value() directly returns the response. However, the computed does not update, so a list bound to it remains empty.
Reproduction
- Open the reproduction and wait for the resource status to show
loading. - Click Complete HTTP request.
- Observe that:
- The resource status becomes
resolved. - The direct resource value becomes
["one", "two"]. computed(() => resource.value())remainsundefined.- A computed that explicitly reads
resource.isLoading()updates correctly.
- The resource status becomes
Relevant code
// Application providers
provideResourceExtensions(withPreviousValueOnLoading())
// Component
readonly resource = extendResource(
httpResource<string[]>(() => '/items')
);
readonly rows = computed(() => this.resource.value());The template reads rows() while the first request is still loading.
Actual behavior
The computed remains undefined, even after a subsequent direct read of resource.value() returns the response.
Expected behavior
The computed should update when the first request resolves and expose the response data.
Versions of NgRx, Angular, Node, affected browser(s) and operating system(s)
@ngrx/signals: 22.0.1 Angular: 22.1.6 Angular CLI: 22.1.8 TypeScript: 6.0.3
Other information
Suspected cause
The extension's value proxy checks:
if (!untracked(resource.isLoading)) {
value = Reflect.apply(target, thisArg, args);
}
return value;During loading, this returns the cached value without tracking isLoading or reading the underlying value signal. A computed first evaluated in this state therefore records no signal dependencies and is not invalidated when the request resolves.
Workaround / comparison
Explicitly reading the loading signal inside the computed makes it update:
readonly rows = computed(() => {
this.resource.isLoading();
return this.resource.value();
});Removing withPreviousValueOnLoading() also restores the expected behavior. No other resource extensions are required to reproduce the issue.
I would be willing to submit a PR to fix this issue
- Yes
- No
Source: ngrx/platform