Skip to content

Commit

Permalink
ref(rr6): Shim browserHistory.listen (#76696)
Browse files Browse the repository at this point in the history
Figured out the correct way to do this. We still have just a few places
left that we're doing this and will need the shim
  • Loading branch information
evanpurkhiser authored Aug 28, 2024
1 parent 0338abf commit 7202754
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions static/app/utils/browserHistory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import {browserHistory as react3BrowserHistory} from 'react-router';
import type {Router} from '@remix-run/router/dist/router';
import type {History} from 'history';

import {locationDescriptorToTo} from './reactRouter6Compat/location';
import {
location6ToLocation3,
locationDescriptorToTo,
} from './reactRouter6Compat/location';

/**
* @deprecated Prefer using useNavigate
Expand Down Expand Up @@ -35,14 +38,8 @@ export function DANGEROUS_SET_REACT_ROUTER_6_HISTORY(router: Router) {
goBack: () => router.navigate(-1),
goForward: () => router.navigate(1),

// XXX(epurkhiser): react-router 6's BrowserHistory does not let you create
// multiple listeners. This implementation is similar but allows multiple
// listeners.
listen: _listener => {
// eslint-disable-next-line no-console
console.error('browserHistory.listen not implemented on react-router 6 shim');
return () => {};
},
listen: listener =>
router.subscribe(state => listener(location6ToLocation3(state.location))),

listenBefore: _hook => {
// eslint-disable-next-line no-console
Expand Down

0 comments on commit 7202754

Please sign in to comment.