Skip to content

Commit 5744aa5

Browse files
authored
Remove future.v7_throwAbortReason flag (#11728)
1 parent a6299fd commit 5744aa5

File tree

6 files changed

+47
-314
lines changed

6 files changed

+47
-314
lines changed

.changeset/moody-kids-count.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"react-router-dom": major
3+
"react-router": major
4+
---
5+
6+
Remove `future.v7_throwAbortReason` from internalized `@remix-run/router` package

packages/react-router/__tests__/router/navigation-test.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,9 @@ describe("navigations", () => {
171171
expect(t.router.state.loaderData).toEqual({});
172172

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

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

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

packages/react-router/__tests__/router/ssr-test.ts

Lines changed: 25 additions & 167 deletions
Original file line numberDiff line numberDiff line change
@@ -737,9 +737,9 @@ describe("ssr", () => {
737737
} catch (_e) {
738738
e = _e;
739739
}
740-
expect(e).toMatchInlineSnapshot(
741-
`[Error: query() call aborted: GET http://localhost/path?key=value]`
742-
);
740+
expect(e).toBeInstanceOf(DOMException);
741+
expect(e.name).toBe("AbortError");
742+
expect(e.message).toBe("This operation was aborted");
743743
});
744744

745745
it("should handle aborted submit requests", async () => {
@@ -764,92 +764,21 @@ describe("ssr", () => {
764764
} catch (_e) {
765765
e = _e;
766766
}
767-
expect(e).toMatchInlineSnapshot(
768-
`[Error: query() call aborted: POST http://localhost/path?key=value]`
769-
);
770-
});
771-
772-
it("should handle aborted load requests (v7_throwAbortReason=true)", async () => {
773-
let dfd = createDeferred();
774-
let controller = new AbortController();
775-
let { query } = createStaticHandler(
776-
[
777-
{
778-
id: "root",
779-
path: "/path",
780-
loader: () => dfd.promise,
781-
},
782-
],
783-
{ future: { v7_throwAbortReason: true } }
784-
);
785-
let request = createRequest("/path?key=value", {
786-
signal: controller.signal,
787-
});
788-
let e;
789-
try {
790-
let contextPromise = query(request);
791-
controller.abort();
792-
// This should resolve even though we never resolved the loader
793-
await contextPromise;
794-
} catch (_e) {
795-
e = _e;
796-
}
797-
// DOMException added in node 17
798-
if (process.versions.node.split(".").map(Number)[0] >= 17) {
799-
// eslint-disable-next-line jest/no-conditional-expect
800-
expect(e).toBeInstanceOf(DOMException);
801-
}
767+
expect(e).toBeInstanceOf(DOMException);
802768
expect(e.name).toBe("AbortError");
803769
expect(e.message).toBe("This operation was aborted");
804770
});
805771

806-
it("should handle aborted submit requests (v7_throwAbortReason=true)", async () => {
772+
it("should handle aborted requests", async () => {
807773
let dfd = createDeferred();
808774
let controller = new AbortController();
809-
let { query } = createStaticHandler(
810-
[
811-
{
812-
id: "root",
813-
path: "/path",
814-
action: () => dfd.promise,
815-
},
816-
],
817-
{ future: { v7_throwAbortReason: true } }
818-
);
819-
let request = createSubmitRequest("/path?key=value", {
820-
signal: controller.signal,
821-
});
822-
let e;
823-
try {
824-
let contextPromise = query(request);
825-
controller.abort();
826-
// This should resolve even though we never resolved the loader
827-
await contextPromise;
828-
} catch (_e) {
829-
e = _e;
830-
}
831-
// DOMException added in node 17
832-
if (process.versions.node.split(".").map(Number)[0] >= 17) {
833-
// eslint-disable-next-line jest/no-conditional-expect
834-
expect(e).toBeInstanceOf(DOMException);
835-
}
836-
expect(e.name).toBe("AbortError");
837-
expect(e.message).toBe("This operation was aborted");
838-
});
839-
840-
it("should handle aborted requests (v7_throwAbortReason=true + custom reason)", async () => {
841-
let dfd = createDeferred();
842-
let controller = new AbortController();
843-
let { query } = createStaticHandler(
844-
[
845-
{
846-
id: "root",
847-
path: "/path",
848-
loader: () => dfd.promise,
849-
},
850-
],
851-
{ future: { v7_throwAbortReason: true } }
852-
);
775+
let { query } = createStaticHandler([
776+
{
777+
id: "root",
778+
path: "/path",
779+
loader: () => dfd.promise,
780+
},
781+
]);
853782
let request = createRequest("/path?key=value", {
854783
signal: controller.signal,
855784
});
@@ -2234,12 +2163,12 @@ describe("ssr", () => {
22342163
} catch (_e) {
22352164
e = _e;
22362165
}
2237-
expect(e).toMatchInlineSnapshot(
2238-
`[Error: queryRoute() call aborted: GET http://localhost/path?key=value]`
2239-
);
2166+
expect(e).toBeInstanceOf(DOMException);
2167+
expect(e.name).toBe("AbortError");
2168+
expect(e.message).toBe("This operation was aborted");
22402169
});
22412170

2242-
it("should handle aborted submit requests", async () => {
2171+
it("should handle aborted submit requests - custom reason", async () => {
22432172
let dfd = createDeferred();
22442173
let controller = new AbortController();
22452174
let { queryRoute } = createStaticHandler([
@@ -2261,92 +2190,21 @@ describe("ssr", () => {
22612190
} catch (_e) {
22622191
e = _e;
22632192
}
2264-
expect(e).toMatchInlineSnapshot(
2265-
`[Error: queryRoute() call aborted: POST http://localhost/path?key=value]`
2266-
);
2267-
});
2268-
2269-
it("should handle aborted load requests (v7_throwAbortReason=true)", async () => {
2270-
let dfd = createDeferred();
2271-
let controller = new AbortController();
2272-
let { queryRoute } = createStaticHandler(
2273-
[
2274-
{
2275-
id: "root",
2276-
path: "/path",
2277-
loader: () => dfd.promise,
2278-
},
2279-
],
2280-
{ future: { v7_throwAbortReason: true } }
2281-
);
2282-
let request = createRequest("/path?key=value", {
2283-
signal: controller.signal,
2284-
});
2285-
let e;
2286-
try {
2287-
let statePromise = queryRoute(request, { routeId: "root" });
2288-
controller.abort();
2289-
// This should resolve even though we never resolved the loader
2290-
await statePromise;
2291-
} catch (_e) {
2292-
e = _e;
2293-
}
2294-
// DOMException added in node 17
2295-
if (process.versions.node.split(".").map(Number)[0] >= 17) {
2296-
// eslint-disable-next-line jest/no-conditional-expect
2297-
expect(e).toBeInstanceOf(DOMException);
2298-
}
2299-
expect(e.name).toBe("AbortError");
2300-
expect(e.message).toBe("This operation was aborted");
2301-
});
2302-
2303-
it("should handle aborted submit requests (v7_throwAbortReason=true)", async () => {
2304-
let dfd = createDeferred();
2305-
let controller = new AbortController();
2306-
let { queryRoute } = createStaticHandler(
2307-
[
2308-
{
2309-
id: "root",
2310-
path: "/path",
2311-
action: () => dfd.promise,
2312-
},
2313-
],
2314-
{ future: { v7_throwAbortReason: true } }
2315-
);
2316-
let request = createSubmitRequest("/path?key=value", {
2317-
signal: controller.signal,
2318-
});
2319-
let e;
2320-
try {
2321-
let statePromise = queryRoute(request, { routeId: "root" });
2322-
controller.abort();
2323-
// This should resolve even though we never resolved the loader
2324-
await statePromise;
2325-
} catch (_e) {
2326-
e = _e;
2327-
}
2328-
// DOMException added in node 17
2329-
if (process.versions.node.split(".").map(Number)[0] >= 17) {
2330-
// eslint-disable-next-line jest/no-conditional-expect
2331-
expect(e).toBeInstanceOf(DOMException);
2332-
}
2193+
expect(e).toBeInstanceOf(DOMException);
23332194
expect(e.name).toBe("AbortError");
23342195
expect(e.message).toBe("This operation was aborted");
23352196
});
23362197

2337-
it("should handle aborted load requests (v7_throwAbortReason=true + custom reason)", async () => {
2198+
it("should handle aborted load requests - custom reason", async () => {
23382199
let dfd = createDeferred();
23392200
let controller = new AbortController();
2340-
let { queryRoute } = createStaticHandler(
2341-
[
2342-
{
2343-
id: "root",
2344-
path: "/path",
2345-
loader: () => dfd.promise,
2346-
},
2347-
],
2348-
{ future: { v7_throwAbortReason: true } }
2349-
);
2201+
let { queryRoute } = createStaticHandler([
2202+
{
2203+
id: "root",
2204+
path: "/path",
2205+
loader: () => dfd.promise,
2206+
},
2207+
]);
23502208
let request = createRequest("/path?key=value", {
23512209
signal: controller.signal,
23522210
});

0 commit comments

Comments
 (0)