diff --git a/packages/ra-core/src/sideEffect/recordForm.js b/packages/ra-core/src/sideEffect/recordForm.js index bc40d4f6c9..7f8783ffa4 100644 --- a/packages/ra-core/src/sideEffect/recordForm.js +++ b/packages/ra-core/src/sideEffect/recordForm.js @@ -18,8 +18,8 @@ export function* handleLocationChange({ payload }) { previousLocation = payload; - yield put(destroy(REDUX_FORM_NAME)); yield put(resetForm()); + yield put(destroy(REDUX_FORM_NAME)); } export default function* recordForm() { diff --git a/packages/ra-core/src/sideEffect/recordForm.spec.js b/packages/ra-core/src/sideEffect/recordForm.spec.js index 9ba3b76838..d3ef02f5cb 100644 --- a/packages/ra-core/src/sideEffect/recordForm.spec.js +++ b/packages/ra-core/src/sideEffect/recordForm.spec.js @@ -1,14 +1,13 @@ import { put } from 'redux-saga/effects'; -import { LOCATION_CHANGE } from 'react-router-redux'; import { destroy } from 'redux-form'; -import { resetForm } from '../actions/formActions'; +import { resetForm, BEFORE_LOCATION_CHANGE } from '../actions/formActions'; import { handleLocationChange } from './recordForm'; import { REDUX_FORM_NAME } from '../form/constants'; describe('recordForm saga', () => { - it('resets the form when the LOCATION_CHANGE action has no state', () => { + it('resets the form when the BEFORE_LOCATION_CHANGE action has no state', () => { const saga = handleLocationChange({ - type: LOCATION_CHANGE, + type: BEFORE_LOCATION_CHANGE, payload: { pathname: '/comments/create' }, }); @@ -16,9 +15,9 @@ describe('recordForm saga', () => { expect(saga.next().value).toEqual(put(destroy(REDUX_FORM_NAME))); }); - it('does not reset the form when the LOCATION_CHANGE action state has skipFormReset set to true', () => { + it('does not reset the form when the BEFORE_LOCATION_CHANGE action state has skipFormReset set to true', () => { const saga = handleLocationChange({ - type: LOCATION_CHANGE, + type: BEFORE_LOCATION_CHANGE, payload: { pathname: '/comments/create/2', state: { skipFormReset: true }, @@ -30,7 +29,7 @@ describe('recordForm saga', () => { it('does not reset the form when navigating to same location', () => { const saga = handleLocationChange({ - type: LOCATION_CHANGE, + type: BEFORE_LOCATION_CHANGE, payload: { pathname: '/comments/create/2', }, @@ -40,7 +39,7 @@ describe('recordForm saga', () => { saga.next(); const saga2 = handleLocationChange({ - type: LOCATION_CHANGE, + type: BEFORE_LOCATION_CHANGE, payload: { pathname: '/comments/create/2', },