Skip to content

astro:actions transforms empty string form inputs into null #13562

@romanstetsyk

Description

@romanstetsyk

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    - P2: has workaroundAn edge case that only affects very specific usage, but has a trivial workaround (priority)feat: actionsRelated to Astro actions (scope)needs discussionIssue needs to be discussed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions