Skip to content

Commit

Permalink
feat(remix-react)!: remove fetcher.type/fetcher.submission (#5716)
Browse files Browse the repository at this point in the history
  • Loading branch information
brophdawg11 authored and MichaelDeBoey committed Jul 9, 2023
1 parent 802a72b commit 561bc4f
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 393 deletions.
8 changes: 8 additions & 0 deletions .changeset/remove-fetcher-back-compat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@remix-run/react": major
---

Remove back-compat layer for `useFetcher`/`useFetchers`. This includes a few small breaking changes:
* `fetcher.type` has been removed since it can be derived from other available information
* "Submission" fields have been flattened from `fetcher.submission` down onto the root `fetcher` object, and prefixed with `form` in some cases (`fetcher.submission.action` => `fetcher.formAction`)
* `<fetcher.Form method="get">` is now more accurately categorized as `state:"loading"` instead of `state:"submitting"` to better align with the underlying GET request
60 changes: 7 additions & 53 deletions integration/fetcher-state-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,10 @@ test.describe("fetcher states", () => {
if (savedStates[savedStates.length - 1]?.state !== fetcher.state) {
savedStates.push({
state: fetcher.state,
type: fetcher.type,
formMethod: fetcher.formMethod,
formAction: fetcher.formAction,
formData:fetcher.formData ? Object.fromEntries(fetcher.formData.entries()) : undefined,
formEncType: fetcher.formEncType,
submission: fetcher.submission ? {
...fetcher.submission,
formData: Object.fromEntries(fetcher.submission.formData.entries()),
key: undefined
}: undefined,
data: fetcher.data,
});
}
Expand Down Expand Up @@ -100,12 +94,11 @@ test.describe("fetcher states", () => {
const fetcher = useFetcher();
return (
<>
{fetcher.type === 'init' ?
{fetcher.state === 'idle' && fetcher.data == null ?
<pre id="initial-state">
{
JSON.stringify({
state: fetcher.state,
type: fetcher.type,
formMethod: fetcher.formMethod,
formAction: fetcher.formAction,
formData: fetcher.formData,
Expand Down Expand Up @@ -163,7 +156,11 @@ test.describe("fetcher states", () => {
let text = (await app.getElement("#initial-state")).text();
expect(JSON.parse(text)).toEqual({
state: "idle",
type: "init",
data: undefined,
formData: undefined,
formAction: undefined,
formMethod: undefined,
formEncType: undefined,
});
});

Expand All @@ -176,38 +173,23 @@ test.describe("fetcher states", () => {
expect(JSON.parse(text)).toEqual([
{
state: "submitting",
type: "actionSubmission",
formData: { key: "value" },
formAction: "/page",
formMethod: "POST",
formEncType: "application/x-www-form-urlencoded",
submission: {
formData: { key: "value" },
action: "/page",
method: "POST",
encType: "application/x-www-form-urlencoded",
},
},
{
state: "loading",
type: "actionReload",
formData: { key: "value" },
formAction: "/page",
formMethod: "POST",
formEncType: "application/x-www-form-urlencoded",
submission: {
formData: { key: "value" },
action: "/page",
method: "POST",
encType: "application/x-www-form-urlencoded",
},
data: {
from: "action",
},
},
{
state: "idle",
type: "done",
data: {
from: "action",
},
Expand All @@ -223,25 +205,14 @@ test.describe("fetcher states", () => {
let text = (await app.getElement("#states")).text();
expect(JSON.parse(text)).toEqual([
{
state: "submitting",
type: "loaderSubmission",
state: "loading",
formData: { key: "value" },
formAction: "/page",
formMethod: "GET",
formEncType: "application/x-www-form-urlencoded",
submission: {
formData: { key: "value" },
// Note: This is a bug in Remix but we're going to keep it that way
// in useTransition (including the back-compat version) and it'll be
// fixed with useNavigation
action: "/page?key=value",
method: "GET",
encType: "application/x-www-form-urlencoded",
},
},
{
state: "idle",
type: "done",
data: {
from: "loader",
},
Expand All @@ -258,35 +229,20 @@ test.describe("fetcher states", () => {
expect(JSON.parse(text)).toEqual([
{
state: "submitting",
type: "actionSubmission",
formData: { redirect: "yes" },
formAction: "/page",
formMethod: "POST",
formEncType: "application/x-www-form-urlencoded",
submission: {
formData: { redirect: "yes" },
action: "/page",
method: "POST",
encType: "application/x-www-form-urlencoded",
},
},
{
state: "loading",
type: "actionRedirect",
formData: { redirect: "yes" },
formAction: "/page",
formMethod: "POST",
formEncType: "application/x-www-form-urlencoded",
submission: {
formData: { redirect: "yes" },
action: "/page",
method: "POST",
encType: "application/x-www-form-urlencoded",
},
},
{
state: "idle",
type: "done",
},
]);
});
Expand All @@ -300,12 +256,10 @@ test.describe("fetcher states", () => {
expect(JSON.parse(text)).toEqual([
{
state: "loading",
type: "normalLoad",
},
{
data: { from: "loader" },
state: "idle",
type: "done",
},
]);
});
Expand Down
Loading

0 comments on commit 561bc4f

Please sign in to comment.