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

@astrojs/netlify Adapter processes edge middleware when building static pages #13179

Open
1 task done
JacobNWolf opened this issue Jan 11, 2025 · 0 comments
Open
1 task done
Labels
needs triage Issue needs to be triaged pkg: netlify Related to the Netlify adapter

Comments

@JacobNWolf
Copy link

Astro Info

Astro                    v5.1.1
Node                     v20.13.1
System                   macOS (arm64)
Package Manager          bun
Output                   static
Adapter                  @astrojs/netlify
Integrations             @astrojs/tailwind
                         @astrojs/react
                         astro-icon
                         @astrojs/partytown
                         @sentry/astro
                         astro-robots-txt

Describe the Bug

When Astro builds a site with the Netlify adapter on static mode, it is processing the middleware when it is building static pages. This occurs regardless of whether or not edgeMiddleware: true in the adapter configuration. When the middleware uses any of the server-side headers or request methods, it outputs the message:

Astro.request.headers was used when rendering the route src/pages/*. Astro.request.headers is not available on prerendered pages. If you need access to request headers, make sure that the page is server-rendered using export const prerender = false; or by setting output to "server" in your Astro config to make all your pages server-rendered by default.

This is expected if normal middleware is elected. However, with edge middleware, middleware will run even on the static pages. Example is attached.

What's the expected result?

Ultimately if edgeMiddleware: true in the astro.config.mjs, this message should not output at all. The headers and request info are able to be accessed in edgeMiddleware even on static pages as if they were server rendered.

Link to Minimal Reproducible Example

https://stackblitz.com/edit/withastro-astro-3u3rtsrg?file=src%2Fmiddleware.ts

Participation

  • I am willing to submit a pull request for this issue.
@JacobNWolf JacobNWolf changed the title @astrojs/netlify Adapter processes middlware when building static pages @astrojs/netlify Adapter processes middleware when building static pages Jan 11, 2025
@JacobNWolf JacobNWolf changed the title @astrojs/netlify Adapter processes middleware when building static pages @astrojs/netlify Adapter processes edge middleware when building static pages Jan 11, 2025
@ematipico ematipico added the pkg: netlify Related to the Netlify adapter label Feb 7, 2025
@ematipico ematipico transferred this issue from withastro/adapters Feb 7, 2025
@github-actions github-actions bot added the needs triage Issue needs to be triaged label Feb 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs triage Issue needs to be triaged pkg: netlify Related to the Netlify adapter
Projects
None yet
Development

No branches or pull requests

2 participants