withastro / astro

The web framework for content-driven websites. ⭐️ Star to support our work!
https://astro.build
Other
46.81k stars 2.49k forks source link

[Actions] Zod object.passthrough does not allow extra input keys/values #11693

Closed chaffinated closed 2 months ago

chaffinated commented 3 months ago

Astro Info

Astro                    v4.13.2
Node                     v20.12.2
System                   macOS (x64)
Package Manager          npm
Output                   server
Adapter                  @astrojs/cloudflare
Integrations             @astrojs/solid-js
                         @astrojs/tailwind

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

When using a zod object schema to validate an action input, using z.object({}).passthrough() has no effect and does not allow additional keys and values.

This line is the cause: https://github.com/withastro/astro/blob/main/packages/astro/src/actions/runtime/virtual/server.ts#L135C19-L135C32

Depending on the desired behavior, it may be more correct to iterate over formData rather than schema.shape.

What's the expected result?

When the action input schema allows for additional keys, the validator does not strip them from the input.

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-vkxmc9?file=src%2Factions%2Findex.ts

Participation

gtrabanco commented 3 months ago

I think this is related to the same problem of the issue #11641

Because now it is using z.ZodObject instead of z.ZodEffect as @bryanwood said in this comment: https://github.com/withastro/astro/issues/11641#issuecomment-2285221026