The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
Prerender record page tabs on hover (#24958)
Félix Malfait6b7232c5a752
diff --git a/packages/twenty-front/src/modules/page-layout/components/PageLayoutPrerenderedTabIdsResetEffect.tsx b/packages/twenty-front/src/modules/page-layout/components/PageLayoutPrerenderedTabIdsResetEffect.tsxnew file mode 100644index 00000000000..0eb1a2db9d8--- /dev/null+++ b/packages/twenty-front/src/modules/page-layout/components/PageLayoutPrerenderedTabIdsResetEffect.tsx@@ -0,0 +1,19 @@+import { useEffect } from 'react';++import { pageLayoutPrerenderedTabIdsComponentState } from '@/page-layout/states/pageLayoutPrerenderedTabIdsComponentState';+import { useSetAtomComponentState } from '@/ui/utilities/state/jotai/hooks/useSetAtomComponentState';++// Prerendering is a within-visit optimization: without the reset, reopening+// a record would mount every tab hovered during the previous visit at once.+export const PageLayoutPrerenderedTabIdsResetEffect = () => {+ const setPageLayoutPrerenderedTabIds = useSetAtomComponentState(+ pageLayoutPrerenderedTabIdsComponentState,+ );++ useEffect(+ () => () => setPageLayoutPrerenderedTabIds([]),+ [setPageLayoutPrerenderedTabIds],+ );++ return null;+};diff --git a/packages/twenty-front/src/modules/page-layout/components/PageLayoutTabListVisibleTabs.tsx b/packages/twenty-front/src/modules/page-layout/components/PageLayoutTabListVisibleTabs.tsxindex be908246148..0e77d641dd9 100644--- a/packages/twenty-front/src/modules/page-layout/components/PageLayoutTabListVisibleTabs.tsx+++ b/packages/twenty-front/src/modules/page-layout/components/PageLayoutTabListVisibleTabs.tsx@@ -8,6 +8,7 @@ import { type SingleTabProps } from '@/ui/layout/tab-list/types/SingleTabProps';import { PAGE_LAYOUT_TAB_LIST_DROPPABLE_IDS } from '@/page-layout/components/PageLayoutTabListDroppableIds';import { PageLayoutTabListReorderableTab } from '@/page-layout/components/PageLayoutTabListReorderableTab';+import { usePrerenderPageLayoutTabOnHover } from '@/page-layout/hooks/usePrerenderPageLayoutTabOnHover';import { type PageLayoutWidget } from '@/page-layout/types/PageLayoutWidget';import { DragDropItemDropTarget } from '@/ui/utilities/drag-and-drop/components/DragDropItemDropTarget';@@ -65,6 +66,9 @@ export const PageLayoutTabListVisibleTabs = ({isScrollable,});+ const { handleTabMouseEnter, handleTabMouseLeave } =+ usePrerenderPageLayoutTabOnHover();+if (canReorder) {const shownTabs = visibleTabs.slice(0, visibleTabCount);@@ -124,6 +128,12 @@ export const PageLayoutTabListVisibleTabs = ({? () => onChangeTab?.(tab.id): () => onSelectTab(tab.id)}+ onMouseEnter={+ tab.id === activeTabId || (tab.disabled ?? loading)+ ? undefined+ : () => handleTabMouseEnter(tab.id)+ }+ onMouseLeave={handleTabMouseLeave}/>))}</StyledTabContainer>diff --git a/packages/twenty-front/src/modules/page-layout/components/PageLayoutTabsRenderer.tsx b/packages/twenty-front/src/modules/page-layout/components/PageLayoutTabsRenderer.tsxindex 3c5de103042..68845c7ada6 100644--- a/packages/twenty-front/src/modules/page-layout/components/PageLayoutTabsRenderer.tsx+++ b/packages/twenty-front/src/modules/page-layout/components/PageLayoutTabsRenderer.tsx@@ -1,5 +1,6 @@import { PageLayoutWidgetDndProvider } from '@/page-layout/components/dnd/PageLayoutWidgetDndProvider';import { PageLayoutLeftPanel } from '@/page-layout/components/PageLayoutLeftPanel';+import { PageLayoutPrerenderedTabIdsResetEffect } from '@/page-layout/components/PageLayoutPrerenderedTabIdsResetEffect';import { PageLayoutScrollResetEffect } from '@/page-layout/components/PageLayoutScrollResetEffect';import { PageLayoutTabList } from '@/page-layout/components/PageLayoutTabList';import { PageLayoutTabListEffect } from '@/page-layout/components/PageLayoutTabListEffect';@@ -9,9 +10,11 @@ import { useIsPageLayoutInEditMode } from '@/page-layout/hooks/useIsPageLayoutInimport { usePageLayoutAddTabStrategy } from '@/page-layout/hooks/usePageLayoutAddTabStrategy';import { usePageLayoutRenderableTabs } from '@/page-layout/hooks/usePageLayoutRenderableTabs';import { PageLayoutMainContent } from '@/page-layout/PageLayoutMainContent';+import { pageLayoutPrerenderedTabIdsComponentState } from '@/page-layout/states/pageLayoutPrerenderedTabIdsComponentState';import { getScrollWrapperInstanceIdFromPageLayoutAndRecord } from '@/page-layout/utils/getScrollWrapperInstanceIdFromPageLayoutAndRecord';import { getTabListInstanceIdFromPageLayoutAndRecord } from '@/page-layout/utils/getTabListInstanceIdFromPageLayoutAndRecord';import { shouldEnableTabEditingFeatures } from '@/page-layout/utils/shouldEnableTabEditingFeatures';+import { shouldPrerenderPageLayoutTab } from '@/page-layout/utils/shouldPrerenderPageLayoutTab';import { sortTabsByPosition } from '@/page-layout/utils/sortTabsByPosition';import { useLayoutRenderingContext } from '@/ui/layout/contexts/LayoutRenderingContext';import { activeTabIdComponentState } from '@/ui/layout/tab-list/states/activeTabIdComponentState';@@ -68,6 +71,14 @@ const StyledTabsAndDashboardContainer = styled.div`}`;+// Hidden prerendered tabs use display: none rather than <Activity mode="hidden">:+// Apollo starts useQuery fetches from effects, which hidden activities do not+// mount, so nothing would preload (see pageLayoutTabPrerenderContract.test).+// display: contents keeps the active tab's layout identical to an unwrapped mount.+const StyledTabContentDisplay = styled.div<{ isActiveTab: boolean }>`+ display: ${({ isActiveTab }) => (isActiveTab ? 'contents' : 'none')};+`;+const StyledScrollWrapperContainer = styled.div`flex: 1;min-height: 0;@@ -139,6 +150,21 @@ export const PageLayoutTabsRenderer = () => {(tab) => tab.id === activeTabId,);+ const pageLayoutPrerenderedTabIds = useAtomComponentStateValue(+ pageLayoutPrerenderedTabIdsComponentState,+ );++ const tabsToMount = sortedTabs.filter(+ (tab) =>+ tab.id === activeTabId ||+ (!isPageLayoutInEditMode &&+ pageLayoutPrerenderedTabIds.includes(tab.id) &&+ shouldPrerenderPageLayoutTab({+ tab,+ pageLayoutType: currentPageLayout.type,+ })),+ );+return (<PageLayoutWidgetDndProvider><PageLayoutScrollResetEffect@@ -146,6 +172,7 @@ export const PageLayoutTabsRenderer = () => {scrollWrapperInstanceId={scrollWrapperInstanceId}targetRecordId={targetRecordIdentifier?.id}/>+ <PageLayoutPrerenderedTabIdsResetEffect /><StyledContainer hasPinnedTab={isDefined(pinnedLeftTab)}>{isDefined(pinnedLeftTab) && (<PageLayoutLeftPanel@@ -182,9 +209,16 @@ export const PageLayoutTabsRenderer = () => {componentInstanceId={scrollWrapperInstanceId}defaultEnableXScroll={false}>- {isDefined(activeTabId) && activeTabExistsInRenderableTabs && (- <PageLayoutMainContent tabId={activeTabId} />- )}+ {isDefined(activeTabId) &&+ activeTabExistsInRenderableTabs &&+ tabsToMount.map((tab) => (+ <StyledTabContentDisplay+ key={tab.id}+ isActiveTab={tab.id === activeTabId}+ >+ <PageLayoutMainContent tabId={tab.id} />+ </StyledTabContentDisplay>+ ))}</ScrollWrapper></StyledScrollWrapperContainer></StyledTabsAndDashboardContainer>diff --git a/packages/twenty-front/src/modules/page-layout/components/__tests__/PageLayoutTabsRenderer.test.tsx b/packages/twenty-front/src/modules/page-layout/components/__tests__/PageLayoutTabsRenderer.test.tsxindex 7562f063811..350da8f4bd6 100644--- a/packages/twenty-front/src/modules/page-layout/components/__tests__/PageLayoutTabsRenderer.test.tsx+++ b/packages/twenty-front/src/modules/page-layout/components/__tests__/PageLayoutTabsRenderer.test.tsx@@ -4,12 +4,15 @@ import { type ReactNode } from 'react';import {PageLayoutTabLayoutMode,PageLayoutType,+ WidgetType,} from '~/generated-metadata/graphql';let mockActiveTabId = 'hidden-transcript-tab-id';+let mockPrerenderedTabIds: string[] = [];let mockTargetRecordId = 'calendar-event-id';let mockIsInSidePanel = false;const mockSetActiveTabId = jest.fn();+const mockSetPrerenderedTabIds = jest.fn();const homeTab = {__typename: 'PageLayoutTab' as const,@@ -25,6 +28,25 @@ const homeTab = {deletedAt: null,};+const timelineTab = {+ ...homeTab,+ id: 'timeline-tab-id',+ title: 'Timeline',+ position: 1,+ icon: 'IconTimeline',+ layoutMode: PageLayoutTabLayoutMode.VERTICAL_LIST,+};++const frontComponentTab = {+ ...homeTab,+ id: 'front-component-tab-id',+ title: 'App',+ position: 2,+ icon: 'IconApps',+ layoutMode: PageLayoutTabLayoutMode.VERTICAL_LIST,+ widgets: [{ id: 'front-component-widget', type: WidgetType.FRONT_COMPONENT }],+};+jest.mock('@/page-layout/components/dnd/PageLayoutWidgetDndProvider', () => ({PageLayoutWidgetDndProvider: ({ children }: { children: ReactNode }) => (<>{children}</>@@ -60,7 +82,7 @@ jest.mock('@/page-layout/hooks/usePageLayoutAddTabStrategy', () => ({jest.mock('@/page-layout/hooks/usePageLayoutRenderableTabs', () => ({usePageLayoutRenderableTabs: () => ({- tabsToRenderInTabList: [homeTab],+ tabsToRenderInTabList: [homeTab, timelineTab, frontComponentTab],pinnedLeftTab: undefined,}),}));@@ -85,10 +107,17 @@ jest.mock('@/ui/layout/contexts/LayoutRenderingContext', () => ({jest.mock('@/ui/utilities/state/jotai/hooks/useAtomComponentStateValue',() => ({- useAtomComponentStateValue: () => mockActiveTabId,+ useAtomComponentStateValue: (componentState: { key: string }) =>+ componentState.key === 'pageLayoutPrerenderedTabIdsComponentState'+ ? mockPrerenderedTabIds+ : mockActiveTabId,}),);+jest.mock('@/ui/utilities/state/jotai/hooks/useSetAtomComponentState', () => ({+ useSetAtomComponentState: () => mockSetPrerenderedTabIds,+}));+jest.mock('@/ui/utilities/state/jotai/hooks/useAtomComponentState', () => ({useAtomComponentState: () => [mockActiveTabId, mockSetActiveTabId],}));@@ -116,9 +145,11 @@ jest.mock('@/ui/utilities/scroll/components/ScrollWrapper', () => ({describe('PageLayoutTabsRenderer', () => {beforeEach(() => {+ mockPrerenderedTabIds = [];mockTargetRecordId = 'calendar-event-id';mockIsInSidePanel = false;mockSetActiveTabId.mockClear();+ mockSetPrerenderedTabIds.mockClear();});it('does not render content for an active tab filtered out of the tab list', () => {@@ -138,6 +169,46 @@ describe('PageLayoutTabsRenderer', () => {expect(screen.getByText('Rendered tab: home-tab-id')).toBeVisible();});+ it('mounts prerendered vertical-list tabs alongside the active tab', () => {+ mockActiveTabId = 'home-tab-id';+ mockPrerenderedTabIds = ['timeline-tab-id'];++ render(<PageLayoutTabsRenderer />);++ expect(screen.getByText('Rendered tab: home-tab-id')).toBeInTheDocument();+ expect(+ screen.getByText('Rendered tab: timeline-tab-id'),+ ).toBeInTheDocument();+ });++ it('mounts prerendered application widget tabs offscreen alongside the active tab', () => {+ mockActiveTabId = 'timeline-tab-id';+ mockPrerenderedTabIds = ['front-component-tab-id'];++ render(<PageLayoutTabsRenderer />);++ expect(+ screen.getByText('Rendered tab: timeline-tab-id'),+ ).toBeInTheDocument();+ expect(+ screen.getByText('Rendered tab: front-component-tab-id'),+ ).toBeInTheDocument();+ });++ it('does not mount prerendered tabs that are not prerenderable', () => {+ mockActiveTabId = 'timeline-tab-id';+ mockPrerenderedTabIds = ['home-tab-id'];++ render(<PageLayoutTabsRenderer />);++ expect(+ screen.getByText('Rendered tab: timeline-tab-id'),+ ).toBeInTheDocument();+ expect(+ screen.queryByText('Rendered tab: home-tab-id'),+ ).not.toBeInTheDocument();+ });+it('resets the scroll position when the target record changes', () => {mockActiveTabId = 'home-tab-id';diff --git a/packages/twenty-front/src/modules/page-layout/components/__tests__/pageLayoutTabPrerenderContract.test.tsx b/packages/twenty-front/src/modules/page-layout/components/__tests__/pageLayoutTabPrerenderContract.test.tsxnew file mode 100644index 00000000000..dcfb71d0ca0--- /dev/null+++ b/packages/twenty-front/src/modules/page-layout/components/__tests__/pageLayoutTabPrerenderContract.test.tsx@@ -0,0 +1,109 @@+import { ApolloClient, ApolloLink, gql, InMemoryCache } from '@apollo/client';+import { ApolloProvider, useQuery } from '@apollo/client/react';+import { render, screen, waitFor } from '@testing-library/react';+import { Activity } from 'react';+import { of } from 'rxjs';++// Prerendered tabs mount CSS-hidden (display: none) rather than inside a+// hidden <Activity>. This test guards the platform behaviors that choice is+// built on: Apollo's useQuery starts fetching from effects, so it fetches+// under display: none but not under a hidden Activity, and revealing an+// offscreen-mounted tab neither refetches nor flashes a loading state.+const PRERENDER_PROBE_QUERY = gql`+ query PrerenderProbe {+ probe+ }+`;++const createOperationTrackingClient = () => {+ const operationCounts: Record<string, number> = {};++ const link = new ApolloLink((operation) => {+ const operationName = operation.operationName ?? 'anonymous';+ operationCounts[operationName] = (operationCounts[operationName] ?? 0) + 1;++ return of({ data: { probe: 'probe-loaded' } });+ });++ return {+ client: new ApolloClient({ link, cache: new InMemoryCache() }),+ operationCounts,+ };+};++const ProbeWidget = () => {+ const { data, loading } = useQuery<{ probe: string }>(PRERENDER_PROBE_QUERY);++ if (loading && !data) {+ return <div>probe-skeleton</div>;+ }++ return <div>{data?.probe}</div>;+};++const flushMicrotasks = () =>+ new Promise((resolve) => {+ setTimeout(resolve, 50);+ });++const OffscreenProbeTab = ({+ client,+ isActiveTab,+}: {+ client: ApolloClient;+ isActiveTab: boolean;+}) => (+ <ApolloProvider client={client}>+ <div style={{ display: isActiveTab ? 'contents' : 'none' }}>+ <ProbeWidget />+ </div>+ </ApolloProvider>+);++describe('page layout tab prerender contract with offscreen-mounted classic useQuery', () => {+ it('starts the query while the tab content is hidden', async () => {+ const { client, operationCounts } = createOperationTrackingClient();++ render(<OffscreenProbeTab client={client} isActiveTab={false} />);++ await waitFor(() => {+ expect(operationCounts.PrerenderProbe).toBe(1);+ });+ });++ it('reveals offscreen content without a second fetch or loading state', async () => {+ const { client, operationCounts } = createOperationTrackingClient();++ const { rerender } = render(+ <OffscreenProbeTab client={client} isActiveTab={false} />,+ );++ await waitFor(() => {+ expect(operationCounts.PrerenderProbe).toBe(1);+ });++ rerender(<OffscreenProbeTab client={client} isActiveTab={true} />);++ expect(screen.getByText('probe-loaded')).toBeVisible();+ expect(screen.queryByText('probe-skeleton')).not.toBeInTheDocument();+ expect(operationCounts.PrerenderProbe).toBe(1);+ });+});++describe('page layout tab prerender contract with classic useQuery inside Activity', () => {+ it('does not start the query while hidden, so tabs must not regress to it', async () => {+ const { client, operationCounts } = createOperationTrackingClient();++ render(+ <ApolloProvider client={client}>+ <Activity mode="hidden">+ <ProbeWidget />+ </Activity>+ </ApolloProvider>,+ );++ await flushMicrotasks();++ expect(operationCounts.PrerenderProbe).toBeUndefined();+ });+});diff --git a/packages/twenty-front/src/modules/page-layout/constants/MaxPrerenderedPageLayoutTabs.ts b/packages/twenty-front/src/modules/page-layout/constants/MaxPrerenderedPageLayoutTabs.tsnew file mode 100644index 00000000000..144c1873a56--- /dev/null+++ b/packages/twenty-front/src/modules/page-layout/constants/MaxPrerenderedPageLayoutTabs.ts@@ -0,0 +1,3 @@+// Each prerendered tab is a mounted (hidden) widget tree with live queries;+// the cap bounds the memory and background work a hover trail can accumulate.+export const MAX_PRERENDERED_PAGE_LAYOUT_TABS = 3;diff --git a/packages/twenty-front/src/modules/page-layout/constants/PageLayoutTabPrerenderHoverIntentDelayMs.ts b/packages/twenty-front/src/modules/page-layout/constants/PageLayoutTabPrerenderHoverIntentDelayMs.tsnew file mode 100644index 00000000000..ffc0a96a641--- /dev/null+++ b/packages/twenty-front/src/modules/page-layout/constants/PageLayoutTabPrerenderHoverIntentDelayMs.ts@@ -0,0 +1,3 @@+// Sweeping the cursor across the tab bar should not prerender every tab it+// crosses; only a pause long enough to signal intent triggers the mount.+export const PAGE_LAYOUT_TAB_PRERENDER_HOVER_INTENT_DELAY_MS = 100;diff --git a/packages/twenty-front/src/modules/page-layout/constants/PrerenderablePageLayoutWidgetTypes.ts b/packages/twenty-front/src/modules/page-layout/constants/PrerenderablePageLayoutWidgetTypes.tsnew file mode 100644index 00000000000..b8b931e3646--- /dev/null+++ b/packages/twenty-front/src/modules/page-layout/constants/PrerenderablePageLayoutWidgetTypes.ts@@ -0,0 +1,19 @@+import { WidgetType } from '~/generated-metadata/graphql';++// Prerendered tabs mount for real while hidden, so only widgets that behave+// under display: none are eligible. Data cards fetch and render lists without+// grabbing focus. FRONT_COMPONENT and IFRAME boot their sandbox worker or+// embed on mount, which is the point: workspace applications are trusted, so+// warming them on hover is wanted. Excluded: GRAPH and RECORD_TABLE measure+// their container, which is zero-sized while hidden.+export const PRERENDERABLE_PAGE_LAYOUT_WIDGET_TYPES: WidgetType[] = [+ WidgetType.FIELDS,+ WidgetType.TIMELINE,+ WidgetType.TASKS,+ WidgetType.NOTES,+ WidgetType.FILES,+ WidgetType.EMAILS,+ WidgetType.CALENDAR,+ WidgetType.FRONT_COMPONENT,+ WidgetType.IFRAME,+];diff --git a/packages/twenty-front/src/modules/page-layout/hooks/__tests__/usePrerenderPageLayoutTabOnHover.test.tsx b/packages/twenty-front/src/modules/page-layout/hooks/__tests__/usePrerenderPageLayoutTabOnHover.test.tsxnew file mode 100644index 00000000000..c8c34b3f0e4--- /dev/null+++ b/packages/twenty-front/src/modules/page-layout/hooks/__tests__/usePrerenderPageLayoutTabOnHover.test.tsx@@ -0,0 +1,81 @@+import { act, renderHook } from '@testing-library/react';++import { PAGE_LAYOUT_TAB_PRERENDER_HOVER_INTENT_DELAY_MS } from '@/page-layout/constants/PageLayoutTabPrerenderHoverIntentDelayMs';+import { usePrerenderPageLayoutTabOnHover } from '@/page-layout/hooks/usePrerenderPageLayoutTabOnHover';+import { pageLayoutPrerenderedTabIdsComponentState } from '@/page-layout/states/pageLayoutPrerenderedTabIdsComponentState';+import { useAtomComponentStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomComponentStateValue';+import { PageLayoutTestWrapper } from './PageLayoutTestWrapper';++describe('usePrerenderPageLayoutTabOnHover', () => {+ beforeEach(() => {+ jest.useFakeTimers();+ });++ afterEach(() => {+ jest.useRealTimers();+ });++ const renderHoverHook = () =>+ renderHook(+ () => ({+ hover: usePrerenderPageLayoutTabOnHover(),+ pageLayoutPrerenderedTabIds: useAtomComponentStateValue(+ pageLayoutPrerenderedTabIdsComponentState,+ ),+ }),+ { wrapper: PageLayoutTestWrapper },+ );++ it('prerenders a tab only after the hover intent delay', () => {+ const { result } = renderHoverHook();++ act(() => {+ result.current.hover.handleTabMouseEnter('tab-1');+ });++ act(() => {+ jest.advanceTimersByTime(+ PAGE_LAYOUT_TAB_PRERENDER_HOVER_INTENT_DELAY_MS - 1,+ );+ });++ expect(result.current.pageLayoutPrerenderedTabIds).toEqual([]);++ act(() => {+ jest.advanceTimersByTime(1);+ });++ expect(result.current.pageLayoutPrerenderedTabIds).toEqual(['tab-1']);+ });++ it('does not prerender when the cursor leaves before the delay', () => {+ const { result } = renderHoverHook();++ act(() => {+ result.current.hover.handleTabMouseEnter('tab-1');+ result.current.hover.handleTabMouseLeave();+ });++ act(() => {+ jest.advanceTimersByTime(PAGE_LAYOUT_TAB_PRERENDER_HOVER_INTENT_DELAY_MS);+ });++ expect(result.current.pageLayoutPrerenderedTabIds).toEqual([]);+ });++ it('only prerenders the last tab of a quick hover trail', () => {+ const { result } = renderHoverHook();++ act(() => {+ result.current.hover.handleTabMouseEnter('tab-1');+ result.current.hover.handleTabMouseLeave();+ result.current.hover.handleTabMouseEnter('tab-2');+ });++ act(() => {+ jest.advanceTimersByTime(PAGE_LAYOUT_TAB_PRERENDER_HOVER_INTENT_DELAY_MS);+ });++ expect(result.current.pageLayoutPrerenderedTabIds).toEqual(['tab-2']);+ });+});diff --git a/packages/twenty-front/src/modules/page-layout/hooks/usePrerenderPageLayoutTab.ts b/packages/twenty-front/src/modules/page-layout/hooks/usePrerenderPageLayoutTab.tsnew file mode 100644index 00000000000..a0d245da327--- /dev/null+++ b/packages/twenty-front/src/modules/page-layout/hooks/usePrerenderPageLayoutTab.ts@@ -0,0 +1,22 @@+import { useCallback } from 'react';++import { pageLayoutPrerenderedTabIdsComponentState } from '@/page-layout/states/pageLayoutPrerenderedTabIdsComponentState';+import { computeNextPrerenderedTabIds } from '@/page-layout/utils/computeNextPrerenderedTabIds';+import { useSetAtomComponentState } from '@/ui/utilities/state/jotai/hooks/useSetAtomComponentState';++export const usePrerenderPageLayoutTab = () => {+ const setPageLayoutPrerenderedTabIds = useSetAtomComponentState(+ pageLayoutPrerenderedTabIdsComponentState,+ );++ const prerenderPageLayoutTab = useCallback(+ (tabId: string) => {+ setPageLayoutPrerenderedTabIds((currentTabIds) =>+ computeNextPrerenderedTabIds({ currentTabIds, tabId }),+ );+ },+ [setPageLayoutPrerenderedTabIds],+ );++ return { prerenderPageLayoutTab };+};diff --git a/packages/twenty-front/src/modules/page-layout/hooks/usePrerenderPageLayoutTabOnHover.ts b/packages/twenty-front/src/modules/page-layout/hooks/usePrerenderPageLayoutTabOnHover.tsnew file mode 100644index 00000000000..6103054fd07--- /dev/null+++ b/packages/twenty-front/src/modules/page-layout/hooks/usePrerenderPageLayoutTabOnHover.ts@@ -0,0 +1,23 @@+import { useDebouncedCallback } from 'use-debounce';++import { PAGE_LAYOUT_TAB_PRERENDER_HOVER_INTENT_DELAY_MS } from '@/page-layout/constants/PageLayoutTabPrerenderHoverIntentDelayMs';+import { usePrerenderPageLayoutTab } from '@/page-layout/hooks/usePrerenderPageLayoutTab';++export const usePrerenderPageLayoutTabOnHover = () => {+ const { prerenderPageLayoutTab } = usePrerenderPageLayoutTab();++ const debouncedPrerenderPageLayoutTab = useDebouncedCallback(+ prerenderPageLayoutTab,+ PAGE_LAYOUT_TAB_PRERENDER_HOVER_INTENT_DELAY_MS,+ );++ const handleTabMouseEnter = (tabId: string) => {+ debouncedPrerenderPageLayoutTab(tabId);+ };++ const handleTabMouseLeave = () => {+ debouncedPrerenderPageLayoutTab.cancel();+ };++ return { handleTabMouseEnter, handleTabMouseLeave };+};diff --git a/packages/twenty-front/src/modules/page-layout/states/pageLayoutPrerenderedTabIdsComponentState.ts b/packages/twenty-front/src/modules/page-layout/states/pageLayoutPrerenderedTabIdsComponentState.tsnew file mode 100644index 00000000000..0752786b501--- /dev/null+++ b/packages/twenty-front/src/modules/page-layout/states/pageLayoutPrerenderedTabIdsComponentState.ts@@ -0,0 +1,11 @@+import { TabListComponentInstanceContext } from '@/ui/layout/tab-list/states/contexts/TabListComponentInstanceContext';+import { createAtomComponentState } from '@/ui/utilities/state/jotai/utils/createAtomComponentState';++// Tab ids the user hovered with intent, most recent last. The tabs renderer+// keeps them mounted but hidden so opening one shows already-fetched content.+export const pageLayoutPrerenderedTabIdsComponentState =+ createAtomComponentState<string[]>({+ key: 'pageLayoutPrerenderedTabIdsComponentState',+ defaultValue: [],+ componentInstanceContext: TabListComponentInstanceContext,+ });diff --git a/packages/twenty-front/src/modules/page-layout/utils/__tests__/computeNextPrerenderedTabIds.test.ts b/packages/twenty-front/src/modules/page-layout/utils/__tests__/computeNextPrerenderedTabIds.test.tsnew file mode 100644index 00000000000..332433892df--- /dev/null+++ b/packages/twenty-front/src/modules/page-layout/utils/__tests__/computeNextPrerenderedTabIds.test.ts@@ -0,0 +1,46 @@+import { MAX_PRERENDERED_PAGE_LAYOUT_TABS } from '@/page-layout/constants/MaxPrerenderedPageLayoutTabs';+import { computeNextPrerenderedTabIds } from '@/page-layout/utils/computeNextPrerenderedTabIds';++describe('computeNextPrerenderedTabIds', () => {+ it('appends a new tab id most recent last', () => {+ expect(+ computeNextPrerenderedTabIds({+ currentTabIds: ['tab-1'],+ tabId: 'tab-2',+ }),+ ).toEqual(['tab-1', 'tab-2']);+ });++ it('moves an already present tab id to the end', () => {+ expect(+ computeNextPrerenderedTabIds({+ currentTabIds: ['tab-1', 'tab-2'],+ tabId: 'tab-1',+ }),+ ).toEqual(['tab-2', 'tab-1']);+ });++ it('returns the same reference when the tab id is already last', () => {+ const currentTabIds = ['tab-1', 'tab-2'];++ expect(+ computeNextPrerenderedTabIds({ currentTabIds, tabId: 'tab-2' }),+ ).toBe(currentTabIds);+ });++ it('evicts the oldest tab ids beyond the cap', () => {+ const currentTabIds = Array.from(+ { length: MAX_PRERENDERED_PAGE_LAYOUT_TABS },+ (_, index) => `tab-${index}`,+ );++ const nextTabIds = computeNextPrerenderedTabIds({+ currentTabIds,+ tabId: 'tab-new',+ });++ expect(nextTabIds).toHaveLength(MAX_PRERENDERED_PAGE_LAYOUT_TABS);+ expect(nextTabIds.at(0)).toBe('tab-1');+ expect(nextTabIds.at(-1)).toBe('tab-new');+ });+});diff --git a/packages/twenty-front/src/modules/page-layout/utils/__tests__/shouldPrerenderPageLayoutTab.test.ts b/packages/twenty-front/src/modules/page-layout/utils/__tests__/shouldPrerenderPageLayoutTab.test.tsnew file mode 100644index 00000000000..af155d21601--- /dev/null+++ b/packages/twenty-front/src/modules/page-layout/utils/__tests__/shouldPrerenderPageLayoutTab.test.ts@@ -0,0 +1,119 @@+import { type PageLayoutTab } from '@/page-layout/types/PageLayoutTab';+import { shouldPrerenderPageLayoutTab } from '@/page-layout/utils/shouldPrerenderPageLayoutTab';+import {+ PageLayoutTabLayoutMode,+ PageLayoutType,+ WidgetConfigurationType,+ WidgetType,+} from '~/generated-metadata/graphql';++describe('shouldPrerenderPageLayoutTab', () => {+ const createMockWidget = (type: WidgetType): PageLayoutTab['widgets'][0] => ({+ isSystemSideEffect: false,+ universalIdentifier: 'universal-identifier-mock',+ __typename: 'PageLayoutWidget',+ id: `widget-${type}`,+ applicationId: '',+ isActive: true,+ pageLayoutTabId: 'tab-1',+ title: `Widget ${type}`,+ type,+ objectMetadataId: null,+ position: {+ layoutMode: PageLayoutTabLayoutMode.VERTICAL_LIST,+ __typename: 'PageLayoutWidgetGridPosition',+ row: 0,+ column: 0,+ rowSpan: 1,+ columnSpan: 1,+ },+ configuration: {+ __typename: 'FieldsConfiguration',+ configurationType: WidgetConfigurationType.FIELDS,+ viewId: null,+ },+ createdAt: '2024-01-01T00:00:00.000Z',+ updatedAt: '2024-01-01T00:00:00.000Z',+ });++ const createMockTab = ({+ layoutMode,+ widgetTypes,+ }: {+ layoutMode?: PageLayoutTabLayoutMode;+ widgetTypes: WidgetType[];+ }): PageLayoutTab => ({+ isSystemSideEffect: false,+ universalIdentifier: 'universal-identifier-mock',+ id: 'tab-1',+ applicationId: '',+ isActive: true,+ pageLayoutId: 'page-layout-1',+ title: 'Tab 1',+ position: 0,+ layoutMode,+ widgets: widgetTypes.map(createMockWidget),+ createdAt: '2024-01-01T00:00:00.000Z',+ updatedAt: '2024-01-01T00:00:00.000Z',+ });++ it('allows a vertical-list record tab with only prerenderable widgets', () => {+ expect(+ shouldPrerenderPageLayoutTab({+ tab: createMockTab({+ layoutMode: PageLayoutTabLayoutMode.VERTICAL_LIST,+ widgetTypes: [WidgetType.TIMELINE, WidgetType.EMAILS],+ }),+ pageLayoutType: PageLayoutType.RECORD_PAGE,+ }),+ ).toBe(true);+ });++ it('rejects non record-page layouts', () => {+ expect(+ shouldPrerenderPageLayoutTab({+ tab: createMockTab({+ layoutMode: PageLayoutTabLayoutMode.VERTICAL_LIST,+ widgetTypes: [WidgetType.TIMELINE],+ }),+ pageLayoutType: PageLayoutType.DASHBOARD,+ }),+ ).toBe(false);+ });++ it('rejects grid tabs', () => {+ expect(+ shouldPrerenderPageLayoutTab({+ tab: createMockTab({+ layoutMode: PageLayoutTabLayoutMode.GRID,+ widgetTypes: [WidgetType.TIMELINE],+ }),+ pageLayoutType: PageLayoutType.RECORD_PAGE,+ }),+ ).toBe(false);+ });++ it('allows tabs holding workspace application widgets', () => {+ expect(+ shouldPrerenderPageLayoutTab({+ tab: createMockTab({+ layoutMode: PageLayoutTabLayoutMode.VERTICAL_LIST,+ widgetTypes: [WidgetType.FRONT_COMPONENT, WidgetType.IFRAME],+ }),+ pageLayoutType: PageLayoutType.RECORD_PAGE,+ }),+ ).toBe(true);+ });++ it('rejects tabs containing a non-prerenderable widget', () => {+ expect(+ shouldPrerenderPageLayoutTab({+ tab: createMockTab({+ layoutMode: PageLayoutTabLayoutMode.VERTICAL_LIST,+ widgetTypes: [WidgetType.TIMELINE, WidgetType.RECORD_TABLE],+ }),+ pageLayoutType: PageLayoutType.RECORD_PAGE,+ }),+ ).toBe(false);+ });+});diff --git a/packages/twenty-front/src/modules/page-layout/utils/computeNextPrerenderedTabIds.ts b/packages/twenty-front/src/modules/page-layout/utils/computeNextPrerenderedTabIds.tsnew file mode 100644index 00000000000..7c0f1bffa41--- /dev/null+++ b/packages/twenty-front/src/modules/page-layout/utils/computeNextPrerenderedTabIds.ts@@ -0,0 +1,17 @@+import { MAX_PRERENDERED_PAGE_LAYOUT_TABS } from '@/page-layout/constants/MaxPrerenderedPageLayoutTabs';++export const computeNextPrerenderedTabIds = ({+ currentTabIds,+ tabId,+}: {+ currentTabIds: string[];+ tabId: string;+}): string[] => {+ if (currentTabIds.at(-1) === tabId) {+ return currentTabIds;+ }++ return [...currentTabIds.filter((id) => id !== tabId), tabId].slice(+ -MAX_PRERENDERED_PAGE_LAYOUT_TABS,+ );+};diff --git a/packages/twenty-front/src/modules/page-layout/utils/shouldPrerenderPageLayoutTab.ts b/packages/twenty-front/src/modules/page-layout/utils/shouldPrerenderPageLayoutTab.tsnew file mode 100644index 00000000000..d282c9bc44f--- /dev/null+++ b/packages/twenty-front/src/modules/page-layout/utils/shouldPrerenderPageLayoutTab.ts@@ -0,0 +1,28 @@+import { PRERENDERABLE_PAGE_LAYOUT_WIDGET_TYPES } from '@/page-layout/constants/PrerenderablePageLayoutWidgetTypes';+import { type PageLayoutTab } from '@/page-layout/types/PageLayoutTab';+import {+ PageLayoutTabLayoutMode,+ PageLayoutType,+} from '~/generated-metadata/graphql';++export const shouldPrerenderPageLayoutTab = ({+ tab,+ pageLayoutType,+}: {+ tab: PageLayoutTab;+ pageLayoutType: PageLayoutType;+}): boolean => {+ if (pageLayoutType !== PageLayoutType.RECORD_PAGE) {+ return false;+ }++ // Grid tabs size their widgets from the container, which measures zero+ // while hidden; vertical lists lay out correctly on reveal.+ if (tab.layoutMode !== PageLayoutTabLayoutMode.VERTICAL_LIST) {+ return false;+ }++ return tab.widgets.every((widget) =>+ PRERENDERABLE_PAGE_LAYOUT_WIDGET_TYPES.includes(widget.type),+ );+};diff --git a/packages/twenty-ui/src/input/TabButton/TabButton.tsx b/packages/twenty-ui/src/input/TabButton/TabButton.tsxindex 5b392b0dce3..6c316015aee 100644--- a/packages/twenty-ui/src/input/TabButton/TabButton.tsx+++ b/packages/twenty-ui/src/input/TabButton/TabButton.tsx@@ -30,6 +30,8 @@ type TabButtonProps = {contentSize?: 'sm' | 'md';disableTestId?: boolean;tooltipContent?: string;+ onMouseEnter?: () => void;+ onMouseLeave?: () => void;};export const TabButton = ({@@ -47,6 +49,8 @@ export const TabButton = ({contentSize = 'sm',disableTestId = false,tooltipContent,+ onMouseEnter,+ onMouseLeave,}: TabButtonProps) => {const tabElementId = `tab-${id}`;@@ -59,6 +63,8 @@ export const TabButton = ({to={to}className={className}onClick={onClick}+ onMouseEnter={onMouseEnter}+ onMouseLeave={onMouseLeave}><TabContentid={id}