withastro / astro

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

Warning messages when reading cookies in middleware functions with hybrid output #11756

Open RaphaelBossek opened 1 month ago

RaphaelBossek commented 1 month ago

Astro Info

Astro                    v4.14.2
Node                     v18.17.1
System                   Linux (x64)
Package Manager          pnpm
Output                   hybrid
Adapter                  @astrojs/node
Integrations             set-prerender

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

Not a browser problem

Describe the Bug

While reading cookies in middleware function result in following warning:

[WARN] Astro.request.headers is unavailable in "static" output mode, and in prerendered pages within "hybrid" and "server" output modes. If you need access to request headers, make sure that output is configured as either "server" or output: "hybrid" in your config file, and that the page accessing the headers is rendered on-demand.

What's the expected result?

No warning message.

Link to Minimal Reproducible Example

https://stackblitz.com/~/github.com/RaphaelBossek/astro-auth-middleware-test

Participation

cielorz commented 1 month ago

I think this issue would be same to #11751, @bholmesdev

ematipico commented 1 month ago

@RaphaelBossek can you provide more context or reasons about why this is a bug?

In particular, please provide:

RaphaelBossek commented 1 month ago

The advice is to change to output mode "hybrid" but I'm in "hybrid" mode.

This warning can be surpressed when the cookie getter code is removed from the middleware function.

I've applied an "working" example at https://stackblitz.com/~/github.com/RaphaelBossek/astro-auth-middleware-test with this warning, so your questions are answered within the short "code". Could you pleaes precise your questions based on the Minimal, Reproducible Example.

cielorz commented 1 month ago

I think this warning might brought by recent changes in astro action. Before ver 4.13.2 there is no warning when build.


From: @hephaistos_DE @.> Sent: Sunday, August 18, 2024 8:31:25 PM To: withastro/astro @.> Cc: Ciel @.>; Comment @.> Subject: Re: [withastro/astro] Warning messages when reading cookies in middleware functions with hybrid output (Issue #11756)

The advice is to change to output mode "hybrid" but I'm in "hybrid" mode. I've applied an "working" example at https://stackblitz.com/~/github.com/RaphaelBossek/astro-auth-middleware-test with this warning, so your questions are answered within the short "code". Could you pleaes precise your questions based on the Minimal, Reproducible Example.

— Reply to this email directly, view it on GitHubhttps://github.com/withastro/astro/issues/11756#issuecomment-2295245346, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ALFPQ5J2NGJS5WEZEA7AHT3ZSCHZ3AVCNFSM6AAAAABMVGZ6BOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEOJVGI2DKMZUGY. You are receiving this because you commented.Message ID: @.***>

hkbertoson commented 1 month ago

Its the same as https://github.com/withastro/astro/issues/11751 The error message was fixed at one point. But then got reintroduced at some point.

bholmesdev commented 1 month ago

Hey @RaphaelBossek! Thanks for reporting. It seems that middleware runs on prerendered routes in development, which trips that warning log when accessing headers or cookies.

We have some Astro maintainers discussing how to expose whether a route is prerendered or not so you can check this from middleware. You can join the discord to discussion in #feedback-ideas! For now, you can safely ignore the warning.

florian-lefebvre commented 2 days ago

It's available in 5.0 beta, you can use context.isPrererendered