From 5cfcc9a5f965c372fe0f7a450fd55cdbeb3213be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mika=C3=ABl=20ANZANO?= Date: Thu, 9 Feb 2023 11:21:22 +0100 Subject: [PATCH] fix(defer): respect headers and status --- .changeset/nasty-carrots-breathe.md | 5 +++++ packages/router/__tests__/router-test.ts | 4 ++++ packages/router/router.ts | 7 ++++++- 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 .changeset/nasty-carrots-breathe.md diff --git a/.changeset/nasty-carrots-breathe.md b/.changeset/nasty-carrots-breathe.md new file mode 100644 index 0000000000..0c06ef5738 --- /dev/null +++ b/.changeset/nasty-carrots-breathe.md @@ -0,0 +1,5 @@ +--- +"@remix-run/router": minor +--- + +Remix document response now respects headers and status code set in defer() diff --git a/packages/router/__tests__/router-test.ts b/packages/router/__tests__/router-test.ts index e9b19cfc88..e33d126135 100644 --- a/packages/router/__tests__/router-test.ts +++ b/packages/router/__tests__/router-test.ts @@ -12350,6 +12350,10 @@ describe("a router", () => { "x-custom": "yes", }), }, + statusCode: 201, + loaderHeaders: { + deferred: new Headers({ "x-custom": "yes" }), + } }); }); diff --git a/packages/router/router.ts b/packages/router/router.ts index 874be611d6..17fc05f191 100644 --- a/packages/router/router.ts +++ b/packages/router/router.ts @@ -3183,7 +3183,12 @@ async function callLoaderOrAction( } if (result instanceof DeferredData) { - return { type: ResultType.deferred, deferredData: result }; + return { + type: ResultType.deferred, + deferredData: result, + statusCode: result.init?.status, + headers: result.init?.headers && new Headers(result.init.headers), + }; } return { type: ResultType.data, data: result };