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

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

Open
1 task
RaphaelBossek opened this issue Aug 17, 2024 · 6 comments
Open
1 task
Labels
needs response Issue needs response from OP needs triage Issue needs to be triaged

Comments

@RaphaelBossek
Copy link
Contributor

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

  • 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 Aug 17, 2024
@RaphaelBossek RaphaelBossek changed the title Warning messages when reading cookies in middleware functions in Astro 4.14.2 Warning messages when reading cookies in middleware functions with hybrid output Aug 17, 2024
@cielorz
Copy link

cielorz commented Aug 18, 2024

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

@ematipico
Copy link
Member

ematipico commented Aug 18, 2024

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

In particular, please provide:

  • instructions on how to reproduce the warning
  • which pages you're rendering, that produce the warning

@ematipico ematipico added the needs response Issue needs response from OP label Aug 18, 2024
@RaphaelBossek
Copy link
Contributor Author

RaphaelBossek commented Aug 18, 2024

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
Copy link

cielorz commented Aug 18, 2024 via email

@hkbertoson
Copy link

Its the same as #11751 The error message was fixed at one point. But then got reintroduced at some point.

@bholmesdev
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs response Issue needs response from OP needs triage Issue needs to be triaged
Projects
None yet
Development

No branches or pull requests

5 participants