-
-
Notifications
You must be signed in to change notification settings - Fork 482
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
Warning: Cannot update a component from inside the function body of a different component. #751
Comments
I'm also seeing this warning after updating to React 16.13.0. For me, it only seems to occur when a field is conditionally rendered. Sandbox link: https://codesandbox.io/s/empty-forest-6m0ri?fontsize=14&hidenavigation=1&theme=dark |
A good example of this happening is the Wizard Form Example. Any time the Previous or Next buttons are pressed, just about every Field from all pages throws this warning. |
Yes, I got this error for a select box that is dynamically rendered. |
Same error here. Using final-form-array produces this error as well. |
Not a fix. But i realized that when i added the |
A lot of popular libraries are affected by this warning : facebook/react#18178 |
I did some analysis on this issue and found the source of the problem, at least for conditionally rendered fields, but this might also be the cause in other cases: react-final-form/src/useField.js Lines 90 to 105 in f3c1aea
In here, the field is synchronously registered, which causes a synchronous update to the form state, which in turn synchronously triggers react-final-form/src/ReactFinalForm.js Line 97 in f3c1aea
So what it boils down to is that the mounting of a |
So, after looking (and trying to understand what the heck all the code is doing), my personal conclusion is this:
Upside of this idea: very easy to implement (just a couple of lines have to be changed), almost no side-effects. Personally, I see no other way to fix this problem, I'd love to hear the thoughts of one of the maintainers about this issue. If they'd agree with my conclusion, I'd go ahead and write a pull request, or they can implement that fix. |
@erikras, any take on below approach?
|
@yann-combarnous, @erikras Any update on this? |
I am not a maintainer, just an interested party like you :). |
I spent a whole day looking for a solution for this issue and so far I manage to silent this error by pausing the form validations with Adding something like do the trick: pauseValidation();
useEffect(() => resumeValidation(), [resumeValidation]); But, final-form is overriding the |
That seems more like a workaround instead of actually solving the problem (like my recommendation would). Still waiting on a word from the maintainer though :) |
Hi guys. Sorry to be so late on this. I got laid off at work and have had two children locked in the house with me for weeks.
A lot have work has been done to ensure that things look right "on first render", which is why things are the way they are. This is going to be a major breaking change. I just tried it and 75% of the unit tests failed.
Yep. This needs more investigation. |
No worries, everything will be fine @erikras . 🍻 |
Don't understand how an elite developer like you would be laid off, even
now... Also, try Upwork. With your resume, you should be making a lot of
money immediately working remotely.
…On Mon, Mar 30, 2020, 6:46 AM Erik Rasmussen ***@***.***> wrote:
Hi guys. Sorry to be so late on this. I got laid off at work and have had
two children locked in the house with me for weeks.
Upside of this idea: very easy to implement (just a couple of lines have
to be changed), almost no side-effects.
A lot have work has been done to ensure that things look right "on first
render", which is why things are the way they are. This is going to be a
major breaking change. I just tried it and 75% of the unit tests failed.
Downside: it changes the useField() API, which is a public one, so this
would affect projects using it directly instead of the Field component.
Yep.
This needs more investigation.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#751 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AC2O764S54EQ7INNMQ5UGLTRKCBBFANCNFSM4K7IAAGQ>
.
|
Yeah, I'm gonna get a job quickly; have several offers already, but it still adds additional stress to the already elevated global level. Companies restructure and my position disappeared out from under me. Wasn't to do with my performance or skill level. |
Another idea, but that one's kinda hacky, which is why I didn't propose it: Have the |
I have some good news for you guys.... |
@erikras Just looking at the code and it is a tad bit hard to follow for me... would you mind explaining why notifyFieldListeners() has an optional 'name' passed into it and the usage there? It is called quite a bit and seems to only get name passed in when silent is true now? Not sure what 'safeFields' is. |
Published fix in Summary:
That means "only notify listeners to this one field". It doesn't seem to have any other usages, so it's vestigial from an earlier time, but it's just what was needed in this case.
Yes. The rest of the times, it really does need to notify all the other fields, as they can depend on each other.
A copy of the fields structure must be made to iterate through, since some of the things that get called can result in fields being unregistered. |
@erikras Thank you so much for the clarification, that helps a lot! |
@erikras I noticed that the |
I'm still having issues with the new version, also using fields with validation. |
Same here, i've upgraded to the newest versions of final-form and the issue still remains. |
Published an example sandbox, see #768 . As mentioned by other users above, this seems to be linked to validators. |
Published fix in |
Thanks @erikras . Still getting one scenario where this error shows up, it seems. Seems to happen on submit when form.registerField is used. Replacing it with OnChange from react-final-form-listeners also seems to not trigger the error. Will try and narrow down the specific pattern, have made a short try today at a CodeSandbox, with no luck so far. Stack trace: |
I have seen a reduction in these errors in my app, but they are not completely eliminated. I have a form that shows some assumed values and gives the user the option to edit them by clicking on a link to make the form fields appear. Previously, that click would throw a couple of these errors (I think 2 or 3? odd since there are 5 fields). Those errors no longer appear. However, that form also includes a checkbox that, when toggled a certain way, adds an additional field. Adding that additional field is still throwing the error. I'm not a frequent user of CodeSandbox, but hopefully I've done this right. The sandbox from @jsalis demonstrated my issue (checkbox to make field appear) so I forked it and updated the final-form version to 4.19.1, and the error still happens there: https://codesandbox.io/s/react-16130-final-form-warning-tnid2 |
@atuttle yep I have the very same error with checkbox adding a new Field. :) |
You also need to upgrade react-final-form to 6.4.0. |
That fixed it for me, thanks! (@callmeberzerker fyi) |
I'm seeing this when using I've solved it temporarily by wrapping the offending function in
Larger section of code for context:
|
I have created a generic dropdown menu component using (Material-Ui Autocomplete), so I can use where I need. But I am facing a warning, "Warning: Cannot update a component ( Note I followed different links but couldn't get the proper answer I have a slightly different scenario. I have created a generic dropdown menu component and use inside other components where needed. Here is code of dropdown menu component
Here is the code of Component in which I am using dropdown menu component `
` |
I have the same issue with ff 4.19.1 and rff 6.5.0. I have not found a way to read the form state from outside my component safely. Is there a workaround? |
Looks like I am seeing the same issue with:
|
I've been encountering this too with field validation updating the form. Package versions: "final-form": "^4.20.1",
"final-form-arrays": "^3.0.2",
"react-final-form": "^6.5.1",
"react-final-form-arrays": "^3.1.2", Console error:
For the time being, I've had to resort to the workaround suggested by @lfantone - feels almost hacky, but works wonderfully. pauseValidation();
useEffect(() => resumeValidation(), [resumeValidation]); |
where did u use that useeffect?? i am using form with render props |
Are you submitting a bug report or a feature request?
bug report
What is the current behavior?
After npm upgrading to the latest React, I am getting the following warning in my console from the React Developer tools Chrome extension:
"Warning: Cannot update a component from inside the function body of a different component."
The component trace just points to a line with a boring/standard use of
Field
in JSX. Quickly going through the app I'm working on, this warning happens everywhere, on every use ofField
in the app. For example, the warnings point to lines like the 2nd to last line (RadioField = ...
) of this file (please excuse the coding style here). Again, there is nothing special about this code; it's happening on everyForm
that has components that useField
.What is the expected behavior?
No warning
Sandbox Link
I'll make one if you need it, but I think the link below in Other Information succinctly explains what is happening and a hooks based workaround that react-final-form can implement.
What's your environment?
ChromeOS 79
React 16.13.0 released Feb 26th, 2020
Final Form 4.18.7
React Final Form 6.3.5
Other information
See here: https://reactjs.org/blog/2020/02/26/react-v16.13.0.html#warnings-for-some-updates-during-render
The text was updated successfully, but these errors were encountered: