Skip to content

Refactor waves list derivation and memoize pinned IDs#1830

Merged
simo6529 merged 3 commits intomainfrom
waveslist-revert
Jan 27, 2026
Merged

Refactor waves list derivation and memoize pinned IDs#1830
simo6529 merged 3 commits intomainfrom
waveslist-revert

Conversation

@simo6529
Copy link
Copy Markdown
Collaborator

@simo6529 simo6529 commented Jan 26, 2026

  • Simplify useWavesList by removing state/ref/deep-compare logic and deriving allWaves directly from memoized inputs for cleaner, predictable updates.
  • Memoize pinnedIds in usePinnedWavesServer to keep stable identities and reduce unnecessary downstream re-renders.
  • Keep missingPinnedIds as a stable empty memo and return mainWaves directly from the hook.
  • Normalize useWavesList tests with consistent formatting/quotes.

Summary by CodeRabbit

  • Tests

    • Enhanced test fixtures with explicit mocking for improved test reliability and clarity.
  • Refactor

    • Simplified internal data flow in wave list hook by removing local state and switching to derived data.
    • Added performance optimizations through memoization in pinned waves hook.

✏️ Tip: You can customize this high-level summary in your review settings.

Signed-off-by: Simo <simo@6529.io>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jan 26, 2026

📝 Walkthrough

Walkthrough

These changes refactor wave list management by replacing local state and refs with memoized derived values. A test file receives quote style standardization and explicit useWaveData mocking. The usePinnedWavesServer hook is enhanced with useMemo for stable pinnedIds derivation.

Changes

Cohort / File(s) Summary
Test Updates
__tests__/hooks/useWavesList.test.tsx
Quote style standardization (single to double quotes), added useWaveData mock in beforeEach to return pinnedExtra with loading/error states, minor formatting adjustments around AuthContext.Provider.
usePinnedWavesServer Enhancement
hooks/usePinnedWavesServer.ts
Added useMemo import and derived pinnedIds from pinnedWaves for stable identity across renders.
useWavesList Refactoring
hooks/useWavesList.ts
Removed broad React imports (now only useContext, useMemo, useCallback); eliminated deep equality helper and local state/refs (allWaves, previous snapshots); introduced memoized derived allWaves by merging mainWaves and separatelyFetchedPinnedWaves; computed isPinned from pinnedIds set; replaced useEffect-based eager updates with derived data patterns; exposed mainWaves in return object; simplified logic and comments.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • PR #1746: Modifies isPinned representation and computation—main PR derives isPinned from pinnedIds in useWavesList while retrieved PR adds EnhancedApiWave.isPinned in mapWave.
  • PR #1669: Modifies hooks/usePinnedWavesServer.ts pinned-waves handling—one derives pinnedIds with useMemo while the other adds refetchInterval.
  • PR #1823: Modifies hooks/useWavesList.ts with opposite pattern—retrieved PR adds state/refs/useEffect while main PR removes them in favor of memoized derived values.

Suggested reviewers

  • ragnep
  • GelatoGenesis

Poem

🐰 Memoize, oh memoize, the waves must flow,
No refs, no state, just derived data's glow!
Pinned IDs dance in memo's embrace,
Clean data streams, a refactored space!
From eager updates to lazy delights,
The hooks sing true through performance heights! 🌊✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main changes: refactoring waves list derivation and memoizing pinned IDs, which are the core objectives of the PR.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@sonarqubecloud
Copy link
Copy Markdown

@simo6529 simo6529 merged commit 8d38a8c into main Jan 27, 2026
7 checks passed
@simo6529 simo6529 deleted the waveslist-revert branch January 27, 2026 07:36
This was referenced Apr 6, 2026
@coderabbitai coderabbitai Bot mentioned this pull request Apr 17, 2026
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