Skip to content
This repository was archived by the owner on Aug 23, 2022. It is now read-only.

Commit 18d5142

Browse files
committed
Ensuring that resetting to null does not cause an infinite loop. Fixes #512
1 parent 7efde9f commit 18d5142

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

src/reducers/form-actions-reducer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const resetFieldState = (field, key) => {
2121

2222
if (field.$form) return mapValues(field, resetFieldState);
2323

24-
return i.merge(initialFieldState, {
24+
return i.assign(initialFieldState, {
2525
value: field.initialValue,
2626
model: field.model,
2727
intents: [{ type: 'validate' }],

src/utils/update-field.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import mapValues from './map-values';
44
import { createInitialState } from '../reducers/form-reducer';
55

66
function assocIn(state, path, value, fn) {
7+
if (!path.length) return i.assign(state, value);
78
if (!fn) return i.assocIn(state, path, value);
89

910
const key0 = path[0];

test/form-reducer-actions-spec.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,4 +697,21 @@ describe('formReducer() (V1)', () => {
697697
assert.equal(resetState.foo.value, 'new initial');
698698
});
699699
});
700+
701+
describe('resetting to null', () => {
702+
it('should work and not cause an infinite loop', () => {
703+
assert.doesNotThrow(() => {
704+
const reducer = formReducer('foo', null);
705+
706+
const state = reducer(
707+
undefined,
708+
actions.reset('foo')
709+
);
710+
711+
assert.containSubset(state, {
712+
value: null,
713+
});
714+
});
715+
});
716+
})
700717
});

0 commit comments

Comments
 (0)