We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
link: https://github.com/alibaba/hooks/issues/new
useRequest:
Fetch.ts 文件:
Fetch.ts
useRequestImplement.ts 文件:
useRequestImplement.ts
当触发用户交互行为, 如拖拽行为时:
React 17 会按照下列顺序执行:
drag文件
useRequest
useUnmount
fetchInstance.cancel()
this.count + 1
this.count
符合预期
React 18 执行顺序 :
const res = await servicePromise;
异步可中断更新
时间切片
useDragPreCheck
异步
currentCount !== this.count
new Promise(() => {});
onSuccess
在页面中的表现则为 onSuccess 未触发, loading 不消失, 数据未处理
loading
相关 demo (React 18.2.0 + ahooks 3.7.10) : https://is.gd/lZJgyH
将一个节点拖拽到另一个容器中, 表现为 loading 不消失; 而将 react 版本更换为 react 17 后则表现正常;
The text was updated successfully, but these errors were encountered:
@crazylxr
Sorry, something went wrong.
收到,我看下
这个计划解决吗?
有的
ReactDOM.render(<App />, document.getElementById("root"))
改成
const root = createRoot(document.getElementById("root")); root.render(<App />);
就正常了
这个计划解决吗? 有的
当前进度如何 @crazylxr
crazylxr
No branches or pull requests
useRequest:
Fetch.ts
文件:useRequestImplement.ts
文件:当触发用户交互行为, 如拖拽行为时:
React 17 会按照下列顺序执行:
drag文件
Effect CleanupuseRequest
Hook Effect Cleanup, 此时会触发useRequestImplement.ts
useUnmount
回调函数, 即fetchInstance.cancel()
, 而执行fetchInstance.cancel()
后会使得this.count + 1
, 此时this.count
值为 1this.count
再次 + 1, 值为 2, 因此 currentCount 的值也为 2, 因此会按照预期执行 onSuccess 回调函数符合预期
React 18 执行顺序 :
this.count + 1
, 值为 1, 因此 currentCount 的值为 1const res = await servicePromise;
触发异步可中断更新
3..
时间切片
调度其他优先级任务, 执行 Effect 链条 Cleanup:useDragPreCheck
Hook Effect Cleanup ->useRequest
Hook Effect Cleanup, 此时执行fetchInstance.cancel()
,this.count + 1
, 此时this.count
值为 2异步
行为完成后, 回到上下文继续执行逻辑, 此时判断currentCount !== this.count
成立, currentCount 由于闭包存在, 值为1, 而this.count
值为 2, 因此返回了new Promise(() => {});
导致onSuccess
未被执行在页面中的表现则为
onSuccess
未触发,loading
不消失, 数据未处理相关 demo (React 18.2.0 + ahooks 3.7.10) : https://is.gd/lZJgyH
将一个节点拖拽到另一个容器中, 表现为 loading 不消失; 而将 react 版本更换为 react 17 后则表现正常;
The text was updated successfully, but these errors were encountered: