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

Remove fetcher.type/fetcher.submission #5716

Merged
merged 4 commits into from
Mar 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
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
Comment on lines +5 to +8
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are technically breaking since they happened in the same API and there's no flag that applied these changes. Is this something small enough we can call it out in the release notes? Or would it be worth a quick v2_fetcher flag to add this behavior into v1?

We did not have this issue on useTransition/useNavigation because it was a new hook introducing the changed behavior.

60 changes: 7 additions & 53 deletions integration/fetcher-state-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,10 @@ test.describe("fetcher states", () => {
const savedStates = fetcherRef.current || [];
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,
});
fetcherRef.current = savedStates;
Expand Down Expand Up @@ -86,12 +80,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 @@ -150,7 +143,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 @@ -163,38 +160,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 @@ -210,25 +192,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 @@ -245,35 +216,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 @@ -287,12 +243,10 @@ test.describe("fetcher states", () => {
expect(JSON.parse(text)).toEqual([
{
state: "loading",
type: "normalLoad",
},
{
data: { from: "loader" },
state: "idle",
type: "done",
},
]);
});
Expand Down
Loading