feat: optimize vercel fast origin trasnfer usages#506
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
📝 WalkthroughWalkthroughChanges three files to shift Markets component from server-side search param handling to client-side URL parsing. Adds Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested labels
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 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 |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/features/markets/markets-view.tsx (1)
24-46:⚠️ Potential issue | 🟡 MinorOne-shot read of
window.location.searchwon't track URL changes.The effect runs once on mount, so any later client-side navigation that mutates the URL (push/replace, back/forward) leaves
currentSearchParamsstale andurlFilterStatewon't re-apply. Also, the initial render parses an empty string before hydration, which can cause a brief filter flash.If the URL is only ever set on hard load this is fine; otherwise consider a lazy initializer plus a
popstatelistener.Possible tweak
- const [currentSearchParams, setCurrentSearchParams] = useState(''); + const [currentSearchParams, setCurrentSearchParams] = useState(() => + typeof window === 'undefined' + ? '' + : window.location.search.replace(/^\?/, ''), + ); @@ - useLayoutEffect(() => { - setCurrentSearchParams(window.location.search.startsWith('?') ? window.location.search.slice(1) : window.location.search); - }, []); + useLayoutEffect(() => { + const sync = () => setCurrentSearchParams(window.location.search.replace(/^\?/, '')); + sync(); + window.addEventListener('popstate', sync); + return () => window.removeEventListener('popstate', sync); + }, []);🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/features/markets/markets-view.tsx` around lines 24 - 46, The current useLayoutEffect only reads window.location.search once, leaving currentSearchParams stale on client-side navigation and causing an empty-string parse before hydration; change the useState for currentSearchParams to a lazy initializer that reads window.location.search when available (guard for SSR), and replace the single-run useLayoutEffect with an effect that sets the initial value and subscribes to history changes: add a 'popstate' listener that calls setCurrentSearchParams(newSearch) and also patch or listen for pushState/replaceState (or provide a small wrapper) so client-side navigations update currentSearchParams; update references in urlFilterState (useMemo) will then recompute correctly. Ensure you update the effect cleanup to remove listeners; refer to currentSearchParams, setCurrentSearchParams, and the existing useLayoutEffect for where to apply these changes.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@src/features/markets/markets-view.tsx`:
- Around line 24-46: The current useLayoutEffect only reads
window.location.search once, leaving currentSearchParams stale on client-side
navigation and causing an empty-string parse before hydration; change the
useState for currentSearchParams to a lazy initializer that reads
window.location.search when available (guard for SSR), and replace the
single-run useLayoutEffect with an effect that sets the initial value and
subscribes to history changes: add a 'popstate' listener that calls
setCurrentSearchParams(newSearch) and also patch or listen for
pushState/replaceState (or provide a small wrapper) so client-side navigations
update currentSearchParams; update references in urlFilterState (useMemo) will
then recompute correctly. Ensure you update the effect cleanup to remove
listeners; refer to currentSearchParams, setCurrentSearchParams, and the
existing useLayoutEffect for where to apply these changes.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: be0e72b3-83c4-42fd-b3ff-f3b920eed74b
📒 Files selected for processing (3)
app/market/[chainId]/[marketid]/page.tsxapp/markets/page.tsxsrc/features/markets/markets-view.tsx
Summary by CodeRabbit