Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix action form parsing for .nullish #11452

Merged
merged 2 commits into from
Jul 17, 2024
Merged

Conversation

FugiTech
Copy link
Contributor

Changes

In the experimental Astro actions, users can provide an input schema using zod and parse formdata natively with accept: 'form'. However, if a user uses the .nullish() zod modifier, it will always treat the field as a string, regardless of the intended type.

This is because zod's .nullish() is equivalent to .nullable().optional() and returns z.ZodOptional<z.ZodNullable<ActualType>> and must be double-unwrapped to get the underlying type.

This change swaps from a single-unwrap of ZodOptional and ZodNullable to a loop that can go as deep as needed.

Testing

This change was not tested.

Docs

No docs were written or changed as this is a bugfix.

Copy link

changeset-bot bot commented Jul 10, 2024

🦋 Changeset detected

Latest commit: aa885e0

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added the pkg: astro Related to the core `astro` package (scope) label Jul 10, 2024
@bluwy bluwy requested a review from bholmesdev July 17, 2024 07:44
Copy link
Contributor

@bholmesdev bholmesdev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! Very bullish on this

@bluwy bluwy merged commit 0e66849 into withastro:main Jul 17, 2024
13 checks passed
@astrobot-houston astrobot-houston mentioned this pull request Jul 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: astro Related to the core `astro` package (scope)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants