-
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
Bug: The loading state of useRequest is incorrect with react-refresh #390
Comments
This is mega annoying when you are using react-refresh... you have to either reload the whole page every time or disable reading |
|
This is a bug for react-refresh-webpack-plugin. It will not work correctly in this scenario import React from 'react';
function getUsername() {
return new Promise(resolve => {
setTimeout(() => {
resolve('test');
}, 1000);
});
}
export function FunctionNamed() {
const isUnmountFlag = React.useRef(false);
const [loading, setLoading] = React.useState(true);
React.useEffect(() => {
setLoading(true);
getUsername().then(() => {
if (!isUnmountFlag.current) {
setLoading(false);
}
});
}, []);
// it will trigger unmount first
React.useEffect(() => {
return () => {
isUnmountFlag.current = true;
}
});
return <h1>
...
{loading ? 'loading' : 'data'}
</h1>;
} |
大哥们,这个问题还是没有解决啊。gaearon 已经说明了这不是bug,是特性。pmmmwh/react-refresh-webpack-plugin#85 (comment) |
就是它们的 bug,useRequest 没法兼容~~ |
为啥呢?我之前也这样觉得,所以也给他们提了bug,但是 Dan 解释之后,我觉得他的说法也有道理。至少目前 react 官方认为这是特性不是bug。 |
其实就像我前面写的这个 demo,在 react-refresh 里面,明显执行的就有问题。 |
仔细看下我给 react 提的 issue 呗。你的例子和我的例子没有本质区别。
|
这个问题会有后续吗? |
暂时没有好的想法。
|
@brickspert 这个怎么 close 了呢?是否可以参考 react-query 是怎么处理的?我用 react-query 没有碰到这个问题 |
热更新状态下,loading一直为true,data的更新也会受到影响。开发的状态下几乎是不可用状态 |
好像是 react-refresh 让 react 在 hmr rerender 的时候,重新执行了 空数组依赖的 useEffect。。。 空数组依赖的 useEffect 在 hmr 时不应重复执行。 |
It's not a bug in React. It's intentional that |
Hi, Dan @gaearon |
I have fixed in #943 , |
React version: 16.13.1
react-refresh version: 0.8.1
react-refresh-webpack-plugin version: 0.3.0-beta.6
umi/hooks version: 1.9.2
Steps To Reproduce
Link to code example:
The current behavior
The result of loading will always be true when hmr.
The expected behavior
The result of loading should be the right value.
The bug reason
The state of Function component is preserved, but effects re-run in React Refresh.
For Detail.
A suggestion for code shown as below :
Thanks for your help.
The text was updated successfully, but these errors were encountered: