withastro / astro

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

Astro Actions: "Error: Unable to get API context." when is sended arguments to an action. #11423

Open ynhhoJ opened 2 weeks ago

ynhhoJ commented 2 weeks ago

Astro Info

Astro                    v4.11.5
Node                     v18.20.3
System                   Linux (x64)
Package Manager          unknown
Output                   server
Adapter                  @astrojs/node
Integrations             @astrojs/preact

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

Firefox

Describe the Bug

I followed example from Actions Proposal and everytime when is called an action with arguments like:

await actions.like({ postId })

Is returned error: Uncaught (in promise) Error: Unable to get API context. and 500 HTTP Status

But if we do:

await actions.like()

We get 400 HTTP Status and validation input error. image

What's the expected result?

There is no error when action:

await actions.like({ postId })

is called

Link to Minimal Reproducible Example

https://stackblitz.com/edit/withastro-astro-pdghi3?file=src%2Fcomponents%2FLike.tsx

Participation

florian-lefebvre commented 1 week ago

Yeah I think the 500 error should not occur here but be a 400 instead. @bholmesdev wdyt?

bholmesdev commented 1 week ago

Thanks for reporting @ynhhoJ! I just confirmed this a Stackblitz issue, but does not occur locally. Is that true for you as well? That 500 error is indeed unexpected

ynhhoJ commented 1 week ago

@bholmesdev , originally, on on my machine:

Astro                    v4.11.5
Node                     v20.15.0
System                   Linux (x64)
Package Manager          bun
Output                   server
Adapter                  @astrojs/node
Integrations             i18n:custom
                         @astrojs/tailwind
                         @astrojs/preact

I got another error Unexpected end of JSON input, every time when action has a body payload. So this is the cause why I opened this issue.

It's very strange:

Image ![image](https://github.com/withastro/astro/assets/22500212/77b73697-a23a-426c-864c-612ed54c5f74)

UPD: This error happens only with bun run --bun dev, if I run project from npm run dev, everything is OK

image

bholmesdev commented 1 week ago

got it. So to clarify @ynhhoJ: do all of the 500 errors you reported go away when using npm? We don't officially support bun, so I'd like to table that dsicussion

ynhhoJ commented 1 week ago

do all of the 500 errors you reported go away when using npm?

Yeah. I opened an issue to bun repo.

Thank you!

ynhhoJ commented 1 week ago

Sorry for issue close, maybe 500 error should be fixed by Astro team :D

But Unexpected end of JSON input will be on Bun side

bholmesdev commented 1 week ago

@ynhhoJ Alright got it, that's good info. I know we rely on the node:async_hooks import for API context. It seems Bun has implemented this, but it could be an issue with the combo of Node and Vite. Not sure which side that issue is on yet.

florian-lefebvre commented 1 week ago

Also stackblitz has issues with ALSs