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.request.headers was used" warning when rewriting root path #12931

Closed
1 task
si-fab opened this issue Jan 8, 2025 · 3 comments · Fixed by #12937
Closed
1 task

"Astro.request.headers was used" warning when rewriting root path #12931

si-fab opened this issue Jan 8, 2025 · 3 comments · Fixed by #12937
Assignees
Labels
- P3: minor bug An edge case that only affects very specific usage (priority) feat: routing Related to Astro routing (scope) needs response Issue needs response from OP

Comments

@si-fab
Copy link

si-fab commented Jan 8, 2025

Astro Info

Astro                    v5.1.3
Node                     v22.9.0
System                   macOS (arm64)
Package Manager          npm
Output                   static
Adapter                  none
Integrations             none

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

No response

Describe the Bug

When rewriting from the / path to a subpath, Astro prints a warning about request headers being accessed.

14:49:27 [WARN] `Astro.request.headers` was used when rendering the route `src/pages/index.astro'`. `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.

You can reproduce the issue with the attached repository by running npm run dev and then navigating the browser to localhost:4321.

The reproduction is the basic Astro template. The only changes I have made is moving index.astro to a /en subfolder and creating a top level index.astro that executes `Astro.rewrite("/en").

screenshot

What's the expected result?

I expect no warning. I'm not accessing the request headers.

Link to Minimal Reproducible Example

https://github.com/si-fab/reproduce-header-warning

Participation

  • I am willing to submit a pull request for this issue.
@github-actions github-actions bot added the needs triage Issue needs to be triaged label Jan 8, 2025
@matthewp
Copy link
Contributor

matthewp commented Jan 8, 2025

The warning seems valid to me. index.astro is a prerendered page, it will be rendered to HTML at build time. So it cannot do a rewrite at runtime. You need to make it be not prerendered. Let me know if I'm missing something.

@matthewp matthewp added needs response Issue needs response from OP and removed needs triage Issue needs to be triaged labels Jan 8, 2025
@ematipico
Copy link
Member

ematipico commented Jan 8, 2025

I believe the issue is valid. In the reproduction, Astro.rewrite should work and shouldn't raise any warnings 🤔

@si-fab
Copy link
Author

si-fab commented Jan 8, 2025

I also believe it is valid 😋. The rewrite is done during build time and not during runtime. Why should rewriting during build time need access to request headers?

@ematipico ematipico added - P3: minor bug An edge case that only affects very specific usage (priority) feat: routing Related to Astro routing (scope) labels Jan 8, 2025
@ematipico ematipico self-assigned this Jan 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P3: minor bug An edge case that only affects very specific usage (priority) feat: routing Related to Astro routing (scope) needs response Issue needs response from OP
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants