fix(core): align DynamicValueSchema with resolveActionParam's runtime contract - #330
Open
hata33 wants to merge 1 commit into
Open
fix(core): align DynamicValueSchema with resolveActionParam's runtime contract#330hata33 wants to merge 1 commit into
hata33 wants to merge 1 commit into
Conversation
… contract
resolveActionParam (via resolvePropValue) accepts $index expressions,
$item expressions, arrays, and plain objects with recursively dynamic
values — all documented shapes for action params inside repeats. But
DynamicValueSchema only allowed literals and { $state }, so
schema-validating an emitted spec against ActionBindingSchema produced
false rejections for exactly the shapes the runtime resolves fine.
Widen the union to cover the documented contract: { $item }, { $index },
arrays of dynamic values, and records whose values are dynamic values
(mirroring the runtime's recursive object/array resolution). Expression
object arms stay strict so typos in $state/$item/$index keep failing
fast when they are the only applicable arm.
Fixes vercel-labs#296
Contributor
|
@hata33 is attempting to deploy a commit to the Vercel Labs Team on Vercel. A member of the Team first needs to authorize it. |
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.
Summary
DynamicValueSchemarejects shapes thatresolveActionParamresolves correctly at runtime, producing false positives for tools that schema-validate emitted specs againstActionBindingSchema:All three shapes are documented API (the schema rules shipped in
packages/react/src/schema.tstell the model to use{ "$item": "field" }`` and{ "$index": true }`` inside repeated children, and the runtime recursively resolves arrays and plain-object values viaresolvePropValue).Changes
Widen the union in
packages/core/src/types.ts:{ $item: string }— resolves to an absolute state path in action params{ $index: true }— resolves to the current repeat indexThe expression object arms stay strict, so a malformed
{ $state: 123 }still fails its dedicated arm — it only passes via the record arm, exactly matching the runtime, which treats it as a literal passthrough object.Tests
Added a parity block to
packages/core/src/types.test.tsthat runs each widened shape through bothDynamicValueSchema.safeParseandresolveActionParam, pinning schema/runtime agreement:Fixes #296