Skip to content
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

fix: preserve method on 307/308 redirects #9597

Merged
merged 8 commits into from
Nov 23, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Merge branch 'dev' into brophdawg11/redirect-307-308
  • Loading branch information
brophdawg11 committed Nov 23, 2022
commit 77cbe518401dc83f7a1aee96300785c1afa9cc63
31 changes: 31 additions & 0 deletions packages/router/__tests__/router-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5570,6 +5570,37 @@ describe("a router", () => {
});
});

it("processes external redirects if window is present", async () => {
let urls = [
"http://remix.run/blog",
"https://remix.run/blog",
"//remix.run/blog",
"app://whatever",
];

for (let url of urls) {
// This is gross, don't blame me, blame SO :)
// https://stackoverflow.com/a/60697570
let oldLocation = window.location;
const location = new URL(window.location.href) as unknown as Location;
location.replace = jest.fn();
delete (window as any).location;
window.location = location as unknown as Location;

let t = setup({ routes: REDIRECT_ROUTES });

let A = await t.navigate("/parent/child", {
formMethod: "post",
formData: createFormData({}),
});

await A.actions.child.redirectReturn(url);
expect(window.location.replace).toHaveBeenCalledWith(url);

window.location = oldLocation;
}
});

describe("redirect status code handling", () => {
it("should not treat 300 as a redirect", async () => {
let t = setup({ routes: REDIRECT_ROUTES });
Expand Down
15 changes: 4 additions & 11 deletions packages/router/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2980,17 +2980,10 @@ function getInternalRouterError(
} else if (status === 405) {
statusText = "Method Not Allowed";
if (method && pathname && routeId) {
if (isSubmissionMethod(method.toLowerCase())) {
errorMessage =
`You made a ${method.toUpperCase()} request to "${pathname}" but ` +
`did not provide an \`action\` for route "${routeId}", ` +
`so there is no way to handle the request.`;
} else {
errorMessage =
`You made a ${method.toUpperCase()} request to "${pathname}" but ` +
`did not provide a \`loader\` for route "${routeId}", ` +
`so there is no way to handle the request.`;
}
errorMessage =
`You made a ${method.toUpperCase()} request to "${pathname}" but ` +
`did not provide an \`action\` for route "${routeId}", ` +
`so there is no way to handle the request.`;
} else if (method) {
errorMessage = `Invalid request method "${method.toUpperCase()}"`;
}
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.