Repository navigation
fix(#724): guard window access for SSR in SorokitProvider - #1018
Merged
k-deejah merged 3 commits intoOct 25, 2026
Merged
Conversation
SorokitProvider's customNetworks useState initializer and the network-restore effect read window.localStorage directly. The existing try/catch only covers SecurityError from storage access, not the case where window itself is unavailable in SSR/Node.js. Add explicit typeof window !== "undefined" guards (matching adapter.ts and WalletConnectButton.tsx) so: - no ReferenceError is thrown when rendered in Node.js/SSR - customNetworks initializes to [] without browser storage Add SSR regression tests that render via renderToString with window stubbed as undefined.
|
@BernardOnuh Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
Resolve the import conflict in SorokitProvider.test.tsx (keep renderToString from this branch and afterEach from main). Also repair two broken merge artifacts on main that stopped the provider suite from parsing: - SorokitProvider.test.tsx: restore the missing closers of the top-level afterEach block - SorokitContext.ts: restore the opening of the isHardware doc comment and drop the duplicated optional declaration Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- TransactionPanel: drop interleaved duplicate MEMO_TYPES tail, isMemoHexType/isMemoHashValid redeclaration, duplicated label/ placeholder/error ternaries and canSubmit tail - budget.ts: restore closing brace of calculateMonthlySpending - SwapExecutionTracker: remove unreachable "signing" branch inside the isPending banner (isPending never includes signing) - payment-flow, useOutsideClick, budget tests: restore missing block closers; merge duplicate budget import; align Sorokit#968 memo assertions with the component's label and message - lint autofix: import sort and prefer-const Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
Author
|
@k-deejah this PR is ready for review and merge. Conflicts with |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #724
Problem
SorokitProviderreadswindow.localStoragesynchronously in two places:customNetworksuseStateinitializer (SorokitProvider.tsx:48).useEffect(SorokitProvider.tsx:131).The existing
try/catchonly guards againstSecurityErrorfrom storage access; it does not make thewindowreference itself safe in environments wherewindowis unavailable. Thetypeof window !== "undefined"guard used elsewhere (src/lib/adapter.ts,WalletConnectButton.tsx) was missing here.Changes
src/context/SorokitProvider.tsxcustomNetworksinitializer now returns[]early whentypeof window === "undefined", before touchingwindow.localStorage.localStorage.getItem(STORAGE_KEY_NETWORK)access in atypeof window !== "undefined"check, so it is skipped entirely when there is no browser storage.src/context/SorokitProvider.test.tsxSSR safety (#724)suite that renders the provider withrenderToStringwhilewindowis stubbed asundefined:customNetworksinitializes to[].Why explicit guards instead of relying on
catchThe bare
catchhappened to swallow the reference error, but relying on a catch-all for control flow is fragile and silent. The explicit guard matches the convention already used throughout the codebase and makes the SSR intent obvious. It also covers the case wherewindowexists butlocalStoragedoes not.Testing
npm test— 100 files / 2033 tests passnpm run typecheck— cleannpm run lint— cleanScreenshots
Not applicable (SSR/Node.js behavior).