Skip to content

Commit

Permalink
fix(core): fix field destructor name will cause stack overflow (#3524)
Browse files Browse the repository at this point in the history
  • Loading branch information
janryWang authored Nov 7, 2022
1 parent f35e5df commit 7306677
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
12 changes: 12 additions & 0 deletions packages/core/src/__tests__/field.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2334,3 +2334,15 @@ test('field hidden value', () => {
expect(objectField.value).toEqual({})
expect(arrayField.value).toEqual([])
})

test('field destructor path with display none', () => {
const form = attach(createForm())
const aa = attach(
form.createArrayField({
name: '[aa,bb]',
})
)
aa.setDisplay('none')
expect(form.values).toEqual({})
expect(aa.value).toEqual([])
})
12 changes: 9 additions & 3 deletions packages/core/src/models/Field.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { isValid, toArr, FormPathPattern, isArr } from '@formily/shared'
import {
isValid,
isEmpty,
toArr,
FormPathPattern,
isArr,
} from '@formily/shared'
import {
ValidatorTriggerType,
parseValidatorDescriptions,
Expand Down Expand Up @@ -47,7 +53,7 @@ import {
} from '../shared/internals'
import { Form } from './Form'
import { BaseField } from './BaseField'
import { IFormFeedback } from '..'
import { IFormFeedback } from '../types'
export class Field<
Decorator extends JSXComponent = any,
Component extends JSXComponent = any,
Expand Down Expand Up @@ -222,7 +228,7 @@ export class Field<
if (this.selfModified && !this.caches.inputting) {
validateSelf(this)
}
if (this.display === 'none') {
if (!isEmpty(value) && this.display === 'none') {
this.caches.value = toJS(value)
this.form.deleteValuesIn(this.path)
}
Expand Down

0 comments on commit 7306677

Please sign in to comment.