-
Notifications
You must be signed in to change notification settings - Fork 171
fix: Avoid merging Location header on response when its an array #977
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
base: main
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: de49e88 The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
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 |
commit: |
Thanks for putting this PR together @sommeeeer ! A few questions as you have looked into this: Do I understand correctly than Next doesn't really care about what's returned when there is no incremental cache... as they always have an incremental cache? Should we rather error when we have static/cached content and no incremental cache? If the header value is an array |
Yeah, or they should SSR that page then, but for some reason in this case the Location's value is an array. Well, when I think more about this. Why would you ever want to setup an OpenNext/Next project without ISR. You could just use the
Yeah, they are always the same. I guess somewhere in Next's code they put that header value twice when |
Not sure what is the best way to handle this. Maybe the Open Next build should fail when Next has cache artifacts and Open Next has no cache configured? I think it's worth leaving this PR opened until we discuss more about it. |
Thats actually a great idea, however I think we should discuss this further as you mentioned. This decision can have consequences and needs to be thought about thoroughly. I'll leave it open for now. |
It should be a big warning not an error. If your app is fully SSR, it could make sense to have no Incremental cache. This error could also happen if you have a cache configured, but it errors out. In this case we return null from the cache handler (same thing as with the dummy incremental cache) and we have this bug As to what exactly to do here, before picking the value, we should check if they are the same, if it's the case we're fine. |
Thanks for the reviews!
Alright, I addressed this in a review commit. |
*/ | ||
if (keyLower === "location" && Array.isArray(value)) { | ||
if (value[0] === value[1]) { | ||
result[keyLower] = value[0]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are we sure they are always exactly 2 values in the array?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are we sure they are always exactly 2 values in the array?
Yeah, and it could only happen if it returns null
from a get in the cacheHandler.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe you can add the info in the JS doc ?
This is for opennextjs/opennextjs-cloudflare#875 (comment)
Next will return a header like
Location: ["/target", "/target"];
on the response for aredirect("/target");
in a staticpage.tsx
when you dont have anincrementalCache
. We should not merge that header's value withjoin(",");
Affected line in Next: https://github.com/vercel/next.js/blob/ea08bf27/packages/next/src/server/base-server.ts#L1521
This is me

console.log(res._res.headers)
before and after that line with a reproduction: