Skip to content

Commit

Permalink
fix(core): fix form fields query throw error (#3992)
Browse files Browse the repository at this point in the history
* fix(core): fix form fields query throw error

* fix: fix ci

* fix: fix ci

* fix: fix ci

* fix: fix ci
  • Loading branch information
janryWang authored Oct 17, 2023
1 parent 2fc23dd commit 7477519
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 28 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name: Node CI

on:
push:
push:
branches:
- formily_next
pull_request:
pull_request:
branches:
- formily_next

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions packages/core/src/models/Query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
48 changes: 26 additions & 22 deletions packages/react/src/__tests__/field.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -306,30 +306,34 @@ test('fields unmount and validate', async () => {
}
return <div data-testid="unmounted"></div>
})
act(async () => {
const MyComponent = () => {
return (
<FormProvider form={form}>
<Field name="parent" component={[Parent]} />
</FormProvider>
)
}
render(<MyComponent />)
try {
await form.validate()
} catch {}
expect(form.invalid).toBeTruthy()

form.query('parent').take((field) => {
field.setState((state) => {
state.value.type = 'unmounted'
})
})
const MyComponent = () => {
return (
<FormProvider form={form}>
<Field name="parent" component={[Parent]} />
</FormProvider>
)
}
render(<MyComponent />)

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()
})
4 changes: 2 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -18075,7 +18075,7 @@ [email protected]:
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"
Expand Down Expand Up @@ -19613,7 +19613,7 @@ [email protected]:
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==
Expand Down

0 comments on commit 7477519

Please sign in to comment.