withastro / astro

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

ActionError and Node Adapter #12489

Open abegehr opened 1 day ago

abegehr commented 1 day ago

Astro Info

Astro                    v4.15.9
Node                     v22.6.0
System                   macOS (arm64)
Package Manager          unknown
Output                   static
Adapter                  none
Integrations             none

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

I've tested on Safari and Chrome and occurs on both.

Describe the Bug

  1. Create an action that throws an ActionError: https://docs.astro.build/en/guides/actions/#creating-an-actionerror
  2. Call the action from a form: https://docs.astro.build/en/guides/actions/#call-actions-from-an-html-form-action
  3. Use the node adapter to host the astro app, build it, and start the server.
  4. Submit the form to run the action.
  5. Issue: The page is blank with status code of the ActionError. When run in dev mode, the error can be shown using Astro.getActionResult(): https://docs.astro.build/en/guides/actions/#handle-form-action-errors

What's the expected result?

I would expect the node adapter to handle action error the same as the dev mode.

To repro the issue, build and preview: npm run build and npm run preview to host astro on the standalone node adapter. The issue also occurs on the node middleware adapter, which is what I'm using.

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-iad8ez

Participation

abegehr commented 1 day ago

Running with npm run dev works fine:

Screenshot 2024-11-21 at 10 11 24

Running dist with npm run preview fails:

Screenshot 2024-11-21 at 10 12 02

Console:

anton@Mac github-iad8ez % npm run dev    

> @example/minimal@0.0.1 dev
> astro dev

10:10:53 [types] Generated 1ms

 astro  v4.16.13 ready in 91 ms

┃ Local    http://localhost:4321/
┃ Network  use --host to expose

10:10:53 watching for file changes...
10:10:55 [500] / 38ms
myAction() test1
10:10:57 [302] POST / 15ms
10:10:57 [500] / 3ms
^C
anton@Mac github-iad8ez % npm run preview

> @example/minimal@0.0.1 preview
> astro preview

10:11:43 [@astrojs/node] Server listening on http://localhost:4321
myAction() test2