Skip to content

fix(wagmi): add resetSSRState method to prevent cross-request state leakage - #5614

Closed
Khizr97 wants to merge 1 commit into
mainfrom
fix/ssr-state-leakage
Closed

fix(wagmi): add resetSSRState method to prevent cross-request state leakage#5614
Khizr97 wants to merge 1 commit into
mainfrom
fix/ssr-state-leakage

Conversation

@Khizr97

@Khizr97 Khizr97 commented Mar 31, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Added resetSSRState() method to WagmiAdapter to prevent cross-request state leakage in Next.js SSR
  • In Next.js App Router with SSR, the WagmiAdapter is typically created as a module-level singleton
  • This can cause one user's wallet connection state to leak into another user's server-rendered HTML
  • The new method resets wagmi config state when no cookies are present

Fixes REOWN-4523

Changes

  1. packages/adapters/wagmi/src/client.ts

    • Added resetSSRState() method that clears connections, sets current to null, and status to 'disconnected'
  2. examples/next-wagmi-app-router/src/app/layout.tsx

    • Updated example to demonstrate proper SSR state reset usage
  3. examples/next-wagmi-app-router/src/config/index.ts

    • Added ssr: true to WagmiAdapter configuration
  4. packages/adapters/wagmi/src/tests/client.test.ts

    • Added unit tests for resetSSRState() method

Test plan

  • Unit tests added and pass for resetSSRState method
  • Build passes
  • All existing tests pass

🤖 Generated with Claude Code

…eakage

In Next.js App Router with SSR, the WagmiAdapter is typically created as a
module-level singleton. This can cause cross-request state leakage where one
user's wallet connection state bleeds into another user's server-rendered HTML.

This commit adds a `resetSSRState()` method that resets the wagmi config state
when `cookieToInitialState` returns undefined (i.e., when the user has no wallet
cookies). This prevents showing another user's wallet address in SSR.

REOWN-4523

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@linear

linear Bot commented Mar 31, 2026

Copy link
Copy Markdown

@changeset-bot

changeset-bot Bot commented Mar 31, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 66562d1

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@github-actions

Copy link
Copy Markdown
Contributor

Thank you for your contribution! We ask that you please read and sign our CTA Document before we can accept your contribution. You can sign the CTA simply by posting a Pull Request Comment with the following text:


I have read the CTA Document and I hereby sign the CTA


You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot.

@vercel

vercel Bot commented Mar 31, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
appkit-demo Ready Ready Preview, Comment Mar 31, 2026 2:43pm
appkit-gallery Ready Ready Preview, Comment Mar 31, 2026 2:43pm
appkit-headless-sample-app Ready Ready Preview, Comment Mar 31, 2026 2:43pm
appkit-laboratory Ready Ready Preview, Comment Mar 31, 2026 2:43pm
9 Skipped Deployments
Project Deployment Actions Updated (UTC)
appkit-basic-example Ignored Ignored Mar 31, 2026 2:43pm
appkit-basic-sign-client-example Ignored Ignored Mar 31, 2026 2:43pm
appkit-basic-up-example Ignored Ignored Mar 31, 2026 2:43pm
appkit-ethers5-bera Ignored Ignored Mar 31, 2026 2:43pm
appkit-nansen-demo Ignored Ignored Mar 31, 2026 2:43pm
appkit-wagmi-cdn-example Ignored Ignored Mar 31, 2026 2:43pm
ethereum-provider-wagmi-example Ignored Ignored Mar 31, 2026 2:43pm
next-wagmi-solana-bitcoin-example Ignored Ignored Mar 31, 2026 2:43pm
vue-wagmi-example Ignored Ignored Mar 31, 2026 2:43pm

Request Review

@github-actions

Copy link
Copy Markdown
Contributor

Visual Regression Test Results ✅ Passed

⚠️ 15 visual change(s) detected

Chromatic Build: https://www.chromatic.com/build?appId=6493191bf4b10fed8ca7353f&number=850
Storybook Preview: https://6493191bf4b10fed8ca7353f-esfaodegzw.chromatic.com/

👉 Please review the visual changes in Chromatic and accept or reject them.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant