Skip to content

Commit

Permalink
fix: nested array initial-value reset on destory
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] authored and charlzyx committed Dec 29, 2023
1 parent 66ede1d commit 9311f49
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 29 deletions.
68 changes: 42 additions & 26 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,33 @@
# Changelog

## v2.3.1(2023-12-18)

### :tada: Enhancements

1. [feat: export getLocaleByPath (#4006)](https://github.com/alibaba/formily/commit/15d51bc9) :point_right: ( [uxuip](https://github.com/uxuip) )

1. [feat: props recursion test case added (#4001)](https://github.com/alibaba/formily/commit/d8716ea9) :point_right: ( [Nice](https://github.com/Nice) )

1. [feat(antd): support disable default behavior of built-in operations in ArrayBase (#3998)](https://github.com/alibaba/formily/commit/c90b1df1) :point_right: ( [whincwu](https://github.com/whincwu) )

### :bug: Bug Fixes

1. [fix: fix vue2 array reactive bug (#4042)](https://github.com/alibaba/formily/commit/c94da3fe) :point_right: ( [yiyunwan](https://github.com/yiyunwan) )

1. [fix: fix docs throw error](https://github.com/alibaba/formily/commit/588e5e52) :point_right: ( [janrywang](https://github.com/janrywang) )

1. [fix: #3986 (#4003)](https://github.com/alibaba/formily/commit/39d64318) :point_right: ( [Lumdzeehol](https://github.com/Lumdzeehol) )

### :hammer_and_wrench: Update Workflow Scripts

1. [build(deps-dev): bump axios from 0.23.0 to 1.6.0 (#4023)](https://github.com/alibaba/formily/commit/d6f827c1) :point_right: ( [dependabot[bot]](https://github.com/dependabot[bot]) )

1. [build(deps): bump browserify-sign from 4.2.1 to 4.2.2 (#4010)](https://github.com/alibaba/formily/commit/e38de2a3) :point_right: ( [dependabot[bot]](https://github.com/dependabot[bot]) )

### :blush: Other Changes

1. [chore: dumi updated for node 18+ (#4018)](https://github.com/alibaba/formily/commit/48c9968b) :point_right: ( [bob](https://github.com/bob) )

## v2.3.0(2023-10-20)

### :tada: Enhancements
Expand Down Expand Up @@ -602,24 +630,6 @@

1. [feat(element): add element style import description (#3188)](https://github.com/alibaba/formily/commit/4bca1108) :point_right: ( [KKandLL-Forever](https://github.com/KKandLL-Forever) )

### :bug: Bug Fixes

1. [fix(antd/next): fix form tab error badge count (#3206)](https://github.com/alibaba/formily/commit/6eed89b3) :point_right: ( [Janry](https://github.com/Janry) )

1. [fix: vue3 slots.default do not always exist (#3192)](https://github.com/alibaba/formily/commit/91d64889) :point_right: ( [qq1037305420](https://github.com/qq1037305420) )

### :memo: Documents Changes

1. [docs: fix contribution.zh-CN error (doc -> docs) (#3202)](https://github.com/alibaba/formily/commit/a4974d23) :point_right: ( [Akong](https://github.com/Akong) )

1. [docs(antd): fix Select component docs error (#3199)](https://github.com/alibaba/formily/commit/ee70cde1) :point_right: ( [微笑](https://github.com/微笑) )

1. [docs: delete useless code (#3198)](https://github.com/alibaba/formily/commit/8ef12b43) :point_right: ( [zhangrenyang](https://github.com/zhangrenyang) )

## v2.1.5(2022-06-12)

### :tada: Enhancements

1. [feat(react): adjust component recognition priority (#3180)](https://github.com/alibaba/formily/commit/bf4e035c) :point_right: ( [Janry](https://github.com/Janry) )

1. [feat(json-schema): support x-compile-omitted attribute (#3145)](https://github.com/alibaba/formily/commit/c8485c0e) :point_right: ( [Janry](https://github.com/Janry) )
Expand Down Expand Up @@ -716,8 +726,6 @@

1. [feat(antd): transfer compat label/value](https://github.com/alibaba/formily/commit/2be3a10d) :point_right: ( [janrywang](https://github.com/janrywang) )

1. [feat(element): add element support (#1734)](https://github.com/alibaba/formily/commit/43d1ef0b) :point_right: ( [Muyao](https://github.com/Muyao) )

1. [feat(core): skip validate when parent.visible is equal hidden/none (#1712)](https://github.com/alibaba/formily/commit/0076ef7d) :point_right: ( [Janry](https://github.com/Janry) )

1. [feat(designable-antd): support markup schema view](https://github.com/alibaba/formily/commit/2acb1033) :point_right: ( [janrywang](https://github.com/janrywang) )
Expand Down Expand Up @@ -824,8 +832,6 @@

1. [feat(layout): support responsive gri layout for older browsers (#916)](https://github.com/alibaba/formily/commit/f87e70dc) :point_right: ( [quirkyvar](https://github.com/quirkyvar) )

1. [feat: support antd v3 (#913)](https://github.com/alibaba/formily/commit/7b4cf527) :point_right: ( [quirkyvar](https://github.com/quirkyvar) )

1. [feat: add ie compat mode of grid(ie) (#912)](https://github.com/alibaba/formily/commit/b7313976) :point_right: ( [quirkyvar](https://github.com/quirkyvar) )

1. [feat(layout): add ts type desc of MegaLayout and fix array-inc doc (#905)](https://github.com/alibaba/formily/commit/f37a0934) :point_right: ( [quirkyvar](https://github.com/quirkyvar) )
Expand Down Expand Up @@ -952,6 +958,10 @@

### :bug: Bug Fixes

1. [fix(antd/next): fix form tab error badge count (#3206)](https://github.com/alibaba/formily/commit/6eed89b3) :point_right: ( [Janry](https://github.com/Janry) )

1. [fix: vue3 slots.default do not always exist (#3192)](https://github.com/alibaba/formily/commit/91d64889) :point_right: ( [qq1037305420](https://github.com/qq1037305420) )

1. [fix(core): fix set initialValue no cache value when display none (#3182)](https://github.com/alibaba/formily/commit/66ffeb6c) :point_right: ( [Janry](https://github.com/Janry) )

1. [fix(react): fix field wrong mounted state (#3181)](https://github.com/alibaba/formily/commit/d705f56d) :point_right: ( [Janry](https://github.com/Janry) )
Expand Down Expand Up @@ -1008,8 +1018,6 @@

1. [fix(antd/next): valueType should not be required attribute since it has default value (#3036)](https://github.com/alibaba/formily/commit/7b8669ba) :point_right: ( [戣蓦](https://github.com/戣蓦) )

1. [fix(antd/next): fix form tab type check issue (#3025)](https://github.com/alibaba/formily/commit/f0511355) :point_right: ( [戣蓦](https://github.com/戣蓦) )

1. [fix(antd): fix error, can't read 'length' of undefined (#3020) (#3021)](https://github.com/alibaba/formily/commit/10503b83) :point_right: ( [melodyYang](https://github.com/melodyYang) )

1. [fix(antd/next): fix cascader preview text exception errors (#3000)](https://github.com/alibaba/formily/commit/a48252b6) :point_right: ( [Janry](https://github.com/Janry) )
Expand Down Expand Up @@ -1274,8 +1282,6 @@

1. [fix(vue): fix a type error in ISchemaMarkupFieldProps (#1454)](https://github.com/alibaba/formily/commit/43abadc5) :point_right: ( [月落音阑](https://github.com/月落音阑) )

1. [fix(antd/next): fix layout context](https://github.com/alibaba/formily/commit/1bb9f1a0) :point_right: ( [janrywang](https://github.com/janrywang) )

1. [fix(core): fix the effects of IFormProps losing generic type (#1418)](https://github.com/alibaba/formily/commit/ee8d118d) :point_right: ( [liuwei](https://github.com/liuwei) )

1. [fix Form.submit miss return values (#1382)](https://github.com/alibaba/formily/commit/57c2c1b3) :point_right: ( [林法鑫](https://github.com/林法鑫) )
Expand Down Expand Up @@ -1410,6 +1416,8 @@

1. [fix(schema-editor): fix dependencies (#857)](https://github.com/alibaba/formily/commit/78f02c38) :point_right: ( [Janry](https://github.com/Janry) )

1. [fix(antd/next): fix button-group typings (#855)](https://github.com/alibaba/formily/commit/08077729) :point_right: ( [Janry](https://github.com/Janry) )

1. [fix(react): fix formSpy conflict with parent SchemaForm (#854)](https://github.com/alibaba/formily/commit/e122c9d9) :point_right: ( [Janry](https://github.com/Janry) )

1. [fix(antd/next): fix FormTextBox doesnot support className (#851)](https://github.com/alibaba/formily/commit/e40bdf2b) :point_right: ( [Janry](https://github.com/Janry) )
Expand Down Expand Up @@ -1462,6 +1470,8 @@

1. [fix: fix type lint (#628)](https://github.com/alibaba/formily/commit/8215d7f4) :point_right: ( [soulwu](https://github.com/soulwu) )

1. [fix(antd/next): fix antd/next table arr[0] path (#624)](https://github.com/alibaba/formily/commit/fb64eae7) :point_right: ( [WingGao](https://github.com/WingGao) )

1. [fix: 616 (#622)](https://github.com/alibaba/formily/commit/23ff1447) :point_right: ( [quirkyvar](https://github.com/quirkyvar) )

1. [fix(@uform/core/react): fix #613 #615 (#618)](https://github.com/alibaba/formily/commit/8dc609f9) :point_right: ( [Janry](https://github.com/Janry) )
Expand Down Expand Up @@ -1614,6 +1624,12 @@

### :memo: Documents Changes

1. [docs: fix contribution.zh-CN error (doc -> docs) (#3202)](https://github.com/alibaba/formily/commit/a4974d23) :point_right: ( [Akong](https://github.com/Akong) )

1. [docs(antd): fix Select component docs error (#3199)](https://github.com/alibaba/formily/commit/ee70cde1) :point_right: ( [微笑](https://github.com/微笑) )

1. [docs: delete useless code (#3198)](https://github.com/alibaba/formily/commit/8ef12b43) :point_right: ( [zhangrenyang](https://github.com/zhangrenyang) )

1. [docs: fix demo error (#3173)](https://github.com/alibaba/formily/commit/91e44698) :point_right: ( [PlutoCA](https://github.com/PlutoCA) )

1. [docs: update codesandbox templates that use the latest formily (#2980)](https://github.com/alibaba/formily/commit/7bb26f98) :point_right: ( [liuwei](https://github.com/liuwei) )
Expand Down
74 changes: 74 additions & 0 deletions packages/core/src/__tests__/array.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,7 @@ test('array field remove memo leak', async () => {
expect(initialValuesChange).toBeCalledTimes(0)
})

// add sandbox https://codesandbox.io/p/devbox/lingering-violet-jwr565
test('nest array remove', async () => {
const form = attach(createForm())

Expand Down Expand Up @@ -588,11 +589,84 @@ test('nest array remove', async () => {
expect(form.fields['metrics.0.content.0.attr']).not.toBeUndefined()
await metrics.remove(1)
expect(form.fields['metrics.0.content.0.attr']).not.toBeUndefined()
// TODO!! 测试不通过
expect(
form.initialValues.metrics?.[1]?.content?.[0]?.attr
).not.toBeUndefined()
})


test('nest array remove for #4024', () => {
const form = attach(createForm())
const arr1 = attach(
form.createArrayField({
name: 'aa',
initialValue: [{}],
})
)

attach(
form.createArrayField({
name: 'bb',
basePath: 'aa.0',
initialValue: [{}],
})
)

attach(
form.createField({
name: 'cc',
basePath: 'aa.0.bb.0',
initialValue: true,
})
)

expect(form.initialValues).toEqual({
aa: [{ bb: [{ cc: true }] }],
})

// 模拟两次 antd/ArrayBase.Addation 点击
attach(
form.createField({
name: 'cc',
basePath: 'aa.0.bb.1',
initialValue: true,
})
)
attach(
form.createField({
name: 'cc',
basePath: 'aa.0.bb.2',
initialValue: true,
})
)
// 符合 formily DevTools 表现
expect(form.initialValues).toEqual({
aa: [{ bb: [{ cc: true }, { cc: true }, { cc: true }] }],
})
// 模拟 antd/ArrayBase.Remove 点击
arr1.remove(0)

// 模拟一次外部数组点击 antd/ArrayBase.Addation 点击
attach(
form.createArrayField({
name: 'bb',
basePath: 'aa.0',
initialValue: [{}],
})
)
attach(
form.createField({
name: 'cc',
basePath: 'aa.0.bb.0',
initialValue: true,
})
)
expect(form.initialValues).toEqual({
aa: [{ bb: [{ cc: true }] }],
})
})

test('indexes: nest path need exclude incomplete number', () => {
const form = attach(createForm())

Expand Down
12 changes: 9 additions & 3 deletions packages/core/src/shared/internals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,17 @@ export const destroy = (
) => {
const field = target[address]
field?.dispose()
if (isDataField(field) && forceClear) {
if (isDataField(field)) {
const form = field.form
const path = field.path
form.deleteValuesIn(path)
form.deleteInitialValuesIn(path)
if (forceClear) {
form.deleteValuesIn(path)
}
// 在 schema 上有定义 initialValue (JSX prop name: default)
const shouldClearInitial = forceClear || !isUndef(field.props.initialValue);
if (shouldClearInitial) {
form.deleteInitialValuesIn(path)
}
}
delete target[address]
}
Expand Down

0 comments on commit 9311f49

Please sign in to comment.