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

feat(server-runtime): v2_headers future flag for inheriting ancestor headers #6431

Merged
merged 10 commits into from
May 24, 2023

Conversation

brophdawg11
Copy link
Contributor

@brophdawg11 brophdawg11 commented May 19, 2023

It can be tedious and error-prone to remember to always export function headers() from every potential leaf route if you care about response headers on document requests. Prior to v1 the logic was to use the deepest renderable headers function that was found but this changed prior to v1 so we're adding it back behind a future flag for v2 to ensure no unintentional breakages in userland.

We still only call headers for "renderable" routes (those at or above the any active error boundaries), but we'll use the deepest discovered headers export, and not insist on it being a leaf.

Continuation of #5473
Closes #3157

@changeset-bot
Copy link

changeset-bot bot commented May 19, 2023

🦋 Changeset detected

Latest commit: bf0bfd6

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

This PR includes changesets to release 18 packages
Name Type
@remix-run/server-runtime Minor
@remix-run/cloudflare Minor
@remix-run/deno Minor
@remix-run/dev Minor
@remix-run/node Minor
@remix-run/react Minor
@remix-run/cloudflare-pages Minor
@remix-run/cloudflare-workers Minor
create-remix Minor
@remix-run/css-bundle Minor
@remix-run/architect Minor
@remix-run/express Minor
@remix-run/netlify Minor
@remix-run/serve Minor
@remix-run/testing Minor
@remix-run/vercel Minor
remix Minor
@remix-run/eslint-config Minor

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

...(loaderHeaders ? Array.from(loaderHeaders.entries()) : []),
...(errorHeaders ? Array.from(errorHeaders.entries()) : []),
]);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This existing test section is now testing the v2 behavior so removed headers from the child. See below for specific tests that continue to assert the v1 behavior.

@@ -256,7 +245,6 @@ test.describe("headers export", () => {
expect(JSON.stringify(Array.from(response.headers.entries()))).toBe(
JSON.stringify([
["content-type", "text/html"],
["x-child-loader", "success"],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

No more headers from children in these tests since we're using the parent headers function

Comment on lines +43 to +48
if (routeModule.headers == null && build.future.v2_headers) {
let headers = parentHeaders;
prependCookies(actionHeaders, headers);
prependCookies(loaderHeaders, headers);
return headers;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's no need to prependCookies for parenHeaders since that's what we're returning

docs/route/headers.md Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cookies set in thrown responses are ignored when the CatchBoundary is in a parent route
4 participants