Skip to content

Fix hydration mismatch in the dev strategy switcher#47

Merged
riethmayer merged 1 commit into
masterfrom
fix-strategy-switcher-hydration
May 25, 2026
Merged

Fix hydration mismatch in the dev strategy switcher#47
riethmayer merged 1 commit into
masterfrom
fix-strategy-switcher-hydration

Conversation

@riethmayer

Copy link
Copy Markdown
Owner

On /play in dev, React reported a hydration mismatch in StrategySwitcher ("the server rendered text didn't match the client … this tree will be regenerated"), which is also why the strategy badge/selection wasn't showing reliably.

Cause: current was initialised from getOrderStrategy() during render. That reads localStorage (the persisted strategy override), which exists on the client but not during SSR — so the highlighted <li> differed between the server and client HTML.

Fix: read the active strategy with useSyncExternalStore:

  • server snapshot = the build-time DEFAULT_STRATEGY (so SSR and the first client render agree → no mismatch),
  • client snapshot = getOrderStrategy().name (resolves the localStorage override after hydration),
  • new subscribeOrderStrategy (notified by setOrderStrategy) re-renders the badge when cycling.

Dev-only component — no production behaviour change. Verified locally: switcher renders cleanly with the default and with a localStorage override (the case that previously mismatched), no error overlay. lint / type-check / vitest (106) / build green.

Not merged — opening for review.

StrategySwitcher initialised `current` from getOrderStrategy() during render,
which reads localStorage on the client but not during SSR — so the highlighted
strategy differed between server and client HTML and React regenerated the
subtree (the visible "can't see the strategy" symptom).

Read the active strategy via useSyncExternalStore: server snapshot = the
build-time default (matches SSR + first client render → no mismatch), client
snapshot resolves the real value after hydration, and a new
subscribeOrderStrategy lets the badge re-render when the strategy changes
(cycling). Dev-only component; no production behaviour change.
@vercel

vercel Bot commented May 25, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
eureka Ready Ready Preview, Comment May 25, 2026 5:39pm

@coderabbitai

coderabbitai Bot commented May 25, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@riethmayer, we couldn't start this review because you've used your available PR reviews for now.

Your plan includes 1 review of capacity. Refill in 15 minutes and 4 seconds.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more review capacity refills, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 trial, open-source, and free plans. In all cases, review capacity refills continuously over time.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 005d1a08-4bea-4e75-baa2-c65bf5c15dfe

📥 Commits

Reviewing files that changed from the base of the PR and between 426cb0c and 2c6e46f.

📒 Files selected for processing (2)
  • src/components/strategy-switcher/index.tsx
  • src/utils/order-strategies.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-strategy-switcher-hydration

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@supabase

supabase Bot commented May 25, 2026

Copy link
Copy Markdown

This pull request has been ignored for the connected project lthqyqlislwikgoxmttn because there are no changes detected in supabase directory. You can change this behaviour in Project Integrations Settings ↗︎.


Preview Branches by Supabase.
Learn more about Supabase Branching ↗︎.

@riethmayer riethmayer merged commit dc48b28 into master May 25, 2026
6 checks passed
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.

1 participant