Validate async signal leaks resource internals
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 45/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 活発
- 技術スタック
- angular, typescript
- 領域
- frontend
調査の方向性
Look at the validateAsync function in @angular/forms, particularly how it handles debounced signals and the Resource interface. The reproduction repo shows the error. Understand the resourceFromSnapshots and resource APIs. The fix likely involves ensuring the signal passed to the factory does not throw internal sentinel errors when debounce is used.
索引モデルが issue の本文から書いたものです。
説明
Which @angular/* package(s) are the source of the bug?
forms
Is this a regression?
No
Description
Let's say we have a function like this:
type Result = { loading: true } | { loading: false; value: string }
function injectResult(value: () => string): Signal<Result> {
// The implementation could be more complex than this,
// but the issue still happens with only this code.
return computed(() => ({ loading: false, value: value() }))
}
const value = signal('Hello Angular!')
const result: Signal<Result> = injectResult(() => value())
We can convert it to a resource like this:
function toSnapshot(result: Result) {
if (result.loading) {
return { status: 'loading', value: undefined }
}
return { status: 'resolved', value: result.value }
}
function toResource(result: Signal<Result>) {
return resourceFromSnapshots(() => toSnapshot(result()))
}
Since validateAsync works with the Resource interface (not the API), one might expect this to work:
@Component({ ... })
export class Registration {
registrationModel = signal({ username: '' })
registrationForm = form(this.registrationModel, (schemaPath) => {
validateAsync(schemaPath.username, {
params: ({ value }) => value(),
factory: (value) => {
const result = injectResult(value)
return toResource(result)
},
onSuccess: () => {},
onError: () => {},
})
})
}
This works with those options, but if we add debounce to the validateAsync options, we get:
ERROR _ResourceParamsStatus: LOADING
The workaround is to wrap the validation signal in a resource to catch the internal sentinel error:
factory: (value) => {
const settled = resource({
params: () => value(),
loader: async ({ params }) => params,
})
const result = injectResult(() => {
return settled.hasValue() ? settled.value() : ''
})
return toResource(result)
}
The expectation is that the signal passed to factory contains the debounced value, rather than a signal that may throw.
Requiring that signal to be used with the resource API (not just the interface) makes it harder for libraries that do not use that API to integrate with Signal Forms, but can provide a Resource Interface. For example, libraries like a resouce-like API for localstorage and query/sync libraries.
Please provide a link to a minimal reproduction of the bug
https://github.com/benjavicente/angular-validate-async-resource-repro
Please provide the exception or error you saw
Please provide the environment you discovered this bug in (run ng version)
┌───────────────────────────┬───────────────────┬───────────────────┐
│ Package │ Installed Version │ Requested Version │
├───────────────────────────┼───────────────────┼───────────────────┤
│ @angular/build │ 22.1.8 │ ^22.0.0 │
│ @angular/cli │ 22.1.8 │ ^22.0.0 │
│ @angular/common │ 22.1.7 │ ^22.0.0 │
│ @angular/compiler │ 22.1.7 │ ^22.0.0 │
│ @angular/compiler-cli │ 22.1.7 │ ^22.0.0 │
│ @angular/core │ 22.1.7 │ ^22.0.0 │
│ @angular/forms │ 22.1.7 │ ^22.0.0 │
│ @angular/platform-browser │ 22.1.7 │ ^22.0.0 │
│ rxjs │ 7.8.2 │ ~7.8.0 │
│ typescript │ 6.0.3 │ ~6.0.2 │
└───────────────────────────┴───────────────────┴───────────────────┘
Anything else?
No response
- 主要言語
- TypeScript
- スター
- 101k
- フォーク
- 28.1k
- 平均マージ
- 2日 6時間
- マージ済み PR(30日)
- 307
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
angular/angular のほかの issue
-
area: docs
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
-
area: forms forms: signals
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
-
area: docs gemini-triaged
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
-
area: forms forms: signals
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
-
area: docs area: forms
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
angular/angular の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
vercel-labs/just-bash#464 ·
-
looksLikeSlug() is ASCII-only, so non-Latin entity slugs (e.g. Korean) skip exact match and collapse オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
-
難易度 1/5 1時間未満 初心者へのやさしさ 90/100
TanStack/tanstack.com#1293 ·