hooks icon indicating copy to clipboard operation
hooks copied to clipboard

useRequest Warning: Can't perform a React state update on a component that hasn't mounted yet.

Open mao437303994 opened this issue 1 year ago • 13 comments

微信图片_20231105232857 这个问题没人遇到吗?获取到数据之前组件已经被卸载了,内部依旧调用useUpdate()导致报错

mao437303994 avatar Nov 05 '23 15:11 mao437303994

React has removed this warning in v18, please see: https://github.com/reactwg/react-18/discussions/82

In React < v18, please ignore this warning.

liuyib avatar Nov 06 '23 02:11 liuyib

React 18.2.0 并没有解决

alvin0216 avatar Jan 23 '24 02:01 alvin0216

+1 , 18.2.0依然存在

1zilc avatar Feb 25 '24 11:02 1zilc

来给个 demo ?具体问题具体分析

SignDawn avatar Feb 25 '24 13:02 SignDawn

截图的报错和 https://github.com/reactwg/react-18/discussions/82 里的报错:

Warning: Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in a useEffect cleanup function.

好像不是同一个问题,后面再看下

liuyib avatar Feb 26 '24 03:02 liuyib

@mao437303994 来个 demo 呢

crazylxr avatar Feb 27 '24 01:02 crazylxr

Hello @mao437303994. Please provide a online reproduction by forking this link https://codesandbox.io/s/ok2fe or a minimal GitHub repository. Issues labeled by Need Reproduce will be closed if no activities in 3 days.

你好 @mao437303994, 我们需要你提供一个在线的重现实例以便于我们帮你排查问题。你可以通过点击 此处 创建一个 codesandbox 或者提供一个最小化的 GitHub 仓库。3 天内未跟进此 issue 将会被自动关闭。

github-actions[bot] avatar Apr 21 '24 08:04 github-actions[bot]

https://codesandbox.io/p/sandbox/userequest-demo-l5l7lg

花了点时间弄了个repo,各位看下?👀,初步发现是MemoryRouter造成的,具体还没去深究。 @crazylxr @SignDawn @liuyib

点下刷新,然后点打开按钮就能看到了 image

1zilc avatar Apr 29 '24 14:04 1zilc

@1zilc 多谢提供 demo,但是没有复现 image

liuyib avatar Apr 30 '24 06:04 liuyib

https://github.com/alibaba/hooks/assets/44715458/078f7c6e-920f-4c5d-8562-145e592599a3

~刷新之后,点击打开按钮可以稳定复现~

在本地能更稳定复现: https://github.com/1zilc/use-request-demo

运行后刷新3-4次页面,然后点打开按钮

chrome v124

麻烦大佬再看下

1zilc avatar Apr 30 '24 07:04 1zilc

React 18.3.3 在使用 useRequest 也遇到了一样的问题 const { data: areaOptions } = useRequest(async () => await GetAreaList(), { cacheKey: 'cacheKey-area-list' });

zhengmenghuang avatar May 24 '24 07:05 zhengmenghuang

+1

linxianxi avatar Jul 22 '24 02:07 linxianxi

Hello @mao437303994. We totally like your proposal/feedback, welcome to send us a Pull Request for it. Please send your Pull Request to proper branch (feature branch for the new feature, master for bugfix and other changes), fill the Pull Request Template here, provide changelog/TypeScript/documentation/test cases if needed and make sure CI passed, we will review it soon. We appreciate your effort in advance and looking forward to your contribution!

你好 @mao437303994,我们完全同意你的提议/反馈,欢迎直接在此仓库 创建一个 Pull Request 来解决这个问题。请将 Pull Request 发到正确的分支(新特性发到 feature 分支,其他发到 master 分支),务必填写 Pull Request 内的预设模板,提供改动所需相应的 changelog、TypeScript 定义、测试用例、文档等,并确保 CI 通过,我们会尽快进行 Review,提前感谢和期待您的贡献。

giphy

github-actions[bot] avatar Jul 24 '24 01:07 github-actions[bot]

好像是设置了 cacheKey 就会有这个问题

linxianxi avatar Jul 24 '24 09:07 linxianxi

same https://github.com/alibaba/hooks/issues/1866

linxianxi avatar Jul 24 '24 09:07 linxianxi