Skip to content

Commit

Permalink
Add future.v7_fetcherPersist flag (#10962)
Browse files Browse the repository at this point in the history
  • Loading branch information
brophdawg11 authored Oct 26, 2023
1 parent cb2d911 commit 19af0cf
Show file tree
Hide file tree
Showing 8 changed files with 608 additions and 389 deletions.
11 changes: 11 additions & 0 deletions .changeset/fetcher-cleanup.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
"@remix-run/router": minor
---

Add a new `future.v7_fetcherPersist` flag to the `@remix-run/router` to change the persistence behavior of fetchers when `router.deleteFetcher` is called. Instead of being immediately cleaned up, fetchers will persist until they return to an `idle` state([RFC](https://github.com/remix-run/remix/discussions/7698))

- This is sort of a long-standing bug fix as the `useFetchers()` API was always supposed to only reflect **in-flight** fetcher information for pending/optimistic UI -- it was not intended to reflect fetcher data or hang onto fetchers after they returned to an `idle` state
- With `v7_fetcherPersist`, the `router` only knows about in-flight fetchers - they do not exist in `state.fetchers` until a `fetch()` call is made, and they are removed as soon as it returns to `idle` (and the data is handed off to the React layer)
- Keep an eye out for the following specific behavioral changes when opting into this flag and check your app for compatibility:
- Fetchers that complete _while still mounted_ will no longer appear in `useFetchers()`. They served effectively no purpose in there since you can access the data via `useFetcher().data`).
- Fetchers that previously unmounted _while in-flight_ will not be immediately aborted and will instead be cleaned up once they return to an `idle` state. They will remain exposed via `useFetchers` while in-flight so you can still access pending/optimistic data after unmount.
6 changes: 6 additions & 0 deletions .changeset/fix-router-future-prop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"react-router": patch
"react-router-dom": patch
---

Fix the `future`prop on `BrowserRouter`, `HashRouter` and `MemoryRouter` so that it accepts a `Partial<FutureConfig>` instead of requiring all flags to be included.
1 change: 1 addition & 0 deletions docs/guides/api-development-strategy.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ const router = createBrowserRouter(routes, {
| Flag | Description |
| ------------------------ | --------------------------------------------------------------------- |
| `v7_normalizeFormMethod` | Normalize `useNavigation().formMethod` to be an uppercase HTTP Method |
| `v7_fetcherPersist` | Delay active fetcher cleanup until they return to an `idle` state |

### React Router Future Flags

Expand Down
Loading

0 comments on commit 19af0cf

Please sign in to comment.