-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Using styled components with formik is incredibly slow #1026
Comments
@mjangir We are having the same issues. Using debounce to handle this. |
I may not have as many styles as you do, but I do have all custom components. I saw this in another thread and it turned out to be true (runs as normal/faster in production) |
I'm seeing the same issue with one input in a form which is a styled component - pressing and holding any key causes a large and noticeable lag |
Incidentally, I've tried using |
@joycollector, where are you placing the |
I am having this issue as well. I tried I was thinking I may have to use vanilla CSS with Formik to fix this bug. |
I've had similar major performance issues with relatively short forms: a custom drop down and 4-5 custom input fields. I'm using tailwind.js (similar to styled components) and Yup for validation. |
Same issue here, I can confirm that production is not affected. It lags only in dev mode. |
That’s interesting. Can you / someone reproduce this behavior in a sandbox? |
I haven't check, but trying around a bit I think that production is affected too, but way less than dev. |
Same issue here, production is effected - but way less |
same but fastfield helped and in prod it's acceptable |
same issue. |
This should be fixed with 1.4.0. https://github.com/jaredpalmer/formik/releases/tag/v1.4.0 |
Thanks!
…On Sat, Dec 8, 2018, 6:05 PM Jared Palmer ***@***.*** wrote:
This should be fixed with 1.4.0.
https://github.com/jaredpalmer/formik/releases/tag/v1.4.0
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#1026 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAUMymNcVbyIH279-kv0xp7TJ2TU8EFiks5u3EXTgaJpZM4XxuvD>
.
|
Hmm, not seeing any improvement on 1.4.0 for me. A single key press is causing 2 renders: This is the code for the form:
I appreciate this is not very helpful without a repro, will try and get one up and running this weekend. |
@jaredpalmer Awesome! So I just upgraded to 1.4.1 and the good news is that the double re-render for a single key press is fixed, and the form input speed is now acceptable on small forms (3 or less inputs). The bad news is that on forms with 5 or more inputs, the performance issue remains (typing is slow, pressing and holding a key freezes the UI). Will investigate more. |
thanks @johnmcdowall I have same issue :( |
I'm also still experiencing the same issues after upgrading to 1.4.1. In my case the unnecessary re-renders are really limited to the components using styled-components. But, it only effects styled-components that are within the scope of the formik's |
Hi @jaredpalmer for me there is a marked improvement in 1.4.1, so thank you for that. I went from 3 renders to 2, which I suppose made it 33% faster. Overall, I think the onus is on styled components more than on you. |
@baleeds Are you using styled-components in your Formik forms? Because this performance issue didn't happen for me when using other React form libraries, or just standard forms, so there would seem to be a Formik specific issue here... |
Apparently styled-components are always rerendering if the parent component triggers a rerender (See styled-components/styled-components#1723). In my case, I have quite a lot of styled components inside the form, which are all being rerendered as soon as a value changes, since they're stored in the form's state. So the solution probably lies in the use of wrapper components (e.g. PureComponent's) around the parts that use styled components to avoid rerenders manually. |
@johnmcdowall we are using styled components throughout the whole app, which includes inside of formik forms. My observation is that styled components are slow because they cause things that don't need to be components to be components, which means more render functions run (in our case, WAY more, since almost all html elements are SC). |
@baleeds is correct. styled-components also hooks every single component into context for theming...slowing down things even more. |
@jaredpalmer Just an update: after updating a bunch of libs and tweaking my base style class things seem to be pretty rocking now, no noticeable lags for me anymore 👍 |
@baleeds Yeah exactly, I used the profile as well to narrow down that my base style entity was causing too many re-renders (along with the previous Formik [now fixed] multiple re-renders). |
Maybe this helps a bit meanwhile? https://travix.io/using-recompose-hocs-to-get-better-performance-in-forms-using-formik-and-yup-e51024d645ba |
Now to use it, [link to gist]
That way sync happens only when user blurs and the field maintains it's state internally while user is typing. |
I managed to achieve the same result as @rohanBagchi , I've been experimenting with the next v2.0.1-rc13 hooks. Instead of
With this, you can spread the fields and properties just like you do in useField
|
I noticed that on every key stroke two values always change:
I used Jakob Rask's trace code:
|
@mblarsen I am reading Formik's code, it seems that
Could it be that |
That would surely explain the inequality of the errors, despite being unchanged. |
Same issue for my form with over 1K fields.
|
Same issue here!, I just have only five fields, if remove handleBlur trigger, the performance change is several. |
Try https://react-hook-form.com/ easier to use and no more lag :) |
Thanks!!! A lot!! |
A few things I have noticed that cause a slow form, and how to fix them...
The above stops all inputs but the one you are typing into re-rendering. Formik still performs all its calculations on every keypress, change, blur etc... but only the component being manipulated is rendered. Other on the page do not. |
@mattsputnikdigital is spot on with the above solutions. In general, any CSS-in-JS library that does runtime style calculations are slow. To add insult to injury, many CSS-in-JS solutions require you to use a For a more detailed analysis of the issue, see this article: https://calendar.perfplanet.com/2019/the-unseen-performance-costs-of-css-in-js-in-react-apps/ So what can be done:
|
You can try in formik SetFieldValue('fieldname', value, false) you can set shouldvalidate to false |
I'm just playing with formik library and found performance issue with custom component in Field tag when the custom component uses styled components heavily.
When I keep pressing the key in an input box which is wrapped in multiple hierarchy of styled components, it causes huge lagging but instead of that, if I use simple divs, it is comparatively faster.
The text was updated successfully, but these errors were encountered: