Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/unlucky-planets-repeat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@remix-run/router": patch
---

Do not attempt to deserialize empty JSON responses
18 changes: 18 additions & 0 deletions packages/router/__tests__/navigation-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,24 @@ describe("navigations", () => {
});
});

// See: https://github.com/remix-run/react-router/issues/11145
it("does not attempt to deserialize empty json responses", async () => {
let t = initializeTest();
let A = await t.navigate("/foo");
await A.loaders.foo.resolve(
new Response(null, {
headers: {
"Content-Type": "application/json",
},
})
);
expect(t.router.state.errors).toBeNull();
expect(t.router.state.loaderData).toMatchObject({
root: "ROOT",
foo: null,
});
});

it("unwraps non-redirect text Responses", async () => {
let t = initializeTest();
let A = await t.navigate("/foo");
Expand Down
6 changes: 5 additions & 1 deletion packages/router/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4098,7 +4098,11 @@ async function callLoaderOrAction(
// Check between word boundaries instead of startsWith() due to the last
// paragraph of https://httpwg.org/specs/rfc9110.html#field.content-type
if (contentType && /\bapplication\/json\b/.test(contentType)) {
data = await result.json();
if (result.body == null) {
data = null;
} else {
data = await result.json();
}
} else {
data = await result.text();
}
Expand Down