File tree Expand file tree Collapse file tree 3 files changed +16
-3
lines changed
packages/react-router-dom Expand file tree Collapse file tree 3 files changed +16
-3
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ " react-router-dom " : patch
3
+ ---
4
+
5
+ Leverage ` useId ` for internal fetcher keys when available
Original file line number Diff line number Diff line change @@ -5368,9 +5368,11 @@ function testDomRouter(
5368
5368
{ window : getWindow ( "/" ) }
5369
5369
) ;
5370
5370
let { container } = render ( < RouterProvider router = { router } /> ) ;
5371
- expect ( container . innerHTML ) . not . toMatch ( / _ _ \d + _ _ , m y - k e y / ) ;
5371
+ expect ( container . innerHTML ) . not . toMatch ( / m y - k e y / ) ;
5372
5372
await waitFor ( ( ) =>
5373
- expect ( container . innerHTML ) . toMatch ( / _ _ \d + _ _ , m y - k e y / )
5373
+ // React `useId()` results in either `:r2a:` or `:rp:` depending on
5374
+ // `DataBrowserRouter`/`DataHashRouter`
5375
+ expect ( container . innerHTML ) . toMatch ( / ( : r 2 a : | : r p : ) , m y - k e y / )
5374
5376
) ;
5375
5377
} ) ;
5376
5378
} ) ;
Original file line number Diff line number Diff line change @@ -396,6 +396,8 @@ const START_TRANSITION = "startTransition";
396
396
const startTransitionImpl = React [ START_TRANSITION ] ;
397
397
const FLUSH_SYNC = "flushSync" ;
398
398
const flushSyncImpl = ReactDOM [ FLUSH_SYNC ] ;
399
+ const USE_ID = "useId" ;
400
+ const useIdImpl = React [ USE_ID ] ;
399
401
400
402
function startTransitionSafe ( cb : ( ) => void ) {
401
403
if ( startTransitionImpl ) {
@@ -1634,10 +1636,14 @@ export function useFetcher<TData = any>({
1634
1636
) ;
1635
1637
1636
1638
// Fetcher key handling
1637
- let [ fetcherKey , setFetcherKey ] = React . useState < string > ( key || "" ) ;
1639
+ // OK to call conditionally to feature detect `useId`
1640
+ // eslint-disable-next-line react-hooks/rules-of-hooks
1641
+ let defaultKey = useIdImpl ? useIdImpl ( ) : "" ;
1642
+ let [ fetcherKey , setFetcherKey ] = React . useState < string > ( key || defaultKey ) ;
1638
1643
if ( key && key !== fetcherKey ) {
1639
1644
setFetcherKey ( key ) ;
1640
1645
} else if ( ! fetcherKey ) {
1646
+ // We will only fall through here when `useId` is not available
1641
1647
setFetcherKey ( getUniqueFetcherId ( ) ) ;
1642
1648
}
1643
1649
You can’t perform that action at this time.
0 commit comments