Skip to content
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

fix(wagmi): solve react max update depth exceeded issue #884

Merged
merged 16 commits into from
May 21, 2024

Conversation

jeasonstudio
Copy link
Collaborator

修复经常在文档中遇到的 react rerender 次数过多导致的问题:
image

web3-wagmi 包中有一处对 setState 的错误使用:

const [currentChain, setCurrentChain] = React.useState();
React.useEffect(() => {
  // ...
  setCurrentChain(newChain);
}, [currentChain]);

Copy link

vercel bot commented May 16, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
ant-design-web3 ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 21, 2024 7:24am

Copy link

changeset-bot bot commented May 16, 2024

🦋 Changeset detected

Latest commit: ae84f79

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 8 packages
Name Type
@ant-design/web3-wagmi Patch
@ant-design/web3-eth-web3js Minor
@ant-design/web3-ethers Minor
@ant-design/web3 Patch
@ant-design/web3-ethers-v5 Patch
@example/eth-web3js Patch
@example/ethers Patch
@example/ethers-v5 Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

github-actions bot commented May 16, 2024

Preview is ready

@jeasonstudio
Copy link
Collaborator Author

感谢 @ONLY-yours 协助 debug

@thinkasany
Copy link
Collaborator

点快了,ci好像有点问题需要再看看

@kiner-tang kiner-tang changed the title Fix react max udpate depth exceeded fix: solve react max update depth exceeded issue May 16, 2024
@jeasonstudio jeasonstudio marked this pull request as draft May 16, 2024 10:24
@jeasonstudio jeasonstudio changed the title fix: solve react max update depth exceeded issue fix(wagmi): solve react max update depth exceeded issue May 16, 2024
Copy link

codecov bot commented May 20, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (b12a0e9) to head (ae84f79).

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #884   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          708       708           
  Lines        21454     21461    +7     
  Branches      1214      1214           
=========================================
+ Hits         21454     21461    +7     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@jeasonstudio
Copy link
Collaborator Author

除了 setState 的问题外,wagmi 本身对于单页面多实例的情况支持也不乐观,暂时添加了个 storage 配置,可以在 demo 中手动取消 localStorage 中的缓存逻辑。

@jeasonstudio
Copy link
Collaborator Author

好奇怪啊,只有在快速切换的时候能复现,正常切换没问题,难道是有些状态没卸载?

@yutingzhao1991
Copy link
Collaborator

好奇怪啊,只有在快速切换的时候能复现,正常切换没问题,难道是有些状态没卸载?

bughd.mov

我这边试的时候不用切换,正常连接也会有问题,重复试几次就会触发,而且是第一个连接下面的报错:

@jeasonstudio
Copy link
Collaborator Author

好奇怪啊,只有在快速切换的时候能复现,正常切换没问题,难道是有些状态没卸载?

bughd.mov
我这边试的时候不用切换,正常连接也会有问题,重复试几次就会触发,而且是第一个连接下面的报错:

ethersjs 和 web3js 页面还能复现这个问题吗

@yutingzhao1991
Copy link
Collaborator

好奇怪啊,只有在快速切换的时候能复现,正常切换没问题,难道是有些状态没卸载?

bughd.mov
我这边试的时候不用切换,正常连接也会有问题,重复试几次就会触发,而且是第一个连接下面的报错:

ethersjs 和 web3js 页面还能复现这个问题吗

ethersjs 这个里面只有一个 demo,试了几次没有复现,web3js 这个两个 demo 来回试就出现了

image

https://preview-884-ant-design-web3.surge.sh/components/ethereum-web3js 这里试的

@jeasonstudio
Copy link
Collaborator Author

最终定位到 useDisconnect 这个 hook,对应的 PR:wevm/wagmi#3949

@jeasonstudio
Copy link
Collaborator Author

最终定位到 useDisconnect 这个 hook,对应的 PR:wevm/wagmi#3949

这个 PR 对我们是有用的,但被 wagmi 关闭了,重新提了个 issue 给他们看看有没有新的进展:wevm/wagmi#3958

这个问题最终可复现路径为:使用了 useDisconnect 并且页面中有多个实例(config),目前采用 @wagmi/core 中的低阶 API 代替了 useDisconnect hook

Co-authored-by: kiner-tang <1127031143@qq.com>
@yutingzhao1991 yutingzhao1991 merged commit 518fd83 into main May 21, 2024
12 checks passed
@yutingzhao1991 yutingzhao1991 deleted the fix-react-max-udpate-depth-exceeded branch May 21, 2024 07:32
MarioJames pushed a commit that referenced this pull request May 23, 2024
* fix(wagmi): max update depth exceeded

* chore(wagmi): add changeset

* fix(wagmi): test case

* test(wagmi): fix ci

* test(wagmi): vitest cases

* feat(ethersjs): support storage props

* feat(web3js): support storage props

* chore(web3): update demos for storage

* chore: add changeset

* test: add coverage

* chore(wagmi): mock use disconnect

* refactor(wagmi): use low-level disconnect instead

* chore(wagmi): rm unused code

Co-authored-by: kiner-tang <1127031143@qq.com>

* docs: add storage config for ethereum adapters

* chore(ethers): add storage for minor upgrade

---------

Co-authored-by: kiner-tang <1127031143@qq.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants