Skip to content

Commit

Permalink
Remove future.v7_throwAbortReason flag (#11728)
Browse files Browse the repository at this point in the history
  • Loading branch information
brophdawg11 authored Jun 25, 2024
1 parent a6299fd commit 5744aa5
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 314 deletions.
6 changes: 6 additions & 0 deletions .changeset/moody-kids-count.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"react-router-dom": major
"react-router": major
---

Remove `future.v7_throwAbortReason` from internalized `@remix-run/router` package
14 changes: 6 additions & 8 deletions packages/react-router/__tests__/router/navigation-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,9 @@ describe("navigations", () => {
expect(t.router.state.loaderData).toEqual({});

// Node 16/18 versus 20 output different errors here :/
let expected =
process.version.startsWith("v16") || process.version.startsWith("v18")
? "Unexpected token } in JSON at position 15"
: "Unexpected non-whitespace character after JSON at position 15";
let expected = process.version.startsWith("v18")
? "Unexpected token } in JSON at position 15"
: "Unexpected non-whitespace character after JSON at position 15";
expect(t.router.state.errors?.foo).toEqual(new SyntaxError(expected));
});

Expand Down Expand Up @@ -208,10 +207,9 @@ describe("navigations", () => {
expect(t.router.state.loaderData).toEqual({});

// Node 16/18 versus 20 output different errors here :/
let expected =
process.version.startsWith("v16") || process.version.startsWith("v18")
? "Unexpected token } in JSON at position 15"
: "Unexpected non-whitespace character after JSON at position 15";
let expected = process.version.startsWith("v18")
? "Unexpected token } in JSON at position 15"
: "Unexpected non-whitespace character after JSON at position 15";
expect(t.router.state.errors?.root).toEqual(new SyntaxError(expected));
});

Expand Down
192 changes: 25 additions & 167 deletions packages/react-router/__tests__/router/ssr-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -737,9 +737,9 @@ describe("ssr", () => {
} catch (_e) {
e = _e;
}
expect(e).toMatchInlineSnapshot(
`[Error: query() call aborted: GET http://localhost/path?key=value]`
);
expect(e).toBeInstanceOf(DOMException);
expect(e.name).toBe("AbortError");
expect(e.message).toBe("This operation was aborted");
});

it("should handle aborted submit requests", async () => {
Expand All @@ -764,92 +764,21 @@ describe("ssr", () => {
} catch (_e) {
e = _e;
}
expect(e).toMatchInlineSnapshot(
`[Error: query() call aborted: POST http://localhost/path?key=value]`
);
});

it("should handle aborted load requests (v7_throwAbortReason=true)", async () => {
let dfd = createDeferred();
let controller = new AbortController();
let { query } = createStaticHandler(
[
{
id: "root",
path: "/path",
loader: () => dfd.promise,
},
],
{ future: { v7_throwAbortReason: true } }
);
let request = createRequest("/path?key=value", {
signal: controller.signal,
});
let e;
try {
let contextPromise = query(request);
controller.abort();
// This should resolve even though we never resolved the loader
await contextPromise;
} catch (_e) {
e = _e;
}
// DOMException added in node 17
if (process.versions.node.split(".").map(Number)[0] >= 17) {
// eslint-disable-next-line jest/no-conditional-expect
expect(e).toBeInstanceOf(DOMException);
}
expect(e).toBeInstanceOf(DOMException);
expect(e.name).toBe("AbortError");
expect(e.message).toBe("This operation was aborted");
});

it("should handle aborted submit requests (v7_throwAbortReason=true)", async () => {
it("should handle aborted requests", async () => {
let dfd = createDeferred();
let controller = new AbortController();
let { query } = createStaticHandler(
[
{
id: "root",
path: "/path",
action: () => dfd.promise,
},
],
{ future: { v7_throwAbortReason: true } }
);
let request = createSubmitRequest("/path?key=value", {
signal: controller.signal,
});
let e;
try {
let contextPromise = query(request);
controller.abort();
// This should resolve even though we never resolved the loader
await contextPromise;
} catch (_e) {
e = _e;
}
// DOMException added in node 17
if (process.versions.node.split(".").map(Number)[0] >= 17) {
// eslint-disable-next-line jest/no-conditional-expect
expect(e).toBeInstanceOf(DOMException);
}
expect(e.name).toBe("AbortError");
expect(e.message).toBe("This operation was aborted");
});

it("should handle aborted requests (v7_throwAbortReason=true + custom reason)", async () => {
let dfd = createDeferred();
let controller = new AbortController();
let { query } = createStaticHandler(
[
{
id: "root",
path: "/path",
loader: () => dfd.promise,
},
],
{ future: { v7_throwAbortReason: true } }
);
let { query } = createStaticHandler([
{
id: "root",
path: "/path",
loader: () => dfd.promise,
},
]);
let request = createRequest("/path?key=value", {
signal: controller.signal,
});
Expand Down Expand Up @@ -2234,12 +2163,12 @@ describe("ssr", () => {
} catch (_e) {
e = _e;
}
expect(e).toMatchInlineSnapshot(
`[Error: queryRoute() call aborted: GET http://localhost/path?key=value]`
);
expect(e).toBeInstanceOf(DOMException);
expect(e.name).toBe("AbortError");
expect(e.message).toBe("This operation was aborted");
});

it("should handle aborted submit requests", async () => {
it("should handle aborted submit requests - custom reason", async () => {
let dfd = createDeferred();
let controller = new AbortController();
let { queryRoute } = createStaticHandler([
Expand All @@ -2261,92 +2190,21 @@ describe("ssr", () => {
} catch (_e) {
e = _e;
}
expect(e).toMatchInlineSnapshot(
`[Error: queryRoute() call aborted: POST http://localhost/path?key=value]`
);
});

it("should handle aborted load requests (v7_throwAbortReason=true)", async () => {
let dfd = createDeferred();
let controller = new AbortController();
let { queryRoute } = createStaticHandler(
[
{
id: "root",
path: "/path",
loader: () => dfd.promise,
},
],
{ future: { v7_throwAbortReason: true } }
);
let request = createRequest("/path?key=value", {
signal: controller.signal,
});
let e;
try {
let statePromise = queryRoute(request, { routeId: "root" });
controller.abort();
// This should resolve even though we never resolved the loader
await statePromise;
} catch (_e) {
e = _e;
}
// DOMException added in node 17
if (process.versions.node.split(".").map(Number)[0] >= 17) {
// eslint-disable-next-line jest/no-conditional-expect
expect(e).toBeInstanceOf(DOMException);
}
expect(e.name).toBe("AbortError");
expect(e.message).toBe("This operation was aborted");
});

it("should handle aborted submit requests (v7_throwAbortReason=true)", async () => {
let dfd = createDeferred();
let controller = new AbortController();
let { queryRoute } = createStaticHandler(
[
{
id: "root",
path: "/path",
action: () => dfd.promise,
},
],
{ future: { v7_throwAbortReason: true } }
);
let request = createSubmitRequest("/path?key=value", {
signal: controller.signal,
});
let e;
try {
let statePromise = queryRoute(request, { routeId: "root" });
controller.abort();
// This should resolve even though we never resolved the loader
await statePromise;
} catch (_e) {
e = _e;
}
// DOMException added in node 17
if (process.versions.node.split(".").map(Number)[0] >= 17) {
// eslint-disable-next-line jest/no-conditional-expect
expect(e).toBeInstanceOf(DOMException);
}
expect(e).toBeInstanceOf(DOMException);
expect(e.name).toBe("AbortError");
expect(e.message).toBe("This operation was aborted");
});

it("should handle aborted load requests (v7_throwAbortReason=true + custom reason)", async () => {
it("should handle aborted load requests - custom reason", async () => {
let dfd = createDeferred();
let controller = new AbortController();
let { queryRoute } = createStaticHandler(
[
{
id: "root",
path: "/path",
loader: () => dfd.promise,
},
],
{ future: { v7_throwAbortReason: true } }
);
let { queryRoute } = createStaticHandler([
{
id: "root",
path: "/path",
loader: () => dfd.promise,
},
]);
let request = createRequest("/path?key=value", {
signal: controller.signal,
});
Expand Down
Loading

0 comments on commit 5744aa5

Please sign in to comment.