Skip to content

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

Open
Khizr97 wants to merge 2 commits intomainfrom
khizr-fixes/REOWN-4523
Open

fix(wagmi): add resetSSRState method to prevent cross-request state leakage#5615
Khizr97 wants to merge 2 commits intomainfrom
khizr-fixes/REOWN-4523

Conversation

@Khizr97
Copy link
Copy Markdown

@Khizr97 Khizr97 commented Mar 31, 2026

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

Branch: khizr-fixes/REOWN-4523

🤖 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
Copy link
Copy Markdown

linear Bot commented Mar 31, 2026

@vercel
Copy link
Copy Markdown

vercel Bot commented Mar 31, 2026

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

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

Request Review

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Mar 31, 2026

⚠️ No Changeset found

Latest commit: c73049c

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

github-actions Bot commented Mar 31, 2026

All contributors have signed the CTA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 31, 2026

Visual Regression Test Results ✅ Passed

⚠️ 15 visual change(s) detected

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

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

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 31, 2026

Warnings
⚠️

🔑 Potential UUID detected in packages/adapters/wagmi/src/tests/client.test.ts (line 419): 07ba87ed-43aa-4adf-4...

Generated by 🚫 dangerJS against c73049c

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 31, 2026

📦 Bundle Size Check

All bundles are within size limits

📊 View detailed bundle sizes

> @reown/appkit-monorepo@1.7.1 size /home/runner/work/appkit/appkit


> size-limit

@reown/appkit - Main Entry
Size limit:   80 kB
Size:         75.72 kB with all dependencies, minified and gzipped
Loading time: 1.5 s    on slow 3G
Running time: 3.3 s    on Snapdragon 410
Total time:   4.7 s
@reown/appkit/react
Size limit:   235 kB
Size:         234.88 kB with all dependencies, minified and gzipped
Loading time: 4.6 s     on slow 3G
Running time: 10.3 s    on Snapdragon 410
Total time:   14.9 s
@reown/appkit/vue
Size limit:   80 kB
Size:         75.72 kB with all dependencies, minified and gzipped
Loading time: 1.5 s    on slow 3G
Running time: 2.4 s    on Snapdragon 410
Total time:   3.9 s
@reown/appkit-scaffold-ui
Size limit:   220 kB
Size:         214.17 kB with all dependencies, minified and gzipped
Loading time: 4.2 s     on slow 3G
Running time: 6.7 s     on Snapdragon 410
Total time:   10.9 s
@reown/appkit-ui
Size limit:   500 kB
Size:         13.16 kB with all dependencies, minified and gzipped
Loading time: 258 ms   on slow 3G
Running time: 670 ms   on Snapdragon 410
Total time:   927 ms

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 31, 2026

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 78.47% 39730 / 50625
🔵 Statements 78.47% 39730 / 50625
🔵 Functions 76.28% 4255 / 5578
🔵 Branches 86.7% 9667 / 11149
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
packages/adapters/wagmi/src/client.ts 76% 67.81% 80% 76% 165-166, 171-172, 186-196, 257-258, 298-301, 420-421, 435, 445-446, 459-460, 537-538, 550-551, 592-593, 610-625, 639-656, 676-677, 690-699, 710-711, 715-716, 721-753, 772-781, 785-791, 794-805, 814-815, 826-827, 848-850, 864-865, 878-879, 894-895, 938-939, 963-964, 972-973, 978-979, 986-987, 995-996, 1001-1002, 1011-1012, 1020-1021, 1026-1027, 1033-1055, 1058-1071
Generated in workflow #17065 for commit c73049c by the Vitest Coverage Report Action

@Khizr97
Copy link
Copy Markdown
Author

Khizr97 commented Apr 13, 2026

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

@Khizr97 Khizr97 requested a review from svenvoskamp April 13, 2026 16:32
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.

2 participants