Skip to content

Commit

Permalink
Proposal: v2_headers flag to inherit parentHeaders
Browse files Browse the repository at this point in the history
I've found it very surprising and have been bitten a few times that a parent route's headers are not automatically used by a child route when that child route does not export its own `headers`. This proposes doing just that for v2 since this would be a breaking change.
  • Loading branch information
appden committed May 2, 2023
1 parent 0e2763f commit 38136de
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 1 deletion.
2 changes: 2 additions & 0 deletions packages/remix-dev/__tests__/readConfig-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ describe("readConfig", () => {
unstable_postcss: expect.any(Boolean),
unstable_tailwind: expect.any(Boolean),
v2_errorBoundary: expect.any(Boolean),
v2_headers: expect.any(Boolean),
v2_meta: expect.any(Boolean),
v2_normalizeFormMethod: expect.any(Boolean),
v2_routeConvention: expect.any(Boolean),
Expand All @@ -55,6 +56,7 @@ describe("readConfig", () => {
"unstable_postcss": Any<Boolean>,
"unstable_tailwind": Any<Boolean>,
"v2_errorBoundary": Any<Boolean>,
"v2_headers": Any<Boolean>,
"v2_meta": Any<Boolean>,
"v2_normalizeFormMethod": Any<Boolean>,
"v2_routeConvention": Any<Boolean>,
Expand Down
2 changes: 2 additions & 0 deletions packages/remix-dev/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ interface FutureConfig {
/** @deprecated Use the `tailwind` config option instead */
unstable_tailwind: boolean;
v2_errorBoundary: boolean;
v2_headers: boolean;
v2_meta: boolean;
v2_normalizeFormMethod: boolean;
v2_routeConvention: boolean;
Expand Down Expand Up @@ -738,6 +739,7 @@ export async function readConfig(
unstable_postcss: appConfig.future?.unstable_postcss === true,
unstable_tailwind: appConfig.future?.unstable_tailwind === true,
v2_errorBoundary: appConfig.future?.v2_errorBoundary === true,
v2_headers: appConfig.future?.v2_headers === true,
v2_meta: appConfig.future?.v2_meta === true,
v2_normalizeFormMethod: appConfig.future?.v2_normalizeFormMethod === true,
v2_routeConvention: appConfig.future?.v2_routeConvention === true,
Expand Down
1 change: 1 addition & 0 deletions packages/remix-react/entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export interface FutureConfig {
/** @deprecated Use the `tailwind` config option instead */
unstable_tailwind: boolean;
v2_errorBoundary: boolean;
v2_headers: boolean;
v2_meta: boolean;
v2_normalizeFormMethod: boolean;
v2_routeConvention: boolean;
Expand Down
1 change: 1 addition & 0 deletions packages/remix-server-runtime/entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export interface FutureConfig {
/** @deprecated Use the `tailwind` config option instead */
unstable_tailwind: boolean;
v2_errorBoundary: boolean;
v2_headers: boolean;
v2_meta: boolean;
v2_normalizeFormMethod: boolean;
v2_routeConvention: boolean;
Expand Down
7 changes: 6 additions & 1 deletion packages/remix-server-runtime/headers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export function getDocumentHeadersRR(
? typeof routeModule.headers === "function"
? routeModule.headers({ loaderHeaders, parentHeaders, actionHeaders })
: routeModule.headers
: build.future.v2_headers
? parentHeaders
: undefined
);

Expand All @@ -40,7 +42,10 @@ export function getDocumentHeadersRR(
function prependCookies(parentHeaders: Headers, childHeaders: Headers): void {
let parentSetCookieString = parentHeaders.get("Set-Cookie");

if (parentSetCookieString) {
if (
parentSetCookieString &&
parentSetCookieString !== childHeaders.get("Set-Cookie")
) {
let cookies = splitCookiesString(parentSetCookieString);
cookies.forEach((cookie) => {
childHeaders.append("Set-Cookie", cookie);
Expand Down
1 change: 1 addition & 0 deletions packages/remix-testing/create-remix-stub.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ export function createRemixStub(
unstable_postcss: false,
unstable_tailwind: false,
v2_errorBoundary: false,
v2_headers: false,
v2_meta: false,
v2_normalizeFormMethod: false,
v2_routeConvention: false,
Expand Down

0 comments on commit 38136de

Please sign in to comment.