Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Astro Actions return a 404 on Netlify when all pages are prerendered #274

Open
1 task done
serhalp opened this issue Jun 6, 2024 · 0 comments
Open
1 task done
Labels
- P4: important Violate documented behavior or significantly improves performance (priority) pkg: netlify

Comments

@serhalp
Copy link

serhalp commented Jun 6, 2024

Astro Info

(some of this is irrelevant as this issue is specific to Netlify)

Astro                    v4.9.3
Node                     v20.11.1
System                   macOS (arm64)
Package Manager          unknown
Output                   hybrid
Adapter                  @astrojs/netlify
Integrations             @astrojs/react

Describe the Bug

👋🏼 Hey Astro friends. In trying to validate that experimental Astro Actions work well on Netlify, we found this issue. (Otherwise, it seems to work great!)

  1. commit deployment output: "server", 1 prerendered page + 1 SSR page
    • Actions work on both pages
  2. commit deployment output: "hybrid", 1 prerendered page + 1 SSR page
    • Actions work on both pages
  3. commit deployment output: "server", 2 prerendered pages
    • Actions do not work on any pages
  4. commit deployment output: "hybrid", 2 prerendered pages
    • Actions do not work on any pages

You can also reproduce this locally with netlify serve (not netlify dev).

I can see the POST /_actions/sayHello is responding with a 404.

I can see the SSR function is being invoked, but not the Action handler.

With some console.log sprinkling locally, I can see that 404 is coming from here (as opposed to line 24).

Here's the routeData returned by app.match:

  routeData: {
    route: '/_actions/[...path]',
    type: 'endpoint',
    pattern: /^\/_actions(?:\/(.*?))?$/,
    params: [ '...path' ],
    component: 'node_modules/astro/dist/actions/runtime/route.js',
    generate: [Function (anonymous)],
    pathname: undefined,
    segments: [ [Array], [Array] ],
    prerender: false,
    redirect: undefined,
    redirectRoute: undefined,
    fallbackRoutes: [],
    isIndex: false
  }

Any ideas on where to start here? Is there any intentional special behavior in Astro when output !== 'static' but all pages are opted in to prerendering? Happy to help but I could use some pointers. Thanks!

What's the expected result?

On all four branches linked above, clicking the button should print "hello ON the server" in the Netlify Function logs, print "hello FROM the server" in the browser console, and render "hello FROM the server" on the page.

Link to Minimal Reproducible Example

https://github.com/serhalp/astro-actions-netlify-demo/branches

Participation

  • I am willing to submit a pull request for this issue.
@ascorbic ascorbic added pkg: netlify - P4: important Violate documented behavior or significantly improves performance (priority) labels Jun 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P4: important Violate documented behavior or significantly improves performance (priority) pkg: netlify
Projects
None yet
Development

No branches or pull requests

2 participants