Skip to content

Commit

Permalink
Merge pull request #6704 from marmelab/remove-connected-router
Browse files Browse the repository at this point in the history
Remove connected-react-router
  • Loading branch information
djhi authored Oct 19, 2021
2 parents 5ef5b2e + 7f2af38 commit a6dae82
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 74 deletions.
2 changes: 0 additions & 2 deletions packages/ra-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
"@types/react-redux": "^7.1.1",
"@types/react-router": "^5.1.0",
"@types/react-router-dom": "^5.1.0",
"connected-react-router": "^6.5.2",
"cross-env": "^5.2.0",
"final-form": "^4.20.2",
"history": "^4.7.2",
Expand All @@ -51,7 +50,6 @@
"rimraf": "^2.6.3"
},
"peerDependencies": {
"connected-react-router": "^6.5.2",
"final-form": "^4.20.2",
"react": "^16.9.0 || ^17.0.0",
"react-dom": "^16.9.0 || ^17.0.0",
Expand Down
13 changes: 3 additions & 10 deletions packages/ra-core/src/core/CoreAdminContext.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import * as React from 'react';
import { ComponentType, useContext, useState } from 'react';
import { Provider, ReactReduxContext } from 'react-redux';
import { History } from 'history';
import { createHashHistory } from 'history';
import { ConnectedRouter } from 'connected-react-router';
import { createHashHistory, History } from 'history';
import { Router } from 'react-router';

import { AuthContext, convertLegacyAuthProvider } from '../auth';
import {
Expand Down Expand Up @@ -73,13 +72,7 @@ React-admin requires a valid dataProvider function to work.`);
<AuthContext.Provider value={finalAuthProvider}>
<DataProviderContext.Provider value={finalDataProvider}>
<TranslationProvider i18nProvider={i18nProvider}>
{typeof window !== 'undefined' ? (
<ConnectedRouter history={finalHistory}>
{children}
</ConnectedRouter>
) : (
children
)}
<Router history={finalHistory}>{children}</Router>
</TranslationProvider>
</DataProviderContext.Provider>
</AuthContext.Provider>
Expand Down
21 changes: 7 additions & 14 deletions packages/ra-core/src/core/createAdminStore.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { createStore, compose, applyMiddleware } from 'redux';
import { routerMiddleware } from 'connected-react-router';
import { createStore, StoreEnhancer } from 'redux';
import { History } from 'history';

import {
Expand All @@ -12,7 +11,7 @@ import createAppReducer from '../reducer';
import { CLEAR_STATE } from '../actions/clearActions';

interface Window {
__REDUX_DEVTOOLS_EXTENSION_COMPOSE__?: (traceOptions: object) => Function;
__REDUX_DEVTOOLS_EXTENSION__?: (traceOptions: object) => StoreEnhancer;
}

interface Params {
Expand Down Expand Up @@ -54,20 +53,14 @@ export default ({
);
const typedWindow = typeof window !== 'undefined' && (window as Window);

const composeEnhancers =
(process.env.NODE_ENV === 'development' &&
typeof typedWindow !== 'undefined' &&
typedWindow.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ &&
typedWindow.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({
trace: true,
traceLimit: 25,
})) ||
compose;

const store = createStore(
resettableAppReducer,
typeof initialState === 'function' ? initialState() : initialState,
composeEnhancers(applyMiddleware(routerMiddleware(history)))
typedWindow.__REDUX_DEVTOOLS_EXTENSION__ &&
typedWindow.__REDUX_DEVTOOLS_EXTENSION__({
trace: true,
traceLimit: 25,
})
);
return store;
};
2 changes: 0 additions & 2 deletions packages/ra-core/src/reducer/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { combineReducers, Reducer } from 'redux';
import { connectRouter } from 'connected-react-router';
import admin, {
getResources as adminGetResources,
getReferenceResource as adminGetReferenceResource,
Expand All @@ -14,7 +13,6 @@ interface CustomReducers {
export default (customReducers: CustomReducers, history) =>
combineReducers({
admin,
router: connectRouter(history),
...customReducers,
});

Expand Down
1 change: 0 additions & 1 deletion packages/ra-test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
"@types/react-redux": "^7.1.1",
"@types/react-router": "^5.1.0",
"@types/react-router-dom": "^5.1.0",
"connected-react-router": "^6.5.2",
"cross-env": "^5.2.0",
"final-form": "^4.20.2",
"history": "^4.7.2",
Expand Down
29 changes: 5 additions & 24 deletions packages/ra-test/src/TestContext.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import * as React from 'react';
import expect from 'expect';
import { render } from '@testing-library/react';
import * as React from 'react';
import { refreshView } from 'ra-core';

import TestContext, { defaultStore } from './TestContext';
import { refreshView } from 'ra-core';

const primedStore = {
admin: {
Expand All @@ -19,17 +19,6 @@ const primedStore = {
},
customQueries: {},
},
router: {
action: 'POP',
location: {
hash: '',
key: '',
pathname: '/',
query: {},
search: '',
state: undefined,
},
},
};

const CHANGE_FOO = 'CHANGE_FOO';
Expand All @@ -56,11 +45,6 @@ const customReducer = (prevState = customReducerInitialState, action) => {
}
};

const eraseRouterKey = state => {
state.router.location.key = ''; // react-router initializes the state with a random key
return state;
};

describe('TestContext.js', () => {
it('should render the given children', () => {
const { queryAllByText } = render(
Expand Down Expand Up @@ -98,8 +82,7 @@ describe('TestContext.js', () => {
}}
</TestContext>
);
const initialstate = eraseRouterKey(testStore.getState());
expect(initialstate).toEqual(primedStore);
expect(testStore.getState()).toEqual(primedStore);

testStore.dispatch(refreshView());

Expand Down Expand Up @@ -145,9 +128,8 @@ describe('TestContext.js', () => {
}}
</TestContext>
);
const initialstate = eraseRouterKey(testStore.getState());

expect(initialstate).toEqual({
expect(testStore.getState()).toEqual({
...primedStore,
customReducer: customReducerInitialState,
});
Expand All @@ -169,9 +151,8 @@ describe('TestContext.js', () => {
);

testStore.dispatch(customAction(testValue));
const alteredState = eraseRouterKey(testStore.getState());

expect(alteredState).toEqual({
expect(testStore.getState()).toEqual({
...primedStore,
customReducer: {
...customReducerInitialState,
Expand Down
1 change: 0 additions & 1 deletion packages/ra-ui-materialui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@
"dependencies": {
"autosuggest-highlight": "^3.1.1",
"classnames": "~2.2.5",
"connected-react-router": "^6.5.2",
"css-mediaquery": "^0.1.2",
"downshift": "3.2.7",
"inflection": "~1.12.0",
Expand Down
1 change: 0 additions & 1 deletion packages/react-admin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
"@emotion/styled": "^11.3.0",
"@mui/icons-material": "^5.0.1",
"@mui/material": "^5.0.2",
"connected-react-router": "^6.5.2",
"final-form": "^4.20.2",
"final-form-arrays": "^3.0.2",
"ra-core": "^4.0.0-alpha.0",
Expand Down
19 changes: 0 additions & 19 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9659,15 +9659,6 @@ connect-history-api-fallback@^1.3.0, connect-history-api-fallback@^1.6.0:
resolved "https://registry.yarnpkg.com/connect-history-api-fallback/-/connect-history-api-fallback-1.6.0.tgz#8b32089359308d111115d81cad3fceab888f97bc"
integrity sha512-e54B99q/OUoH64zYYRf3HBP5z24G38h5D3qXu23JGRoigpX5Ss4r9ZnDk3g0Z8uQC2x2lPaJ+UlWBc1ZWBWdLg==

connected-react-router@^6.5.2:
version "6.6.1"
resolved "https://registry.yarnpkg.com/connected-react-router/-/connected-react-router-6.6.1.tgz#f6b7717abf959393fab6756c8d43af1a57d622da"
integrity sha512-a/SE3HgpZABCxr083bfAMpgZwUzlv1RkmOV71+D4I77edoR/peg7uJMHOgqWnXXqGD7lo3Y2ZgUlXtMhcv8FeA==
dependencies:
immutable "^3.8.1"
prop-types "^15.7.2"
seamless-immutable "^7.1.3"

console-browserify@^1.1.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/console-browserify/-/console-browserify-1.2.0.tgz#67063cef57ceb6cf4993a2ab3a55840ae8c49336"
Expand Down Expand Up @@ -14582,11 +14573,6 @@ immer@8.0.1:
resolved "https://registry.yarnpkg.com/immer/-/immer-8.0.1.tgz#9c73db683e2b3975c424fb0572af5889877ae656"
integrity sha512-aqXhGP7//Gui2+UrEtvxZxSquQVXTpZ7KDxfCcKAF3Vysvw0CViVaW9RZ1j1xlIYqaaaipBoqdqeibkc18PNvA==

immutable@^3.8.1:
version "3.8.2"
resolved "https://registry.yarnpkg.com/immutable/-/immutable-3.8.2.tgz#c2439951455bb39913daf281376f1530e104adf3"
integrity sha1-wkOZUUVbs5kT2vKBN28VMOEErfM=

import-cwd@^2.0.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/import-cwd/-/import-cwd-2.1.0.tgz#aa6cf36e722761285cb371ec6519f53e2435b0a9"
Expand Down Expand Up @@ -22260,11 +22246,6 @@ scoped-regex@^1.0.0:
resolved "https://registry.yarnpkg.com/scoped-regex/-/scoped-regex-1.0.0.tgz#a346bb1acd4207ae70bd7c0c7ca9e566b6baddb8"
integrity sha1-o0a7Gs1CB65wvXwMfKnlZra63bg=

seamless-immutable@^7.1.3:
version "7.1.4"
resolved "https://registry.yarnpkg.com/seamless-immutable/-/seamless-immutable-7.1.4.tgz#6e9536def083ddc4dea0207d722e0e80d0f372f8"
integrity sha512-XiUO1QP4ki4E2PHegiGAlu6r82o5A+6tRh7IkGGTVg/h+UoeX4nFBeCGPOhb4CYjvkqsfm/TUtvOMYC1xmV30A==

select-hose@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/select-hose/-/select-hose-2.0.0.tgz#625d8658f865af43ec962bfc376a37359a4994ca"
Expand Down

0 comments on commit a6dae82

Please sign in to comment.