Skip to content

Commit 3bc35f5

Browse files
authored
Make unstable_useTransitions prop optional on Router component (#14646)
* Make unstable_useTransitions prop optional on Router component * Update context * Let undefined flow through even though behavior is the same
1 parent fc8a862 commit 3bc35f5

File tree

4 files changed

+24
-8
lines changed

4 files changed

+24
-8
lines changed

.changeset/four-sloths-notice.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"react-router": patch
3+
---
4+
5+
Fix `unstable_useTransitions` prop on `<Router>` component to permit omission for backewards compatibility

packages/react-router/lib/components.tsx

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,7 @@ export function RouterProvider({
740740
location={state.location}
741741
navigationType={state.historyAction}
742742
navigator={navigator}
743-
unstable_useTransitions={unstable_useTransitions === true}
743+
unstable_useTransitions={unstable_useTransitions}
744744
>
745745
<MemoizedDataRoutes
746746
routes={router.routes}
@@ -895,7 +895,7 @@ export function MemoryRouter({
895895
location={state.location}
896896
navigationType={state.action}
897897
navigator={history}
898-
unstable_useTransitions={unstable_useTransitions === true}
898+
unstable_useTransitions={unstable_useTransitions}
899899
/>
900900
);
901901
}
@@ -1310,9 +1310,20 @@ export interface RouterProps {
13101310
*/
13111311
static?: boolean;
13121312
/**
1313-
* Whether this router should wrap navigations in `React.startTransition()`
1313+
* Control whether router state updates are internally wrapped in
1314+
* [`React.startTransition`](https://react.dev/reference/react/startTransition).
1315+
*
1316+
* - When left `undefined`, all router state updates are wrapped in
1317+
* `React.startTransition`
1318+
* - When set to `true`, {@link Link} and {@link Form} navigations will be wrapped
1319+
* in `React.startTransition` and all router state updates are wrapped in
1320+
* `React.startTransition`
1321+
* - When set to `false`, the router will not leverage `React.startTransition`
1322+
* on any navigations or state changes.
1323+
*
1324+
* For more information, please see the [docs](https://reactrouter.com/explanation/react-transitions).
13141325
*/
1315-
unstable_useTransitions: boolean;
1326+
unstable_useTransitions?: boolean;
13161327
}
13171328

13181329
/**

packages/react-router/lib/context.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ interface NavigationContextObject {
179179
basename: string;
180180
navigator: Navigator;
181181
static: boolean;
182-
unstable_useTransitions: boolean;
182+
unstable_useTransitions: boolean | undefined;
183183
// TODO: Re-introduce a singular `FutureConfig` once we land our first
184184
// future.unstable_ or future.v8_ flag
185185
future: {};

packages/react-router/lib/dom/lib.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -849,7 +849,7 @@ export function BrowserRouter({
849849
location={state.location}
850850
navigationType={state.action}
851851
navigator={history}
852-
unstable_useTransitions={unstable_useTransitions === true}
852+
unstable_useTransitions={unstable_useTransitions}
853853
/>
854854
);
855855
}
@@ -940,7 +940,7 @@ export function HashRouter({
940940
location={state.location}
941941
navigationType={state.action}
942942
navigator={history}
943-
unstable_useTransitions={unstable_useTransitions === true}
943+
unstable_useTransitions={unstable_useTransitions}
944944
/>
945945
);
946946
}
@@ -1027,7 +1027,7 @@ export function HistoryRouter({
10271027
location={state.location}
10281028
navigationType={state.action}
10291029
navigator={history}
1030-
unstable_useTransitions={unstable_useTransitions === true}
1030+
unstable_useTransitions={unstable_useTransitions}
10311031
/>
10321032
);
10331033
}

0 commit comments

Comments
 (0)