Viem Migration - Yield tab is returning to previous page when clicked#7352
Viem Migration - Yield tab is returning to previous page when clicked#7352lgahdl wants to merge 2 commits intocowprotocol:developfrom
Conversation
Syncing cowprotocol/cowswap dev
|
Someone is attempting to deploy a commit to the cow Team on Vercel. A member of the Team first needs to authorize it. |
|
All contributors have signed the CLA ✍️ ✅ |
|
Warning Rate limit exceeded
Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 10 minutes and 3 seconds. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
WalkthroughThe Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
a9a8e52 to
5c13b4f
Compare
Summary
Fixes #901
useTradeNavigatewas reading the trade route fromtradeTypeAtom(Jotai atom), which is updated viauseLayoutEffect— meaning it's stale during the first render after a route change. When navigating from Swap to Yield, the atom still held the SWAP route, souseSetupTradeState'stokensAreEmptyredirect would fire and send the user back to/swap/WETH/USDC.Fix: replace
useTradeTypeInfo()(atom-based) withuseTradeTypeInfoFromUrl()(URL-based) insideuseTradeNavigate, so the redirect always targets the route that matches the current URL.This was a heisenbug — opening Chrome DevTools slows JS execution enough to change render/effect timing, masking the race condition.
To Test
/1/swap/WETH/USDC)/1/yield)Background
The root cause is a race condition between
useLayoutEffectanduseEffectscheduling. In React,useLayoutEffectruns synchronously after the DOM commit, but theuseEffectclosures in the same render cycle already captured the pre-layout-effect state. SouseTradeNavigate'stradeRoutewas SWAP (stale) when the redirect effect fired, even though the URL had already changed to/yield.useTradeTypeInfoFromUrl()derives the trade type directly from the URL viauseMatch, making it always in sync with the current route without depending on atom propagation timing.Summary by CodeRabbit