fix: improve theme preset loading and add tests#2079
Open
Conversation
- Fix race conditions in theme preset loading - Add cleanup for async operations to prevent memory leaks - Simplify theme effect dependencies to avoid unnecessary re-renders - Add comprehensive tests for useConnectionValue hook - Ensure theme falls back correctly when preset is missing or invalid 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Vitest requires all vi.mock() calls to be at the top of the file before any other code execution. This fixes the syntax errors in CI. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
Test files using JSX syntax must have .tsx extension for TypeScript to properly parse them. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
Apply prettier formatting to pass CI format checks. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
Apply prettier formatting to all modified files. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
The Window interface with keychain_wallets is already declared in wallets.tsx. Declaring it again with a different type (unknown) causes a TypeScript compilation error. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
Move mock variable declarations after vi.mock() calls and use vi.mocked() to get references to the mocked functions. This prevents "Cannot access before initialization" errors. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
The theme object passed to useThemeEffect is a ControllerTheme, not a VerifiableControllerTheme, so it doesn't have a verified property. Remove the invalid assertions. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
Set window.controller to undefined instead of creating a partial mock object. This avoids TypeScript type errors while still allowing the tests to run correctly with mocked dependencies.
| setTheme({ | ||
| verified: true, | ||
| ...defaultTheme, | ||
| }); |
There was a problem hiding this comment.
Bug: Preset Verification Bypass
When a preset is active but its configuration lacks a theme, the fallback default theme is incorrectly set with verified: true. This bypasses the actual verified state of the preset, potentially hiding security warnings if the preset itself was unverified or failed to load.
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.
Summary
Test plan
🤖 Generated with Claude Code
Note
Refactors preset config loading and theme handling with proper defaults, verification, and cleanup; adds comprehensive tests for isOriginVerified and useConnectionValue.
packages/keychain/src/hooks/connection.ts:preset, adds cancellation guard, setsverifiedfalse andconfigDatanull on missing origin or errors.verifiedviaisOriginVerifiedand gracefully handles absentoriginconfig.preset, immediately apply default theme; when loading, wait; if config hastheme, apply withverified, else fallback to default. Simplifies deps by removingtheme.nameguard.connection.test.tswithconnection.test.tsxadding tests foruseConnectionValue(preset load success, fallback, error) and retainingisOriginVerifiedcases, with necessary mocks for presets/UI, controller, and RPC.Written by Cursor Bugbot for commit 152f01a. This will update automatically on new commits. Configure here.