Skip to content

Commit 19af0cf

Browse files
authored
Add future.v7_fetcherPersist flag (#10962)
1 parent cb2d911 commit 19af0cf

File tree

8 files changed

+608
-389
lines changed

8 files changed

+608
-389
lines changed

.changeset/fetcher-cleanup.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
"@remix-run/router": minor
3+
---
4+
5+
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))
6+
7+
- 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
8+
- 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)
9+
- Keep an eye out for the following specific behavioral changes when opting into this flag and check your app for compatibility:
10+
- 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`).
11+
- 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.

.changeset/fix-router-future-prop.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"react-router": patch
3+
"react-router-dom": patch
4+
---
5+
6+
Fix the `future`prop on `BrowserRouter`, `HashRouter` and `MemoryRouter` so that it accepts a `Partial<FutureConfig>` instead of requiring all flags to be included.

docs/guides/api-development-strategy.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ const router = createBrowserRouter(routes, {
6666
| Flag | Description |
6767
| ------------------------ | --------------------------------------------------------------------- |
6868
| `v7_normalizeFormMethod` | Normalize `useNavigation().formMethod` to be an uppercase HTTP Method |
69+
| `v7_fetcherPersist` | Delay active fetcher cleanup until they return to an `idle` state |
6970

7071
### React Router Future Flags
7172

0 commit comments

Comments
 (0)