Commit 1dfbde8
authored
Upgrade react-hook-form and improve subnet pool member and IP range validation (#3188)
Resolvers are really for transforming form input into another shape. We
were using it for form-level cross-field validation. The new form-level
`validate` API added in
react-hook-form/react-hook-form#13195 is perfect
for what we were doing. It does not override existing validations and it
runs whenever validations are supposed to run (I think `resolver` only
runs on submit.
### Interesting changes in RHF
I had Claude go through the releases since the old version and summarize
the interesting stuff.
**Features worth a look**
-
[v7.69.0](https://github.com/react-hook-form/react-hook-form/releases/tag/v7.69.0)
`reset({ keepIsValid: true })` fix — the existing `keepIsValid` option
was buggy before. We don't currently use it but `SideModalForm`'s "name
already exists" flow uses `setError` in a post-submit effect; switching
to `errors` prop with focus
([v7.57.0](https://github.com/react-hook-form/react-hook-form/releases/tag/v7.57.0)
`focus form field for errors supplied by errors prop`) could be cleaner.
-
[v7.65.0](https://github.com/react-hook-form/react-hook-form/releases/tag/v7.65.0)
`<Watch />` +
[v7.68.0](https://github.com/react-hook-form/react-hook-form/releases/tag/v7.68.0)
`<FormStateSubscribe />` — render-prop components that re-render only
when a named field (or formState slice) changes. `instance-create.tsx`
and `firewall-rules-common.tsx` have lots of `useWatch` at the top
level; some of that churn could be isolated inside a `<Watch>`
render-prop. Worth trying only if profiling shows the re-renders hurt.
-
[v7.61.0](https://github.com/react-hook-form/react-hook-form/releases/tag/v7.61.0)
`useWatch({ compute })` — subscribe to the whole form but only surface a
derived value when a condition matches. Could collapse `useWatch +
useMemo` pairs. `instance-create.tsx:451-463` computes `bootDiskSource`
from four `useWatch` calls; a single `useWatch({ compute })` would work.
-
[v7.63.0](https://github.com/react-hook-form/react-hook-form/releases/tag/v7.63.0)
`getValues(undefined, { dirtyFields: true })` — extract only dirty
fields. Useful for PATCH-style edits; our edit forms mostly send the
full object so the win is small.
-
[v7.55.0](https://github.com/react-hook-form/react-hook-form/releases/tag/v7.55.0)
`createFormControl` / `subscribe` — subscribe to form state outside
React (e.g., from a store). Not obviously useful here.
-
[v7.56.0](https://github.com/react-hook-form/react-hook-form/releases/tag/v7.56.0)
reactive `mode` / `reValidateMode` — these become reactive to
re-renders. The firewall-rules `HACK` comment at
`firewall-rules-common.tsx:136-143` is specifically about the
validate/reValidate regime swap, but that HACK is about `isSubmitted`
state after reset, not about mode being non-reactive, so this doesn't
directly help.
**Bug that might have been biting us**
-
[v7.72.1](https://github.com/react-hook-form/react-hook-form/releases/tag/v7.72.1)
— `setValue` with `shouldDirty` no longer pollutes unrelated dirty
fields. We use `setValue` heavily (silo-create, idp-create,
instance-create); if any of those use `shouldDirty` we likely had
ghost-dirty fields.
- This sounds really familiar...........
-
[v7.66.1](https://github.com/react-hook-form/react-hook-form/releases/tag/v7.66.1)
— `deepEqual` uses `Object.is` for NaN. `subnet-pool-member-add` stores
`NaN` as the unset state for optional NumberFields — pre-fix, `isDirty`
might have flipped on those.
-
[v7.69.0](https://github.com/react-hook-form/react-hook-form/releases/tag/v7.69.0)
— race between `setError` and `setFocus` resolved. Relevant to our
`SideModalForm` effect that calls both.1 parent 93ae439 commit 1dfbde8
8 files changed
Lines changed: 136 additions & 148 deletions
File tree
- app
- components/form/fields
- forms
- test/e2e
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
65 | 65 | | |
66 | 66 | | |
67 | 67 | | |
| 68 | + | |
68 | 69 | | |
69 | 70 | | |
70 | 71 | | |
| |||
83 | 84 | | |
84 | 85 | | |
85 | 86 | | |
| 87 | + | |
86 | 88 | | |
87 | 89 | | |
88 | 90 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
| |||
45 | 46 | | |
46 | 47 | | |
47 | 48 | | |
| 49 | + | |
48 | 50 | | |
49 | 51 | | |
50 | 52 | | |
| |||
98 | 100 | | |
99 | 101 | | |
100 | 102 | | |
| 103 | + | |
101 | 104 | | |
102 | 105 | | |
103 | 106 | | |
| |||
109 | 112 | | |
110 | 113 | | |
111 | 114 | | |
112 | | - | |
| 115 | + | |
113 | 116 | | |
114 | 117 | | |
115 | 118 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
| 8 | + | |
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
88 | 42 | | |
89 | 43 | | |
90 | 44 | | |
| |||
107 | 61 | | |
108 | 62 | | |
109 | 63 | | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
| 64 | + | |
114 | 65 | | |
115 | 66 | | |
116 | 67 | | |
| |||
132 | 83 | | |
133 | 84 | | |
134 | 85 | | |
| 86 | + | |
135 | 87 | | |
136 | 88 | | |
137 | 89 | | |
138 | 90 | | |
139 | 91 | | |
140 | 92 | | |
| 93 | + | |
141 | 94 | | |
142 | 95 | | |
143 | 96 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
11 | 11 | | |
12 | | - | |
13 | | - | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
14 | 16 | | |
15 | 17 | | |
16 | 18 | | |
17 | | - | |
| 19 | + | |
18 | 20 | | |
19 | | - | |
20 | | - | |
| 21 | + | |
| 22 | + | |
21 | 23 | | |
22 | 24 | | |
23 | | - | |
| 25 | + | |
24 | 26 | | |
25 | | - | |
| 27 | + | |
26 | 28 | | |
27 | 29 | | |
28 | 30 | | |
29 | | - | |
| 31 | + | |
30 | 32 | | |
31 | 33 | | |
32 | 34 | | |
33 | 35 | | |
34 | | - | |
| 36 | + | |
35 | 37 | | |
36 | 38 | | |
37 | 39 | | |
38 | | - | |
| 40 | + | |
39 | 41 | | |
40 | 42 | | |
41 | 43 | | |
42 | 44 | | |
43 | | - | |
| 45 | + | |
44 | 46 | | |
45 | 47 | | |
46 | 48 | | |
47 | | - | |
| 49 | + | |
48 | 50 | | |
49 | 51 | | |
50 | 52 | | |
51 | 53 | | |
52 | | - | |
| 54 | + | |
53 | 55 | | |
54 | 56 | | |
55 | 57 | | |
56 | 58 | | |
57 | | - | |
| 59 | + | |
58 | 60 | | |
59 | 61 | | |
60 | 62 | | |
61 | 63 | | |
62 | | - | |
| 64 | + | |
63 | 65 | | |
64 | 66 | | |
65 | 67 | | |
66 | 68 | | |
67 | | - | |
| 69 | + | |
68 | 70 | | |
69 | 71 | | |
70 | 72 | | |
71 | 73 | | |
72 | | - | |
| 74 | + | |
73 | 75 | | |
74 | 76 | | |
75 | 77 | | |
76 | 78 | | |
77 | | - | |
| 79 | + | |
78 | 80 | | |
79 | 81 | | |
80 | 82 | | |
81 | 83 | | |
82 | | - | |
| 84 | + | |
83 | 85 | | |
84 | 86 | | |
85 | 87 | | |
86 | 88 | | |
87 | 89 | | |
88 | 90 | | |
89 | | - | |
| 91 | + | |
90 | 92 | | |
91 | 93 | | |
92 | 94 | | |
93 | 95 | | |
94 | | - | |
| 96 | + | |
95 | 97 | | |
96 | 98 | | |
97 | 99 | | |
| |||
0 commit comments