Skip to content

Conversation

@tarrencev
Copy link
Contributor

@tarrencev tarrencev commented Sep 29, 2025

Summary

  • Fixed race conditions in theme preset loading that could cause incorrect theme application
  • Added comprehensive tests for the useConnectionValue hook to ensure reliability
  • Improved cleanup of async operations to prevent memory leaks

Test plan

  • Added new test suite for useConnectionValue hook
  • Tests cover preset loading, theme fallback, and error handling scenarios
  • Verify theme loads correctly in production with various presets
  • Check that theme fallback works when preset is invalid or missing

🤖 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.

  • Key changes in packages/keychain/src/hooks/connection.ts:
    • Preset config loading: resets state when no preset, adds cancellation guard, sets verified false and configData null on missing origin or errors.
    • Verification: computes verified via isOriginVerified and gracefully handles absent origin config.
    • Theme handling: when no preset, immediately apply default theme; when loading, wait; if config has theme, apply with verified, else fallback to default. Simplifies deps by removing theme.name guard.
  • Tests:
    • Replace connection.test.ts with connection.test.tsx adding tests for useConnectionValue (preset load success, fallback, error) and retaining isOriginVerified cases, 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.

- 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 <[email protected]>
@vercel
Copy link

vercel bot commented Sep 29, 2025

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

Project Deployment Preview Updated (UTC)
controller-example-next Ready Ready Preview Sep 30, 2025 2:23am
controller-example-next-compat Ready Ready Preview Sep 30, 2025 2:23am
keychain Ready Ready Preview Sep 30, 2025 2:23am
keychain-storybook Ready Ready Preview Sep 30, 2025 2:23am

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 <[email protected]>
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 <[email protected]>
Apply prettier formatting to pass CI format checks.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
Apply prettier formatting to all modified files.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
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 <[email protected]>
cursor[bot]

This comment was marked as outdated.

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 <[email protected]>
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 <[email protected]>
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,
});
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Fix in Cursor Fix in Web

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