You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have seen some Github issues (open and closed) about problems with type recursion and some improvements that may come in v8. I have a use case where it has only one level of recursion but it is causing significant performance issues. I am wondering if anyone has any suggestions to work around this until v8 comes out.
Hot Spots
└─ Check file /home/projects/vitejs-vite-b8aq7akf/src/Form.tsx (1140ms)
└─ Check deferred node from (line 26, char 5) to (line 28, char 20) (714ms)
└─ Determine variance of type 19189 (652ms)
└─ {"id":19189,"kind":"GenericTypeAlias","name":"UseFormResetField","aliasTypeArguments":[19190],"location":{"path":"/home/projects/vitejs-vite-b8aq7akf/node_modules/react-hook-form/dist/types/form.d.ts","line":507,"char":1}}
└─ {"id":19190,"kind":"TypeParameter","name":"TFieldValues","location":{"path":"/home/projects/vitejs-vite-b8aq7akf/node_modules/react-hook-form/dist/types/form.d.ts","line":507,"char":31}}
In my real repo, it detects hotspots of 7+ seconds 🫠 and it flags usages of useFieldArray() and useWatch() on this nested field. In the real repo, I also get Type instantiation is excessively deep and possibly infinite. when I try to do setValue() on the that field.
This all surprises me coz the form schema type is not even infinitely recursive (only 1 level).
My workaround with similar cases in the past was to entirely move the type out RHF and replace it with unknown, and then cast on access (ugly, I know). This is less an option with the above ☝️ case, if you still want to use things like useFieldArray().
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I have seen some Github issues (open and closed) about problems with type recursion and some improvements that may come in v8. I have a use case where it has only one level of recursion but it is causing significant performance issues. I am wondering if anyone has any suggestions to work around this until v8 comes out.
Here is a minimal repo: https://stackblitz.com/edit/vitejs-vite-b8aq7akf?file=src%2FForm.tsx
You can run the following to see the hotspots:
This is what I got:
In my real repo, it detects hotspots of 7+ seconds 🫠 and it flags usages of
useFieldArray()
anduseWatch()
on this nested field. In the real repo, I also getType instantiation is excessively deep and possibly infinite.
when I try to dosetValue()
on the that field.This all surprises me coz the form schema type is not even infinitely recursive (only 1 level).
My workaround with similar cases in the past was to entirely move the type out RHF and replace it with
unknown
, and then cast on access (ugly, I know). This is less an option with the above ☝️ case, if you still want to use things likeuseFieldArray()
.Beta Was this translation helpful? Give feedback.
All reactions