Skip to content

Commit befbcef

Browse files
PandaManEruis
andauthored
fix: prevent tab synchronization between different records (#17559)
Fixes issue where tabs were synchronized when opening two records of the same type in show page and side panel. The root cause was that tab instance IDs were only based on `pageLayoutId`, causing all records using the same page layout to share the same tab state. This change includes the record ID in the tab instance ID, making tabs unique per record while maintaining backward compatibility for cases where no record ID is available. Fixes #17522 --------- Co-authored-by: Eruis <github@eruis.example>
1 parent 83b800a commit befbcef

File tree

3 files changed

+40
-7
lines changed

3 files changed

+40
-7
lines changed

packages/twenty-front/src/modules/page-layout/components/PageLayoutRenderer.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ import { PageLayoutRendererContent } from '@/page-layout/components/PageLayoutRe
44
import { useSetIsPageLayoutInEditMode } from '@/page-layout/hooks/useSetIsPageLayoutInEditMode';
55
import { PageLayoutComponentInstanceContext } from '@/page-layout/states/contexts/PageLayoutComponentInstanceContext';
66
import { type PageLayout } from '@/page-layout/types/PageLayout';
7-
import { getTabListInstanceIdFromPageLayoutId } from '@/page-layout/utils/getTabListInstanceIdFromPageLayoutId';
7+
import { getTabListInstanceIdFromPageLayoutAndRecord } from '@/page-layout/utils/getTabListInstanceIdFromPageLayoutAndRecord';
88
import { isPageLayoutEmpty } from '@/page-layout/utils/isPageLayoutEmpty';
9+
import { useLayoutRenderingContext } from '@/ui/layout/contexts/LayoutRenderingContext';
910
import { TabListComponentInstanceContext } from '@/ui/layout/tab-list/states/contexts/TabListComponentInstanceContext';
1011
import 'react-grid-layout/css/styles.css';
1112
import 'react-resizable/css/styles.css';
@@ -20,6 +21,8 @@ export const PageLayoutRenderer = ({
2021
const { setIsPageLayoutInEditMode } =
2122
useSetIsPageLayoutInEditMode(pageLayoutId);
2223

24+
const { targetRecordIdentifier, layoutType } = useLayoutRenderingContext();
25+
2326
const onInitialized = (pageLayout: PageLayout) => {
2427
if (isPageLayoutEmpty(pageLayout)) {
2528
setIsPageLayoutInEditMode(true);
@@ -28,6 +31,12 @@ export const PageLayoutRenderer = ({
2831
}
2932
};
3033

34+
const tabListInstanceId = getTabListInstanceIdFromPageLayoutAndRecord({
35+
pageLayoutId,
36+
layoutType,
37+
targetRecordIdentifier,
38+
});
39+
3140
return (
3241
<PageLayoutComponentInstanceContext.Provider
3342
value={{
@@ -36,7 +45,7 @@ export const PageLayoutRenderer = ({
3645
>
3746
<TabListComponentInstanceContext.Provider
3847
value={{
39-
instanceId: getTabListInstanceIdFromPageLayoutId(pageLayoutId),
48+
instanceId: tabListInstanceId,
4049
}}
4150
>
4251
<PageLayoutInitializationQueryEffect

packages/twenty-front/src/modules/page-layout/components/PageLayoutRendererContent.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { PageLayoutMainContent } from '@/page-layout/PageLayoutMainContent';
1111
import { isPageLayoutInEditModeComponentState } from '@/page-layout/states/isPageLayoutInEditModeComponentState';
1212
import { pageLayoutTabSettingsOpenTabIdComponentState } from '@/page-layout/states/pageLayoutTabSettingsOpenTabIdComponentState';
1313
import { getScrollWrapperInstanceIdFromPageLayoutId } from '@/page-layout/utils/getScrollWrapperInstanceIdFromPageLayoutId';
14-
import { getTabListInstanceIdFromPageLayoutId } from '@/page-layout/utils/getTabListInstanceIdFromPageLayoutId';
14+
import { getTabListInstanceIdFromPageLayoutAndRecord } from '@/page-layout/utils/getTabListInstanceIdFromPageLayoutAndRecord';
1515
import { getTabsByDisplayMode } from '@/page-layout/utils/getTabsByDisplayMode';
1616
import { getTabsWithVisibleWidgets } from '@/page-layout/utils/getTabsWithVisibleWidgets';
1717
import { shouldEnableTabEditingFeatures } from '@/page-layout/utils/shouldEnableTabEditingFeatures';
@@ -52,7 +52,8 @@ const StyledScrollWrapper = styled(ScrollWrapper)`
5252
export const PageLayoutRendererContent = () => {
5353
const { currentPageLayout } = useCurrentPageLayout();
5454

55-
const { isInRightDrawer } = useLayoutRenderingContext();
55+
const { isInRightDrawer, layoutType, targetRecordIdentifier } =
56+
useLayoutRenderingContext();
5657

5758
const isPageLayoutInEditMode = useRecoilComponentValue(
5859
isPageLayoutInEditModeComponentState,
@@ -104,9 +105,11 @@ export const PageLayoutRendererContent = () => {
104105
isInRightDrawer,
105106
});
106107

107-
const tabListInstanceId = getTabListInstanceIdFromPageLayoutId(
108-
currentPageLayout.id,
109-
);
108+
const tabListInstanceId = getTabListInstanceIdFromPageLayoutAndRecord({
109+
pageLayoutId: currentPageLayout.id,
110+
layoutType,
111+
targetRecordIdentifier,
112+
});
110113

111114
const sortedTabs = sortTabsByPosition(tabsToRenderInTabList);
112115

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { type TargetRecordIdentifier } from '@/ui/layout/contexts/TargetRecordIdentifier';
2+
import { type LayoutRenderingContextType } from '@/ui/layout/contexts/LayoutRenderingContext';
3+
import { getTabListInstanceIdFromPageLayoutId } from './getTabListInstanceIdFromPageLayoutId';
4+
import { isDefined } from 'twenty-shared/utils';
5+
6+
export const getTabListInstanceIdFromPageLayoutAndRecord = ({
7+
pageLayoutId,
8+
layoutType,
9+
targetRecordIdentifier,
10+
}: {
11+
pageLayoutId: string;
12+
layoutType: LayoutRenderingContextType['layoutType'];
13+
targetRecordIdentifier?: TargetRecordIdentifier;
14+
}) => {
15+
// Include record ID in tab instance ID to prevent tab synchronization between different records
16+
// Only for RECORD_PAGE layouts, as DASHBOARD layouts are standalone
17+
const recordId =
18+
layoutType === 'RECORD_PAGE' ? targetRecordIdentifier?.id : undefined;
19+
const baseInstanceId = getTabListInstanceIdFromPageLayoutId(pageLayoutId);
20+
return isDefined(recordId) ? `${baseInstanceId}-${recordId}` : baseInstanceId;
21+
};

0 commit comments

Comments
 (0)