Repository navigation
feat(forms): resource and loader validation - #71613
Open
benjavicente wants to merge 2 commits into
Open
benjavicente wants to merge 2 commits into
benjavicente wants to merge 2 commits into
Conversation
Expose settledResourceValue to read completed resource values as a signal when integrating resource state with value-based reactive APIs. Expose the existing fatal resource error policy internally so Forms can preserve programming errors when adapting validation params to snapshots.
Separate resource factories from async loaders so validation can compose resource state without exposing implicit chain markers through a signal. Add validateResource and validateAsyncLoader, preserve pending and error state across debounce transitions, and delegate reloads to the resource. Migrate Standard Schema validation and update the guides and public APIs. Cover validation gating, errors, reloads, request replacement, cleanup, and compatibility with the existing validator. DEPRECATED: deprecate validateAsync in Signal Forms Use validateAsyncLoader for async functions or validateResource for resource factories. The validateResource factory receives params as a Resource instead of a Signal. Preserve the existing validateAsync runtime behavior.
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 is the current behavior?
Issue: #70884
Related discussion: #71414 (comment)
When debounce is enabled,
validateAsynccallsɵchaininternally and supplies the factory with a params signal that can throw resource status markers.This implicitly relies on the factory reading that signal inside a core resource's
paramscallback, where those markers are handled. Implementing theResourceinterface alone does not provide that behavior.The public
chainAPI makes this composition explicit inside resource params, butvalidateAsynchides it from consumers.This does not work but types pass, no documentation says it should not work:
Usually, any API that read the params directly assuming it is a simple signal that will not throw, will fail for
validateAsyncs that are debounced.What is the new behavior?
validateResourceThe factory receives a params resource instead of an implicitly chained signal. Consumers can explicitly compose it using the resource API:
The validator composes the params resource with the returned resource, preserving validation's pending, idle, and error states.
validateAsyncLoaderFor async functions, consumers can provide a loader directly without creating a resource or repeating the params callback:
settledResourceValueThis helper exposes a resource's settled value as a signal. It returns the value for
resolvedandlocalstates, andundefinedfor other states.This makes resource values easier to compose with utilities that accept ordinary reactive values. For example:
validateResourcepreserves the params resource's pending and error states even when the adapted resource is disabled while params are unavailable.validateAsyncvalidateAsyncis deprecated without changing its existing runtime behavior. Standard Schema validation and the guide examples are updated to use the new APIs.It is marked as deprecated since it is using
chaininternally in a way it can end up unexpected to consumers.Does this PR introduce a breaking change?
Other information
Feel free to take over the PR/branch. AI assisted code. This is the "ideal" API I see for validation with promises and resources that keep the shape close to the current API. The APIs changes are sorted by priority, the important change needed to solve the issue is
validateResource, the other API changes could be reverted.