From 74775198fb34143b84f19b03c5b6b0c277deb316 Mon Sep 17 00:00:00 2001 From: Janry Date: Tue, 17 Oct 2023 21:33:39 +0800 Subject: [PATCH] fix(core): fix form fields query throw error (#3992) * fix(core): fix form fields query throw error * fix: fix ci * fix: fix ci * fix: fix ci * fix: fix ci --- .github/workflows/ci.yml | 6 +-- .github/workflows/release.yml | 2 +- packages/core/src/models/Query.ts | 4 ++ packages/react/src/__tests__/field.spec.tsx | 48 +++++++++++---------- yarn.lock | 4 +- 5 files changed, 36 insertions(+), 28 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9c5dddb66c1..3288f7de622 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,10 +1,10 @@ name: Node CI on: - push: + push: branches: - formily_next - pull_request: + pull_request: branches: - formily_next @@ -14,7 +14,7 @@ jobs: if: contains(github.event.head_commit.message, 'chore(versions)') == false strategy: matrix: - node_version: [10.x, 11.x] + node_version: 16 os: [ubuntu-latest] steps: - uses: actions/checkout@v1 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e85ce8f479c..faf9b25c6b6 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -15,7 +15,7 @@ jobs: ref: formily_next - uses: actions/setup-node@v1 with: - node-version: 12 + node-version: 16 registry-url: https://registry.npmjs.org/ - run: | yarn -v diff --git a/packages/core/src/models/Query.ts b/packages/core/src/models/Query.ts index a86bb411069..bcbdbef5bcb 100644 --- a/packages/core/src/models/Query.ts +++ b/packages/core/src/models/Query.ts @@ -45,6 +45,10 @@ export class Query { } } else { each(this.form.fields, (field, address) => { + if (!field) { + delete this.form.fields[address] + return + } if (field.match(this.pattern)) { this.addresses.push(address) } diff --git a/packages/react/src/__tests__/field.spec.tsx b/packages/react/src/__tests__/field.spec.tsx index 917755e9de8..b5503651ce5 100644 --- a/packages/react/src/__tests__/field.spec.tsx +++ b/packages/react/src/__tests__/field.spec.tsx @@ -306,30 +306,34 @@ test('fields unmount and validate', async () => { } return
}) - act(async () => { - const MyComponent = () => { - return ( - - - - ) - } - render() - try { - await form.validate() - } catch {} - expect(form.invalid).toBeTruthy() - form.query('parent').take((field) => { - field.setState((state) => { - state.value.type = 'unmounted' - }) - }) + const MyComponent = () => { + return ( + + + + ) + } + render() - await waitFor(() => { - expect(fn.mock.calls.length).toBe(1) - }) + try { await form.validate() - expect(form.invalid).toBeFalsy() + } catch {} + + expect(form.invalid).toBeTruthy() + + form.query('parent').take((field) => { + field.setState((state) => { + state.value.type = 'unmounted' + }) + }) + + await waitFor(() => { + expect(fn.mock.calls.length).toBe(1) }) + + try { + await form.validate() + } catch {} + expect(form.invalid).toBeTruthy() }) diff --git a/yarn.lock b/yarn.lock index ee16d0858df..b40d1c57ae2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -18075,7 +18075,7 @@ serve-static@1.15.0: set-blocking@~2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/set-blocking/-/set-blocking-2.0.0.tgz#045f9782d011ae9a6803ddd382b24392b3d890f7" - integrity sha1-BF+XgtARrppoA93TgrJDkrPYkPc= + integrity sha512-KiKBS8AnWGEyLzofFfmvKwpdPzqiy16LvQfK3yv/fVH7Bj13/wl3JSR1J+rfgRE9q7xUJK4qvgS8raSOeLUehw== set-value@^2.0.0, set-value@^2.0.1: version "2.0.1" @@ -19613,7 +19613,7 @@ tty-browserify@0.0.0: resolved "https://registry.yarnpkg.com/tty-browserify/-/tty-browserify-0.0.0.tgz#a157ba402da24e9bf957f9aa69d524eed42901a6" integrity sha1-oVe6QC2iTpv5V/mqadUk7tQpAaY= -ttypescript@^1.5.15: +ttypescript@1.5.15, ttypescript@^1.5.15: version "1.5.15" resolved "https://registry.yarnpkg.com/ttypescript/-/ttypescript-1.5.15.tgz#e45550ad69289d06d3bc3fd4a3c87e7c1ef3eba7" integrity sha512-48ykDNHzFnPMnv4hYX1P8Q84TvCZyL1QlFxeuxsuZ48X2+ameBgPenvmCkHJtoOSxpoWTWi8NcgNrRnVDOmfSg==