Skip to content
This repository has been archived by the owner on Feb 21, 2023. It is now read-only.

Warning: unstable_flushDiscreteUpdates #40

Open
iongion opened this issue Aug 21, 2019 · 25 comments
Open

Warning: unstable_flushDiscreteUpdates #40

iongion opened this issue Aug 21, 2019 · 25 comments

Comments

@iongion
Copy link

iongion commented Aug 21, 2019

For react deps:

    "react": "^16.9.0",
    "react-block-ui": "^1.3.1",
    "react-color": "^2.17.3",
    "react-dom": "^16.9.0",

There is now this warning showing up

Warning: unstable_flushDiscreteUpdates: Cannot flush updates when React is already rendering.
    in BlockUi
@TheSharpieOne
Copy link
Collaborator

Looks like it has something to do with the focus calls based on this code comment: https://github.com/facebook/react/blob/c80678c7606b1895573c23182bfb9a418e2ad31e/packages/react-reconciler/src/ReactFiberWorkLoop.js#L605-L607

I'm not sure how to address this.

@goxr3plus
Copy link

What is happening with this issue guys ?

@GoPro16
Copy link
Contributor

GoPro16 commented Oct 15, 2019

What is happening with this issue guys ?

No one has picked up this issue if you want to take it. Just a warning so not a top concern.

@goxr3plus
Copy link

We are full of warnings bro

@vitaly-redkin
Copy link

Looks like it has something to do with the focus calls based on this code comment: https://github.com/facebook/react/blob/c80678c7606b1895573c23182bfb9a418e2ad31e/packages/react-reconciler/src/ReactFiberWorkLoop.js#L605-L607

I'm not sure how to address this.

In my private fork I have replaced
if (typeof this.focused.focus === 'function') { this.focused.focus(); }
with
if (typeof this.focused.focus === 'function') { const focusedControl = this.focused; window.setInterval(() => { focusedControl.focus(); }, 100); }

A hack, no doubt, but seems to be working so far,,,

@goxr3plus
Copy link

@vitaly-redkin Can you please make a pull request for that ? :) Thank you

@vitaly-redkin
Copy link

@vitaly-redkin Can you please make a pull request for that ? :) Thank you

I probably can but what is the point? The PR to use UNSAFE_ methods for componentWillXXX (#46) is not merged - and probably will not.

My local version has both UNSAFE_ and "wrap this.focusedControl.focus() into setTimeout()" changes so it will break the same tests as the previous PR did. So it will not be merged, etc.

Personally I made my change to serve as a temporary solution and waiting for the hooks rewrite...

@goxr3plus
Copy link

goxr3plus commented Nov 4, 2019

Yes i understand . How about you pull reuqest only the wrap this.focusedControl.focus() into setTimeout() , i am having that annoying errors in production code .

@vitaly-redkin
Copy link

Will do but a bit later - really tied up right now...

@goxr3plus
Copy link

@vitaly-redkin No prob fill free to drop a pull request when you have time :)

@Adam-Asatryan
Copy link

any updates here ?

@goxr3plus
Copy link

@Adam-Asatryan Vitaly got married i think.

@mehmetkasalak
Copy link

Will there be any progress?

@GoPro16
Copy link
Contributor

GoPro16 commented Dec 25, 2019

No it’s Christmas 🎄

@goxr3plus
Copy link

goxr3plus commented Dec 25, 2019 via email

@joeheror
Copy link

I use BlockUi with redux-saga to block screen when fetching data from back-end.
I thought this warning happens when the fetching time is too short.
So I delayed some time after data is fetched but the result was same even with delaying time more than 1 or 3 seconds.
On the other hand, stating BlockUi with button, no warning happens even though I click the buttons twice as quick as possible.
I don't understand why it actually happens.

@diegodesouza
Copy link

Yeah, I'm experiencing the same thing
react-block-ui: 1.1.3

@skworden
Copy link

skworden commented Mar 5, 2020

@Joe-Cristop it's happening because the dom (in this case x.focus()) is being manipulated outside of react before react has time to finish its rendering process. Adding a slight delay is why the timeout works in most cases.

I had a similar issue on unrelated code but google lead me here. I was able to fix a similar issue in my code using the useEffect hook with the proper dependencies. However, this looks to be a class so calling the focus in the appropriate render stage (didmount/updated/ etc) with the appropriate condition check should eliminate the error.

my og code with the error
if(!open && ref.current){ ref.current.focus(); }

updated code without error
useEffect(()=>{ if(!open && ref.current){ ref.current.focus(); } }, [open]);

I don't use this library and Idk what is calling your update but maybe this helps y'all out.

@whitecobalt
Copy link

A fix to this would be welcome

@thushan85
Copy link

I'm getting the same issue in 1.3.3. Are there any fix?

@moc89
Copy link

moc89 commented Sep 4, 2020

I found why it is happening; in my case below;
When I remove value={name} ;It works well.
But when I re-render this element, I want to use in the state value. Is there any other way to use state value when I render this element again? Because currently, it is getting ustable_flushDiscreteUpdates.

My so simple example;

<TextField id="name" onChange={(e: React.ChangeEvent<HTMLTextAreaElement>) => setName(e.target.value)} value={name}> </TextField>

@shunyh
Copy link

shunyh commented Jan 7, 2021

"react-block-ui": "^1.3.3" has the same issue, any update?

@rixant
Copy link

rixant commented Feb 17, 2022

Did anyone find the solution to this issue? I am using "react-block-ui": "^1.3.3"

@rickhanlonii
Copy link

I don't have a repro - but based on the above example the issue may be that you're calling focus inside of render, instead of an effect.

@rtnario
Copy link

rtnario commented Jul 26, 2022

Was encountering this issue on React 17. After following lifedup's advice on using proper useEffect hooks, and also checking dapabe's mention and updating to React 18, I no longer experience the issue.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests