Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: rendering optimization #337

Open
1 of 4 tasks
mschipperheyn opened this issue Nov 10, 2023 · 2 comments
Open
1 of 4 tasks

[Bug]: rendering optimization #337

mschipperheyn opened this issue Nov 10, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@mschipperheyn
Copy link

Which packages are impacted?

  • remix-validated-form
  • @remix-validated-form/with-zod
  • @remix-validated-form/with-yup
  • zod-form-data

What version of these packages are you using?

  • remive-validated-form: 5.1.5

Please provide a link to a minimal reproduction of the issue.

I'm taking the time to review the issue and write this up.

Steps to Reproduce the Bug or Issue

None of the callback functions used in the app, but in particular onChange and onBlur support useCallback. From what I can tell this leads to a lot of unnecessarily deep rerenders of components.

To reproduce, Install the React profiler and start editing a form. You will see that the cause of rerenders is listed as onChange and onBlur

But the code already suggests this clearly

onChange: (...args: unknown[]) => {
        if (behavior === "onChange") validate();
        else clearError();
        return props?.onChange?.(...args);
      },
      onBlur: (...args: unknown[]) => {
        if (behavior === "onBlur") validate();
        setTouched(true);
        return props?.onBlur?.(...args);
      },

Expected behavior

This could should be supported by useCallback to ensure that passing a new callback and blur identity to a child component does not force a rerender each and every time.

Screenshots or Videos

No response

Platform

  • OS: mac os
  • Browser: Chrime

Additional context

No response

@mschipperheyn mschipperheyn added the bug Something isn't working label Nov 10, 2023
@patrickpissurno
Copy link

Any updates on this?

@airjp73
Copy link
Owner

airjp73 commented Mar 15, 2024

Hi!

It isn't clear from the issue description what needs to be fixed. The referenced code is inside createGetInputProps which already gets memoized where it's used.

In order to help, I'm going to need a more detailed reproduction of the issue. In what specific situation are you observing more renders than there should be?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants