V7 Bug – Typescript performance issue on Field Array

Describe the bug

If

  1. A custom type is created to represent form values
  2. The type is of a certain structure
  3. The type is used as a generic in useForm,

then typescript compilation will slow down tremendously.

In larger apps with many useForms that take this generic, Node can run out of heap memory even with 8gb of allocated heap. I’ve created a code sandbox, but unfortunately, the issue can not really be observed there since we cannot track typescript compilation time (at least to my knowledge). Therefore, I’ve created a very simple sample project to show the issue.

To Reproduce
Steps to reproduce the behavior:

  1. Download the sample project.
  2. Run npm/yarn install
  3. Run npm/yarn start
  4. Observe the extremely long time it takes for typescript to compute results via react-scripts latest version

Codesandbox link (Required)
Use this
memory-issues.zip

might not help but included regardless.
https://codesandbox.io/s/summer-sunset-b2wwn?file=/src/App.tsx

Desktop (please complete the following information):

  • OS: Ubuntu 20.04 LTS

Additional Context
I copied over my types exactly. The issue is focused around using an object in a triple nested array. So line 51 in types.ts. If you remove the custom select type here and just use null, then the issue is improved exponentially.

1 possible answer(s) on “V7 Bug – Typescript performance issue on Field Array

  1. @wdfinch

    The old one allows any child item which is an array in a nested object might have length “0” -> “99” while the new one allows “0” -> “49” of length.