From 3f235c87fceb9a7816f28ce1b57199190c9dd989 Mon Sep 17 00:00:00 2001 From: Andrew Tam Date: Tue, 24 Mar 2020 21:14:57 -0400 Subject: [PATCH] Clear form cache on `componentDidMount` instead of `mapStateToProps` (#1218) --- src/components/form-component.js | 2 +- test/form-component-spec.js | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/components/form-component.js b/src/components/form-component.js index 49dc6881e..42ebd57e7 100644 --- a/src/components/form-component.js +++ b/src/components/form-component.js @@ -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) { @@ -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, diff --git a/test/form-component-spec.js b/test/form-component-spec.js index 712d8c952..b7064dfc2 100644 --- a/test/form-component-spec.js +++ b/test/form-component-spec.js @@ -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, @@ -69,6 +70,10 @@ Object.keys(testContexts).forEach((testKey) => { const combineForms = testContext.combineForms; describe(`
component (${testKey} context)`, () => { + beforeEach(() => { + clearGetFormCache(); + }); + describe('wraps component if specified', () => { const store = testCreateStore({ testForm: formReducer('test', object),