Skip to content

fix: lifecycle-manage name auction storage sync to prevent test failures - #227

Merged
truthixify merged 1 commit into
wraith-protocol:developfrom
boalambo:fix/name-auction-storage-sync-lifecycle
Oct 16, 2026
Merged

truthixify merged 1 commit into
wraith-protocol:developfrom
boalambo:fix/name-auction-storage-sync-lifecycle

Conversation

@boalambo

Copy link
Copy Markdown
Contributor

Fix: Lifecycle-manage name auction storage sync to prevent test failures

Problem

Both nameWatchlistStore.test.ts tests were failing because the module initialization called window.addEventListener after only checking that window exists. The anonymous module-level listener could not be removed and would duplicate after module reloads, causing test failures in environments with partial browser mocks.

Solution

  • Replace module-level addEventListener with explicit initNameWatchlistSync() and cleanupNameWatchlistSync() functions
  • Add safe checks for window.addEventListener/removeEventListener existence to handle test environments and SSR
  • Create a MockWindow class in tests with proper event listener methods
  • Initialize sync in App.tsx via useEffect with cleanup on unmount
  • Tests now call initNameWatchlistSync() in beforeEach and cleanupNameWatchlistSync() in afterEach

Changes

  • src/store/nameWatchlistStore.tsx: Refactored to provide lifecycle-managed storage sync
  • src/store/nameWatchlistStore.test.ts: Added MockWindow class and lifecycle calls
  • src/store/multiTabSync.test.tsx: Added lifecycle initialization/cleanup
  • src/App.tsx: Added useEffect to initialize sync on mount with cleanup

Verification

  • ✅ All 332 unit tests now pass (previously 2 failing)
  • ✅ Storage event synchronization preserved in real browsers
  • ✅ Safe initialization in tests, SSR-like environments, and partial browser mocks
  • ✅ No duplicate listeners after module reloads
  • ✅ Follows same pattern as contactsStore.tsx and splitTemplatesStore.tsx

Closes #208

- Replace module-level addEventListener with explicit init/cleanup functions
- Add safe checks for window.addEventListener existence in test environments
- Mock window object with addEventListener/removeEventListener in tests
- Initialize sync in App useEffect with cleanup on unmount
- Tests: call initNameWatchlistSync in beforeEach, cleanup in afterEach
@drips-wave

drips-wave Bot commented Oct 16, 2026

Copy link
Copy Markdown

@boalambo 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

@vercel

vercel Bot commented Oct 16, 2026

Copy link
Copy Markdown

@boalambo is attempting to deploy a commit to the truthixify's projects Team on Vercel.

A member of the Team first needs to authorize it.

@truthixify truthixify left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The storage listener now has explicit init/cleanup ownership at the app lifecycle boundary. The full unit suite passes locally (332/332); the GitHub build is green, and the only red status is the external Vercel authorization check.

@truthixify
truthixify merged commit 5ccfe9c into wraith-protocol:develop Oct 16, 2026
1 of 2 checks passed
@boalambo
boalambo deleted the fix/name-auction-storage-sync-lifecycle branch October 17, 2026 08:59
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.

[Wave 10] Fix and lifecycle-manage name auction storage sync

2 participants