Skip to content

Fix merge records page accumulating duplicate morph items#17705

Open
rdelassus wants to merge 4 commits intotwentyhq:mainfrom
rdelassus:codex/fix-merge-records-duplicate-tabs
Open

Fix merge records page accumulating duplicate morph items#17705
rdelassus wants to merge 4 commits intotwentyhq:mainfrom
rdelassus:codex/fix-merge-records-duplicate-tabs

Conversation

@rdelassus
Copy link
Contributor

@rdelassus rdelassus commented Feb 4, 2026

Why

When opening Merge records repeatedly, morph items for the same command-menu page were appended instead of replaced. This could produce duplicated IDs (e.g. [A,B,B,A]) in the merge flow and extra duplicate tabs in the UI.

What

  • Update useCommandMenuUpdateNavigationMorphItemsByPage to replace page morph items instead of appending existing ones.
  • Add regression tests covering:
    • replacing existing morph items for the same page
    • keeping only the latest payload when called twice for the same page

Notes

I could not run the full workspace tests locally in this environment because of existing test/build setup issues unrelated to this change (missing packages/twenty-front/tsconfig.spec.json and temporal-polyfill resolution in dependent tasks).

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 2 files

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 4, 2026

Greptile Overview

Greptile Summary

Fixed a bug where repeatedly opening the Merge Records page accumulated duplicate morph items instead of replacing them. The hook now correctly replaces existing morph items for a given page ID, preventing duplicate record IDs and extra duplicate tabs in the UI. Added comprehensive regression tests to ensure the replacement behavior works correctly.

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The fix is straightforward and well-tested, changing append behavior to replacement behavior. The logic change is minimal, removing the spread operator that was accumulating items. Comprehensive regression tests verify both replacement scenarios.
  • No files require special attention

Important Files Changed

Filename Overview
packages/twenty-front/src/modules/command-menu/hooks/useCommandMenuUpdateNavigationMorphItemsByPage.tsx Replaced appending logic with replacement logic to fix duplicate IDs bug; removed unused import
packages/twenty-front/src/modules/command-menu/hooks/tests/useCommandMenuUpdateNavigationMorphItemsByPage.test.tsx Added comprehensive regression tests for replacement behavior

Sequence Diagram

sequenceDiagram
    participant User
    participant MergeUI as Merge Records UI
    participant Hook as useOpenMergeRecordsPageInCommandMenu
    participant UpdateHook as useCommandMenuUpdateNavigationMorphItemsByPage
    participant State as commandMenuNavigationMorphItemsByPageState
    participant Nav as navigateCommandMenu

    User->>MergeUI: Click "Merge Records"
    MergeUI->>Hook: openMergeRecordsPageInCommandMenu()
    Hook->>Hook: Generate new pageId (UUID)
    Hook->>UpdateHook: updateCommandMenuNavigationMorphItemsByPage({pageId, objectMetadataId, objectRecordIds})
    
    Note over UpdateHook: OLD: Appended to existing items<br/>NEW: Replaces existing items
    
    UpdateHook->>State: Get current morph items Map
    UpdateHook->>UpdateHook: Map objectRecordIds to MorphItems
    UpdateHook->>State: Set new Map with pageId → newMorphItems
    
    Hook->>Hook: Fetch records from API
    Hook->>Hook: Upsert records in store
    Hook->>Nav: Navigate to MergeRecords page
    Nav->>User: Display Merge Records page with correct items
Loading

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

2 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@github-actions
Copy link
Contributor

github-actions bot commented Feb 4, 2026

🚀 Preview Environment Ready!

Your preview environment is available at: http://bore.pub:64466

This environment will automatically shut down when the PR is closed or after 5 hours.

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.

1 participant