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

Closed
1 task
RaphaelBossek opened this issue Aug 17, 2024 · 11 comments
Closed
1 task
Labels
- P2: has workaround Bug, but has workaround (priority) feat: middleware Related to middleware (scope)

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.

@florian-lefebvre
Copy link
Member

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

@bholmesdev
Copy link
Contributor

context.isPrererendered is now supported! @RaphaelBossek can you try this API on the 5.0 beta and give us your feedback?

@florian-lefebvre florian-lefebvre added - P2: has workaround Bug, but has workaround (priority) feat: middleware Related to middleware (scope) and removed needs triage Issue needs to be triaged labels Sep 23, 2024
@mlafeldt
Copy link

Looks like it's still called _isPrerendered ...

_isPrerendered: isPrerendered,

... and not officially part of the context yet.

if ((context as any)._isPrerendered) {

Apart from that, it works fine!

@florian-lefebvre
Copy link
Member

That's because the change is on the next branch

@florian-lefebvre florian-lefebvre removed the needs response Issue needs response from OP label Sep 28, 2024
@ematipico
Copy link
Member

ematipico commented Oct 2, 2024

I just tried the user's reproduction, and I can't see the warning anymore when using ctx.isPrendered. The fix is only available in Astro v5.

Closing as completed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P2: has workaround Bug, but has workaround (priority) feat: middleware Related to middleware (scope)
Projects
None yet
Development

No branches or pull requests

7 participants