Repository navigation
fix(forms): safely chain debounced async validation resources - #71414
Open
benjavicente wants to merge 1 commit into
Open
benjavicente wants to merge 1 commit into
benjavicente wants to merge 1 commit into
Conversation
Pass debounced params to async validator factories without exposing resource status sentinels. Compose snapshots separately to preserve pending and error states, and delegate reloads after debounce settles. Add regression coverage for effects, custom snapshots, params error recovery, and reloadValidation. Fixes angular#70884
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Checklist
PR Type
What kind of change does this PR introduce?
What is the current behavior?
In signal forms,
validateAsyncwithdebounceconfigured passes a params signal that can throw the internalResourceParamsStatus.LOADING. Factories that consume that signal in an effect or useresourceFromSnapshotscan fail outside theresource()params handler.The
傻chainfunction seems only used in that way in signal forms (傻chain(has only 1 result in the codebase), and the docs mention that chain is to be used on the params function, giving the consumer the option to chain resources, while thevalidateAsyncfunction hides that and can lead to unexpected errors when the param function throws in an unexpected context. That creates a problem for libraries that can return the Resource interface but don't use the Resource API, since it's the Resource API param's function that catches the issue, not the Interface that libraries can implement to adapt into Angular libraries.Issue Number: #70884
What is the new behavior?
Pass a safe debounced params signal to the factory, retaining the previous value during debounce, and compose the debounce resource and factory resource safely, without
傻chain. The safe chain forwards reloads to preservesreloadValidation()functionality.Does this PR introduce a breaking change?
Other information
In the future, a resource type that declares the
Resource & { reload: () => boolean }could be used as a union to better declare the usage of the reload method, see #69443 (alternatives considered forvalidateAsyncinterface) and #71299 (Router'snonBlockingutility type).