Repository: remix-run/react-router
File: packages/router/__tests__/ssr-test.ts (TypeScript)

Code before:
          {
            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);
        // Note this works in Node 18+ - but it does not work if using the
        // `abort-controller` polyfill which doesn't yet support a custom `reason`
        // See: https://github.com/mysticatea/abort-controller/issues/33
        controller.abort(new Error("Oh no!"));
        // This should resolve even though we never resolved the loader
        await contextPromise;
      } catch (_e) {
        e = _e;
      }
      expect(e).toBeInstanceOf(Error);
      expect(e.message).toBe("Oh no!");
    });

    it("should assign signals to requests by default (per the", async () => {
      let { query } = createStaticHandler(SSR_ROUTES);
      let request = createRequest("/", { signal: undefined });
      let context = await query(request);
      expect((context as StaticHandlerContext).loaderData.index).toBe(
        "INDEX LOADER"
      );
    });

    it("should handle not found action submissions with a 405 error", async () => {
      let { query } = createStaticHandler([
        {
          id: "root",
          path: "/",
        },
      ]);
      let request = createSubmitRequest("/");
      let context = await query(request);
      expect(context).toMatchObject({
        actionData: null,
        loaderData: {},
        errors: {
          root: new ErrorResponseImpl(
            405,

Review comment (suggestion):
Worth calling out - this could be an issue in Remix apps that still use the polyfills if we wanted to use a custom `reason`

Code after:
      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 request = createRequest("/path?key=value", {
        signal: controller.signal,
      });
      let e;
      try {
        let contextPromise = query(request);
        // Note this works in Node 18+ - but it does not work if using the
        // `abort-controller` polyfill which doesn't yet support a custom `reason`
        // See: https://github.com/mysticatea/abort-controller/issues/33
        controller.abort(new Error("Oh no!"));
        // This should resolve even though we never resolved the loader
        await contextPromise;
      } catch (_e) {
        e = _e;
      }
      expect(e).toBeInstanceOf(Error);
      expect(e.message).toBe("Oh no!");
    });

    it("should assign signals to requests by default (per the", async () => {
      let { query } = createStaticHandler(SSR_ROUTES);
      let request = createRequest("/", { signal: undefined });
      let context = await query(request);
      expect((context as StaticHandlerContext).loaderData.index).toBe(
        "INDEX LOADER"
      );
    });

    it("should handle not found action submissions with a 405 error", async () => {
      let { query } = createStaticHandler([
        {
          id: "root",
          path: "/",
        },
      ]);