T
TanStack•2mo ago
xenial-black

Unnecessary rerendering of fields caused by validation libs

I noticed some unexpected rerendering and wanted to know if this is the intended behavior. In the Form Composition example, when you continuously type into any field, it only ever rerenders that field. Even when others fields are still invalid. https://tanstack.com/form/latest/docs/framework/react/examples/large-form However, this is not the case for the Standard Schema example. When you continuously type into field1, field2 will also rerender while it is invalid. If you make field2 valid and go back to typing in field1, then field2 no longer rerenders. This behavior is the same no matter which validation lib you switch between. https://tanstack.com/form/latest/docs/framework/react/examples/standard-schema In both examples, the only validators option is being set is for the useForm hook, specifically validating on onChange events only. I suspect the reason for this difference in rerendering behavior is due to Form Composition validations returning string | undefined vs. Standard Schema validations returning StandardSchemaV1Issue | undefined. And we are not using deep equality on the StandardSchemaV1Issue objects? Is there anything that can be done to reducing the rerendering without setting validations on each field one-by-one?
4 Replies
xenial-black
xenial-black•2mo ago
sounds related to https://github.com/TanStack/form/issues/1625 what's likely happening is that a shallow comparison is made for the two-layered deep object (either the array of standard schema issues, or the issue's path parameter being an array) and failing
GitHub
Using zod schema as a form level onChange validator causes form ele...
Describe the bug Let's consider the example from the documentation which uses a zod schema as its form-level onChange validator: https://tanstack.com/form/latest/docs/framework/react/examples/s...
xenial-black
xenial-blackOP•2mo ago
Yea this is definitely the same issue as the one you link 😅 Is this issue planning to be addressed?
xenial-black
xenial-black•2mo ago
of course, there‘s just a lot to tackle at the moment it‘s not labeled as bug because I haven‘t checked the reproducible example yet, but I see no reason to doubt it
xenial-black
xenial-blackOP•2mo ago
Awesome, thank you 🙂

Did you find this page helpful?