skorphil / nextjs-form

Educational NextJs project to build a complex mobile-first form
https://www.chromatic.com/library?appId=65b2882ac1586a6b21cba0dd
MIT License
3 stars 0 forks source link

Poor performance of inputs on mobile #53

Closed skorphil closed 4 months ago

skorphil commented 4 months ago

Inputs on mobile slowly respond to user input. lag

skorphil commented 4 months ago

Works fine in storybook

skorphil commented 4 months ago

After audit in rect dev tools profiler, i noticed 2 causes of this

I think further tweaking may help (creating an external form provider or excluding formState from context)

For now lower the priority, cause the main problem was in use-hook-form devtools were enabled

skorphil commented 4 months ago

Fix everything by excluding unnecessary formStates:{dirtyFields} from children components

skorphil commented 4 months ago

Again not working after some refactoring https://www.reddit.com/r/react/comments/1b0jhii/usehookform_rerenders_component_without_any/

Got bug with rerendering of RecordForm after these changes https://github.com/skorphil/nextjs-form/commit/22a67fec42e40c16edbd5b62de6343423c0e18cb

skorphil commented 4 months ago

{ watch } = useForm() re-rendered root component RecordForm, causing horrible performance. While utilising useWatch() allowed to re-render only component which is using it Reddit thread: https://www.reddit.com/r/react/comments/1b0jhii/comment/ks897ms/?context=3 useWatch docs: https://react-hook-form.com/docs/usewatch