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

fix(routing): don't trigger get of headers #12937

Merged
merged 2 commits into from
Jan 8, 2025

Conversation

ematipico
Copy link
Member

Changes

Closes #12931
Closes PLT-2736

The issue was that doing oldRequest.headers during a rewrite was causing the warning to fire, because it triggers the .get method.

This is fixed now by checking the isPrerendered flag.

Also, I updated the method copyRequest to use the internal method copyRequest, which creates the headers object based on isPrenredererd. This should fix cases (not caught, probably) where users could have used Request.headers during a rewrite.

Testing

I tested it locally using the reproduction provided.

Docs

N/A

Copy link

changeset-bot bot commented Jan 8, 2025

🦋 Changeset detected

Latest commit: f6483fe

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added the pkg: astro Related to the core `astro` package (scope) label Jan 8, 2025
| ReadableStream
| URLSearchParams
| FormData
| ReadableStream<Uint8Array>;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is type provided by Request.body

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we use Request['body'] instead?


export interface CreateRequestOptions {
url: URL | string;
clientAddress?: string | undefined;
headers: HeaderType;
method?: string;
body?: RequestBody | undefined;
body?: RequestBody | undefined | null;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added null because Request.body is ReadableStream<Uint8Array> | null

Copy link

codspeed-hq bot commented Jan 8, 2025

CodSpeed Performance Report

Merging #12937 will not alter performance

Comparing fix/rewrite-headers-warnings (f6483fe) with main (fd12a26)

Summary

✅ 6 untouched benchmarks

* @param newUrl The new `URL`
* @param oldRequest The old `Request`
*/
export function copyRequest(newUrl: URL, oldRequest: Request, isPrerendered: boolean): Request {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is this version of the function used?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bad copy-paste. Good catch

'astro': patch
---

Fixes an issue where the use of `Astro.rewrite` would trigger the invalid use of `Astro.request.headers`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these two separate issues beign fixed? It's a little unclear.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. What should I reword?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's fine. Just wanted to confirm that they're separate.

@ematipico ematipico merged commit 30edb6d into main Jan 8, 2025
16 checks passed
@ematipico ematipico deleted the fix/rewrite-headers-warnings branch January 8, 2025 18:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: astro Related to the core `astro` package (scope)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"Astro.request.headers was used" warning when rewriting root path
3 participants