Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Validate async signal leaks resource internals

Đang mở
#70,884 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
45/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
angular, typescript
Lĩnh vực
frontend

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

area: forms gemini-triaged
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

Ngôn ngữ chính
TypeScript
Star
101k
Fork
28.1k
Merge trung bình
2 ngày 6 giờ
Pull request đã merge (30 ngày)
307

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của angular/angular

Tất cả issue của angular/angular

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.