-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
Patch patch cause the spec is weird #10216
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@remix-run/router": patch | ||
| --- | ||
|
|
||
| Update to latest `@remix-run/[email protected]` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -624,7 +624,7 @@ function setup({ | |
| // Otherwise we should only need a loader for the leaf match | ||
| let activeLoaderMatches = [match]; | ||
| // @ts-expect-error | ||
| if (opts?.formMethod === "post") { | ||
| if (opts?.formMethod != null && opts.formMethod.toLowerCase() !== "get") { | ||
| if (currentRouter.state.navigation?.location) { | ||
| let matches = matchRoutes( | ||
| inFlightRoutes || currentRouter.routes, | ||
|
|
@@ -689,7 +689,7 @@ function setup({ | |
| invariant(currentRouter, "No currentRouter available"); | ||
|
|
||
| // @ts-expect-error | ||
| if (opts?.formMethod === "post") { | ||
| if (opts?.formMethod != null && opts.formMethod.toLowerCase() !== "get") { | ||
| activeActionType = "navigation"; | ||
| activeActionNavigationId = navigationId; | ||
| // Assume happy path and mark this navigations loaders as active. Even if | ||
|
|
@@ -779,7 +779,7 @@ function setup({ | |
| invariant(currentRouter, "No currentRouter available"); | ||
|
|
||
| // @ts-expect-error | ||
| if (opts?.formMethod === "post") { | ||
| if (opts?.formMethod != null && opts.formMethod.toLowerCase() !== "get") { | ||
| activeActionType = "fetch"; | ||
| activeActionFetchId = navigationId; | ||
| } else { | ||
|
|
@@ -867,10 +867,7 @@ function initializeTmTest(init?: { | |
| } | ||
|
|
||
| function createRequest(path: string, opts?: RequestInit) { | ||
| return new Request(`http://localhost${path}`, { | ||
| signal: new AbortController().signal, | ||
| ...opts, | ||
| }); | ||
| return new Request(`http://localhost${path}`, opts); | ||
| } | ||
|
|
||
| function createSubmitRequest(path: string, opts?: RequestInit) { | ||
|
|
@@ -5899,6 +5896,47 @@ describe("a router", () => { | |
| expect((await request.formData()).get("query")).toBe("params"); | ||
| }); | ||
|
|
||
| // https://fetch.spec.whatwg.org/#concept-method | ||
| it("properly handles method=PATCH weirdness", async () => { | ||
| let t = setup({ | ||
| routes: TASK_ROUTES, | ||
| initialEntries: ["/"], | ||
| hydrationData: { | ||
| loaderData: { | ||
| root: "ROOT_DATA", | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| let nav = await t.navigate("/tasks", { | ||
| formMethod: "patch", | ||
| formData: createFormData({ query: "params" }), | ||
| }); | ||
| expect(nav.actions.tasks.stub).toHaveBeenCalledWith({ | ||
| params: {}, | ||
| request: expect.any(Request), | ||
| }); | ||
|
|
||
| // Assert request internals, cannot do a deep comparison above since some | ||
| // internals aren't the same on separate creations | ||
| let request = nav.actions.tasks.stub.mock.calls[0][0].request; | ||
| expect(request.method).toBe("PATCH"); | ||
| expect(request.url).toBe("http://localhost/tasks"); | ||
| expect(request.headers.get("Content-Type")).toBe( | ||
| "application/x-www-form-urlencoded;charset=UTF-8" | ||
| ); | ||
| expect((await request.formData()).get("query")).toBe("params"); | ||
|
|
||
| await nav.actions.tasks.resolve("TASKS ACTION"); | ||
| let rootLoaderRequest = nav.loaders.root.stub.mock.calls[0][0].request; | ||
| expect(rootLoaderRequest.method).toBe("GET"); | ||
| expect(rootLoaderRequest.url).toBe("http://localhost/tasks"); | ||
|
|
||
| let tasksLoaderRequest = nav.loaders.tasks.stub.mock.calls[0][0].request; | ||
| expect(tasksLoaderRequest.method).toBe("GET"); | ||
| expect(tasksLoaderRequest.url).toBe("http://localhost/tasks"); | ||
| }); | ||
|
|
||
| it("handles multipart/form-data submissions", async () => { | ||
| let t = setup({ | ||
| routes: [ | ||
|
|
@@ -13437,17 +13475,12 @@ describe("a router", () => { | |
| expect(e).toMatchInlineSnapshot(`[Error: query() call aborted]`); | ||
| }); | ||
|
|
||
| it("should require a signal on the request", async () => { | ||
| it("should assign signals to requests by default (per the", async () => { | ||
| let { query } = createStaticHandler(SSR_ROUTES); | ||
| let request = createRequest("/", { signal: undefined }); | ||
| let e; | ||
| try { | ||
| await query(request); | ||
| } catch (_e) { | ||
| e = _e; | ||
| } | ||
| expect(e).toMatchInlineSnapshot( | ||
| `[Error: query()/queryRoute() requests must contain an AbortController signal]` | ||
| let context = await query(request); | ||
| expect((context as StaticHandlerContext).loaderData.index).toBe( | ||
| "INDEX LOADER" | ||
| ); | ||
| }); | ||
|
|
||
|
|
@@ -14673,18 +14706,11 @@ describe("a router", () => { | |
| expect(e).toMatchInlineSnapshot(`[Error: queryRoute() call aborted]`); | ||
| }); | ||
|
|
||
| it("should require a signal on the request", async () => { | ||
| it("should assign signals to requests by default (per the spec)", async () => { | ||
| let { queryRoute } = createStaticHandler(SSR_ROUTES); | ||
| let request = createRequest("/", { signal: undefined }); | ||
| let e; | ||
| try { | ||
| await queryRoute(request, { routeId: "index" }); | ||
| } catch (_e) { | ||
| e = _e; | ||
| } | ||
| expect(e).toMatchInlineSnapshot( | ||
| `[Error: query()/queryRoute() requests must contain an AbortController signal]` | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We've since fixed our |
||
| ); | ||
| let data = await queryRoute(request, { routeId: "index" }); | ||
| expect(data).toBe("INDEX LOADER"); | ||
| }); | ||
|
|
||
| it("should support a requestContext passed to loaders and actions", async () => { | ||
|
|
@@ -14890,15 +14916,15 @@ describe("a router", () => { | |
|
|
||
| it("should handle unsupported methods with a 405 Response", async () => { | ||
| try { | ||
| await queryRoute(createRequest("/", { method: "TRACE" }), { | ||
| await queryRoute(createRequest("/", { method: "CHICKEN" }), { | ||
| routeId: "root", | ||
| }); | ||
| expect(false).toBe(true); | ||
| } catch (data) { | ||
| expect(isRouteErrorResponse(data)).toBe(true); | ||
| expect(data.status).toBe(405); | ||
| expect(data.error).toEqual( | ||
| new Error('Invalid request method "TRACE"') | ||
| new Error('Invalid request method "CHICKEN"') | ||
| ); | ||
| expect(data.internal).toBe(true); | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test doesn't fail (without the code fix) at the moment - I think our fetch polyfill is probably uppercasing all methods, so we should update that to force this test to be able to fail
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remix-run/web-std-io#30