Skip to content

Commit

Permalink
Clear form cache on componentDidMount instead of mapStateToProps (d…
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewmtam committed Mar 25, 2020
1 parent 877b08a commit 3f235c8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/components/form-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ function createFormClass(s = defaultStrategy) {
if (this.props.getDispatch) {
this.props.getDispatch(this.props.dispatch);
}
clearGetFormCacheForModel(this.props.model);
}

UNSAFE_componentWillReceiveProps(nextProps) {
Expand Down Expand Up @@ -409,7 +410,6 @@ function createFormClass(s = defaultStrategy) {

function mapStateToProps(state, { model }) {
const modelString = getModel(model, state);
clearGetFormCacheForModel(modelString);
const form = s.getForm(state, modelString);

invariant(form,
Expand Down
5 changes: 5 additions & 0 deletions test/form-component-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import sinon from 'sinon';

import isValid from '../src/form/is-valid';
import { defaultTestContexts, testCreateStore, testRender } from './utils';
import { clearGetFormCache } from '../src/utils/get-form';

import {
Form as _Form,
Expand Down Expand Up @@ -69,6 +70,10 @@ Object.keys(testContexts).forEach((testKey) => {
const combineForms = testContext.combineForms;

describe(`<Form> component (${testKey} context)`, () => {
beforeEach(() => {
clearGetFormCache();
});

describe('wraps component if specified', () => {
const store = testCreateStore({
testForm: formReducer('test', object),
Expand Down

0 comments on commit 3f235c8

Please sign in to comment.