withastro / astro

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

Server actions cause an error when returning a value of 0. #11549

Closed bryanwood closed 3 months ago

bryanwood commented 3 months ago

Astro Info

Astro                    v4.12.2
Node                     v18.20.3
System                   Linux (x64)
Package Manager          npm
Output                   server
Adapter                  none
Integrations             none

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

No response

Describe the Bug

When returning the number 0 from a server action an error occurs:

Response constructor: Invalid response status code 204

Cause appears to be this falsy check: https://github.com/withastro/astro/blob/7f26de906e87f1e8973a1f84399f23e36e506bb3/packages/astro/src/actions/runtime/route.ts#L43

Should this check for only null and undefined values?

A work around is to wrap the value in an object literal e.g. { number: 0 }

What's the expected result?

The action returns the value 0.

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-fozayp?file=src%2Fpages%2Findex.astro

Participation

bluwy commented 3 months ago

It should probably use a != null check, feel free to send a PR!