-
Notifications
You must be signed in to change notification settings - Fork 47.4k
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
Hooks: callback in useEffect is not always fired in same time. #14354
Comments
I'm new to React, but your output to me looks correct. In both cases we have -> You can ignore the mounted parts, because it's not even part of the React component. From what I can tell, React is not totally synchronous, it uses a fiber a stack. I'm assuming this is prevent successive DOM comparisons on multiple setStates etc. So what I would suggest is that you treat In fact I wouldn't be surprised if you had a result like -> Seen as your doing this on two separate mount points. |
@KpjComp This issue show I just hope it could be always asynchronous or always synchronous. It is fine to forcing to write testing cases asynchronous. test("test App", async () => {
const node = await mount(<App />);
console.log("mounted", node.innerHTML);
});
test("test App2", async () => {
const node = await mount(<App2 />);
console.log("mounted", node.innerHTML);
});
function mount(e) {
return new Promise(resolve => {
const node = document.createElement("div");
render(e, node, () => {
// todo have to wrapper setTimeout to make sure asynchronous
setTimeout(() => {
resolve(node);
});
});
});
} But there have similar issue. The render callback of |
I think the request here is the same as #14050. |
Do you want to request a feature or report a bug?
maybe a bug?
What is the current behavior?
see bellow.
If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem. Your bug will get fixed much faster if we can run your code and it doesn't have dependencies other than React. Paste the link to your JSFiddle (https://jsfiddle.net/Luktwrdm/) or CodeSandbox (https://codesandbox.io/s/new) example below:
run the tests, and see the log.
What is the expected behavior?
But got
after useEffect callback firing in
App2
, we can't get re-rendered dom.btw, in codesandbox, log the
App2 effect
, but in local node env, will lost the logApp2 effect
Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?
The text was updated successfully, but these errors were encountered: