Skip to content

Commit a0b341a

Browse files
authored
Merge pull request #1051 from alexstotsky/migrate-to-redux-first-history
(internal) Migration from connected-react-router to redux-first-history
2 parents 163a01a + 15c4b04 commit a0b341a

8 files changed

Lines changed: 65 additions & 71 deletions

File tree

package-lock.json

Lines changed: 29 additions & 49 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
"axios": "^1.8.4",
2727
"bignumber.js": "^9.3.1",
2828
"classnames": "2.5.1",
29-
"connected-react-router": "6.9.3",
3029
"flexboxgrid2": "7.2.1",
3130
"history": "^4.9.0",
3231
"i18next": "15.0.7",
@@ -41,15 +40,16 @@
4140
"normalize.css": "8.0.1",
4241
"prop-types": "^15.7.2",
4342
"query-string": "^9.3.1",
44-
"react": "^17.0.2",
45-
"react-dom": "^17.0.2",
43+
"react": "^18.3.1",
44+
"react-dom": "^18.3.1",
4645
"react-i18next": "10.5.2",
4746
"react-redux": "7.2.8",
4847
"react-router-dom": "^5.0.0",
4948
"react-swipeable": "^5.5.1",
5049
"react-transition-group": "^2.6.1",
5150
"recharts": "2.1.13",
5251
"redux": "4.2.0",
52+
"redux-first-history": "^5.2.0",
5353
"redux-logger": "3.0.6",
5454
"redux-persist": "6.0.0",
5555
"redux-saga": "0.16.2",

src/App.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import React, { Suspense } from 'react'
22
import { useSelector } from 'react-redux'
3-
import { ConnectedRouter } from 'connected-react-router'
3+
import { Router } from 'react-router-dom'
44
import { I18nextProvider } from 'react-i18next'
55

66
import i18n from 'locales/i18n'
7-
import history from 'state/createdHistory'
7+
import { history } from 'state/store'
88
import Auth from 'components/Auth'
99
import ElectronMenu from 'components/ElectronMenu'
1010
import Header from 'components/Header'
@@ -17,14 +17,14 @@ function App() {
1717
return (
1818
<I18nextProvider i18n={i18n}>
1919
<Suspense fallback={<div className='app-loader' />}>
20-
<ConnectedRouter history={history}>
20+
<Router history={history}>
2121
{showElectronMenu && (<ElectronMenu />)}
2222
<Header />
2323
<div className='app'>
2424
<Auth />
2525
<Main />
2626
</div>
27-
</ConnectedRouter>
27+
</Router>
2828
</Suspense>
2929
</I18nextProvider>
3030
)

src/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react'
2-
import ReactDOM from 'react-dom'
2+
import { createRoot } from 'react-dom/client'
33
import { Provider } from 'react-redux'
44
import { FocusStyleManager } from '@blueprintjs/core'
55
import { PersistGate } from 'redux-persist/integration/react'
@@ -23,13 +23,13 @@ import packageInfo from '../package.json'
2323

2424
const { version } = packageInfo
2525

26-
ReactDOM.render(
26+
const root = createRoot(document.getElementById('root'))
27+
root.render(
2728
<Provider store={store}>
2829
<PersistGate loading={null} persistor={persistor}>
2930
<App />
3031
</PersistGate>
3132
</Provider>,
32-
document.getElementById('root'),
3333
)
3434

3535
window.addEventListener('load', () => {

src/state/createdHistory.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
11
import { createBrowserHistory } from 'history'
2+
import { createReduxHistoryContext } from 'redux-first-history'
23

3-
export default createBrowserHistory()
4+
const {
5+
createReduxHistory,
6+
routerMiddleware,
7+
routerReducer,
8+
} = createReduxHistoryContext({ history: createBrowserHistory() })
9+
10+
export {
11+
createReduxHistory,
12+
routerMiddleware,
13+
routerReducer,
14+
}

src/state/reducers.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import { combineReducers } from 'redux'
22
import { persistReducer, createMigrate } from 'redux-persist'
3-
import { connectRouter } from 'connected-react-router'
43
import storage from 'redux-persist/lib/storage'
54

65
import config from 'config'
76
import persistMigrations from 'state/persist.migrations'
87

9-
import history from './createdHistory'
8+
import { routerReducer } from './createdHistory'
109
import accountBalanceReducer from './accountBalance/reducer'
1110
import accountSummaryReducer from './accountSummary/reducer'
1211
import affiliatesEarningsReducer from './affiliatesEarnings/reducer'
@@ -99,7 +98,7 @@ const BASE_REDUCERS = {
9998
profits: profitsReducer,
10099
publicFunding: publicFundingReducer,
101100
publicTrades: publicTradesReducer,
102-
router: connectRouter(history),
101+
router: routerReducer,
103102
routing: routingReducer,
104103
spayments: stakingPaymentsReducer,
105104
query: queryReducer,

src/state/routing/saga.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { put, select, takeLatest } from 'redux-saga/effects'
2-
import { LOCATION_CHANGE, replace } from 'connected-react-router'
2+
import { LOCATION_CHANGE, replace } from 'redux-first-history'
33
import { isEmpty } from '@bitfinex/lib-js-util-base'
44

55
import { getTarget } from 'state/query/utils'
@@ -14,11 +14,15 @@ import { getLastRoute, getRouteParams } from './selectors'
1414

1515
const { MENU_ORDER_TRADES } = queryConstants
1616

17+
let isFirstRendering = true
18+
1719
function* locationChange({ payload }) {
18-
const { isFirstRendering, location } = payload
20+
const { location } = payload
1921
const { pathname, search, state } = location
2022

21-
if (isFirstRendering) {
23+
const isFirstRender = isFirstRendering
24+
if (isFirstRender) {
25+
isFirstRendering = false
2226
// redirects from legacy sections `deposits' and 'withdrawals' to 'movements' on first render
2327
if (pathname.includes('/deposits') || pathname.includes('/withdrawals')) {
2428
const [, , symbols] = pathname.split('/')
@@ -43,7 +47,7 @@ function* locationChange({ payload }) {
4347
}
4448

4549
// return previously saved params on route change
46-
if (route !== lastRoute && !isFirstRendering) {
50+
if (route !== lastRoute && !isFirstRender) {
4751
const routeParams = yield select(getRouteParams, route)
4852
if (isEmpty(routeParams)) {
4953
const query = getQueryWithoutParams(Object.keys(FILTER_KEYS)) // remove filters of current section

src/state/store.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@ import {
66
import createSagaMiddleware from 'redux-saga'
77
import { createLogger } from 'redux-logger'
88
import { persistStore } from 'redux-persist'
9-
import { routerMiddleware } from 'connected-react-router'
10-
119
import reducer from './reducers'
1210
import saga from './sagas'
13-
import history from './createdHistory'
11+
import { createReduxHistory, routerMiddleware } from './createdHistory'
1412

1513
const { REACT_APP_ENV } = process.env
1614

@@ -20,7 +18,7 @@ function configureStore() {
2018
// eslint-disable-next-line no-underscore-dangle
2119
const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose
2220
// add middlewares here
23-
const middleware = [sagaMiddleware, routerMiddleware(history)]
21+
const middleware = [sagaMiddleware, routerMiddleware]
2422
// use the logger in development mode - this is set in webpack.config.dev.js
2523
if (REACT_APP_ENV === 'development' || REACT_APP_ENV === 'staging') {
2624
middleware.push(createLogger())
@@ -33,6 +31,7 @@ function configureStore() {
3331
}
3432

3533
const store = configureStore()
34+
const history = createReduxHistory(store)
3635
const persistor = persistStore(store)
3736

3837
if (REACT_APP_ENV !== 'testing') {
@@ -41,6 +40,7 @@ if (REACT_APP_ENV !== 'testing') {
4140

4241
export {
4342
configureStore,
43+
history,
4444
persistor,
4545
store,
4646
}

0 commit comments

Comments
 (0)