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

Commit 0fd07c6

Browse files
authored
Merge pull request #1219 from andrewmtam/issue-1218
Clear form cache on `componentDidMount` instead of `mapStateToProps` (#1218)
2 parents 877b08a + 488eb9e commit 0fd07c6

File tree

4 files changed

+42
-23
lines changed

4 files changed

+42
-23
lines changed

src/components/control-component-factory.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,6 @@ function createControlClass(s) {
157157
this.handleLoad();
158158
}
159159

160-
UNSAFE_componentWillReceiveProps({ modelValue }) {
161-
if (modelValue !== this.props.modelValue) {
162-
this.setViewValue(modelValue);
163-
}
164-
}
165-
166160
shouldComponentUpdate(nextProps, nextState) {
167161
return !shallowEqual(this.props, nextProps, {
168162
deepKeys: ['controlProps'],
@@ -388,6 +382,13 @@ function createControlClass(s) {
388382
return this.props.getValue(event, this.props);
389383
}
390384

385+
/* eslint-disable camelcase */
386+
UNSAFE_componentWillReceiveProps({ modelValue }) {
387+
if (modelValue !== this.props.modelValue) {
388+
this.setViewValue(modelValue);
389+
}
390+
}
391+
391392
handleIntents() {
392393
const {
393394
model,

src/components/form-component.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,7 @@ function createFormClass(s = defaultStrategy) {
9898
if (this.props.getDispatch) {
9999
this.props.getDispatch(this.props.dispatch);
100100
}
101-
}
102-
103-
UNSAFE_componentWillReceiveProps(nextProps) {
104-
if (containsEvent(nextProps.validateOn, 'change')) {
105-
this.validate(nextProps);
106-
}
101+
clearGetFormCacheForModel(this.props.model);
107102
}
108103

109104
shouldComponentUpdate(nextProps, nextState) {
@@ -122,6 +117,13 @@ function createFormClass(s = defaultStrategy) {
122117
}
123118
}
124119

120+
/* eslint-disable camelcase */
121+
UNSAFE_componentWillReceiveProps(nextProps) {
122+
if (containsEvent(nextProps.validateOn, 'change')) {
123+
this.validate(nextProps);
124+
}
125+
}
126+
125127
handleUpdate() {
126128
if (this.props.onUpdate) {
127129
this.props.onUpdate(this.props.formValue);
@@ -409,7 +411,6 @@ function createFormClass(s = defaultStrategy) {
409411

410412
function mapStateToProps(state, { model }) {
411413
const modelString = getModel(model, state);
412-
clearGetFormCacheForModel(modelString);
413414
const form = s.getForm(state, modelString);
414415

415416
invariant(form,

test/form-component-spec.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import sinon from 'sinon';
1111

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

1516
import {
1617
Form as _Form,
@@ -69,6 +70,10 @@ Object.keys(testContexts).forEach((testKey) => {
6970
const combineForms = testContext.combineForms;
7071

7172
describe(`<Form> component (${testKey} context)`, () => {
73+
beforeEach(() => {
74+
clearGetFormCache();
75+
});
76+
7277
describe('wraps component if specified', () => {
7378
const store = testCreateStore({
7479
testForm: formReducer('test', object),

yarn.lock

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2588,6 +2588,11 @@ js-tokens@^3.0.0, js-tokens@^3.0.2:
25882588
version "3.0.2"
25892589
resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-3.0.2.tgz#9866df395102130e38f7f996bceb65443209c25b"
25902590

2591+
"js-tokens@^3.0.0 || ^4.0.0":
2592+
version "4.0.0"
2593+
resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499"
2594+
integrity sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==
2595+
25912596
js-yaml@^3.5.1:
25922597
version "3.11.0"
25932598
resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.11.0.tgz#597c1a8bd57152f26d622ce4117851a51f5ebaef"
@@ -2719,7 +2724,7 @@ loader-utils@^1.0.2:
27192724
emojis-list "^2.0.0"
27202725
json5 "^0.5.0"
27212726

2722-
lodash-es@^4.17.5, lodash-es@^4.2.1:
2727+
lodash-es@^4.17.5:
27232728
version "4.17.10"
27242729
resolved "https://registry.yarnpkg.com/lodash-es/-/lodash-es-4.17.10.tgz#62cd7104cdf5dd87f235a837f0ede0e8e5117e05"
27252730

@@ -2792,7 +2797,7 @@ lodash.words@^3.0.0:
27922797
dependencies:
27932798
lodash._root "^3.0.0"
27942799

2795-
lodash@^4.0.0, lodash@^4.17.4, lodash@^4.17.5, lodash@^4.2.0, lodash@^4.2.1, lodash@^4.3.0, lodash@~4.17.2:
2800+
lodash@^4.0.0, lodash@^4.17.4, lodash@^4.17.5, lodash@^4.2.0, lodash@^4.3.0, lodash@~4.17.2:
27962801
version "4.17.10"
27972802
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.10.tgz#1b7793cf7259ea38fb3661d4d38b3260af8ae4e7"
27982803

@@ -2810,6 +2815,13 @@ loose-envify@^1.0.0, loose-envify@^1.1.0, loose-envify@^1.3.1:
28102815
dependencies:
28112816
js-tokens "^3.0.0"
28122817

2818+
loose-envify@^1.4.0:
2819+
version "1.4.0"
2820+
resolved "https://registry.yarnpkg.com/loose-envify/-/loose-envify-1.4.0.tgz#71ee51fa7be4caec1a63839f7e682d8132d30caf"
2821+
integrity sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==
2822+
dependencies:
2823+
js-tokens "^3.0.0 || ^4.0.0"
2824+
28132825
lru-cache@2:
28142826
version "2.7.3"
28152827
resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-2.7.3.tgz#6d4524e8b955f95d4f5b58851ce21dd72fb4e952"
@@ -3745,14 +3757,13 @@ redux-thunk@^2.0.1:
37453757
version "2.2.0"
37463758
resolved "https://registry.yarnpkg.com/redux-thunk/-/redux-thunk-2.2.0.tgz#e615a16e16b47a19a515766133d1e3e99b7852e5"
37473759

3748-
redux@^3.3.1:
3749-
version "3.7.2"
3750-
resolved "https://registry.yarnpkg.com/redux/-/redux-3.7.2.tgz#06b73123215901d25d065be342eb026bc1c8537b"
3760+
redux@^4.0.0:
3761+
version "4.0.5"
3762+
resolved "https://registry.yarnpkg.com/redux/-/redux-4.0.5.tgz#4db5de5816e17891de8a80c424232d06f051d93f"
3763+
integrity sha512-VSz1uMAH24DM6MF72vcojpYPtrTUu3ByVWfPL1nPfVRb5mZVTve5GnNCUV53QM/BZ66xfWrm0CTWoM+Xlz8V1w==
37513764
dependencies:
3752-
lodash "^4.2.1"
3753-
lodash-es "^4.2.1"
3754-
loose-envify "^1.1.0"
3755-
symbol-observable "^1.0.3"
3765+
loose-envify "^1.4.0"
3766+
symbol-observable "^1.2.0"
37563767

37573768
regenerate@^1.2.1:
37583769
version "1.3.3"
@@ -4187,9 +4198,10 @@ svgo@^0.7.0:
41874198
sax "~1.2.1"
41884199
whet.extend "~0.9.9"
41894200

4190-
symbol-observable@^1.0.3:
4201+
symbol-observable@^1.2.0:
41914202
version "1.2.0"
41924203
resolved "https://registry.yarnpkg.com/symbol-observable/-/symbol-observable-1.2.0.tgz#c22688aed4eab3cdc2dfeacbb561660560a00804"
4204+
integrity sha512-e900nM8RRtGhlV36KGEU9k65K3mPb1WV70OdjfxlG2EAuM1noi/E/BaW/uMhL7bPEssK8QV57vN3esixjUvcXQ==
41934205

41944206
symbol-tree@^3.2.1:
41954207
version "3.2.2"

0 commit comments

Comments
 (0)