-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
astro:actions transforms empty string form inputs into null #13562
Copy link
Copy link
Open
Labels
- P2: has workaroundAn edge case that only affects very specific usage, but has a trivial workaround (priority)An edge case that only affects very specific usage, but has a trivial workaround (priority)feat: actionsRelated to Astro actions (scope)Related to Astro actions (scope)needs discussionIssue needs to be discussedIssue needs to be discussed
Description
Astro Info
Astro v5.6.1
Node v22.11.0
System macOS (x64)
Package Manager pnpm
Output server
Adapter @astrojs/node
Integrations @astrojs/react
simple-stream
@astrojs/tailwind
If this issue only occurs in one browser, which browser is a problem?
No response
Describe the Bug
When using astro:actions to handle a form submission, an empty <input type="text" /> field is unexpectedly parsed as null rather than an empty string. This causes Zod to throw a type error (invalid_type).
{
error: [ActionInputError: Failed to validate: [
{
"code": "invalid_type",
"expected": "string",
"received": "null",
"path": [
"email"
],
"message": "Expected string, received null"
}
]]
}
What's the expected result?
An empty form input should submit an empty string, which is a valid string. I would expect Zod to throw a different error than "Expected string, received null", depending on the schema.
For example, for the shcema z.object({ email: z.string().trim().email() }).strict() I would expect an Invalid email error if an empty field is submitted, similar to this zod playground.
Astro actions didn’t work for me on StackBlitz, so here’s the CodeSandbox link to a minimal reproducible example instead.
Link to Minimal Reproducible Example
https://codesandbox.io/p/devbox/6fvnh7
Participation
- I am willing to submit a pull request for this issue.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
- P2: has workaroundAn edge case that only affects very specific usage, but has a trivial workaround (priority)An edge case that only affects very specific usage, but has a trivial workaround (priority)feat: actionsRelated to Astro actions (scope)Related to Astro actions (scope)needs discussionIssue needs to be discussedIssue needs to be discussed