Skip to content

fix(#717): remove redundant readAllRecent() in handleClearContracts - #836

Merged
k-deejah merged 5 commits into
Sorokit:mainfrom
JinadJay:fix/issue-717-soroban-localstorage-memoization
Sep 30, 2026
Merged

k-deejah merged 5 commits into
Sorokit:mainfrom
JinadJay:fix/issue-717-soroban-localstorage-memoization

Conversation

@JinadJay

Copy link
Copy Markdown
Contributor

Problem

Issue #717 reports that SorobanScreen.tsx reads localStorage on every re-render via inline localStorage.getItem() calls. The core fix (useState lazy init for savedContractsBase) was already on main. However, handleClearContracts still called readAllRecent() (a localStorage.getItem wrapper) redundantly after writeRecent([]), which always returns [].

Solution

  • Replaced new Set(readAllRecent()) with new Set() in handleClearContracts — after clearing localStorage, there's no need to re-read it.
  • The useState(() => readAllRecent()) lazy init at line 63 ensures localStorage is only read on mount.
  • The existing test at line 179 (reads localStorage.getItem exactly once on mount, not on subsequent re-renders (#815)) already verifies the core fix.

Acceptance Criteria

  • localStorage.getItem is not called on every render (lazy useState init)
  • Adding a contract updates the list reactively (via setSavedContractsBase)
  • Removing a contract updates the list reactively (via setSavedContractsBase)
  • SorobanScreen.test.tsx verifies reactive list updates (existing test at line 179)

Closes #717

…racts

handleClearContracts called readAllRecent() after writeRecent([]), which
always returns []. Use new Set() directly to avoid an unnecessary
localStorage read.

Closes Sorokit#717
@drips-wave

drips-wave Bot commented Sep 29, 2026

Copy link
Copy Markdown

@JinadJay 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! 🚀

Learn more about application limits

CI environment has @types/node conflicting with DOM types for
setInterval return type. Explicitly annotate timerId to resolve.

Closes Sorokit#717
@JinadJay JinadJay closed this Sep 29, 2026
@JinadJay JinadJay reopened this Sep 29, 2026
@k-deejah
k-deejah merged commit 1b6ac2b into Sorokit:main Sep 30, 2026
1 of 3 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.

SorobanScreen.tsx reads localStorage on every re-render — savedContracts not memoized

2 participants