Skip to content

TagSpaces is an offline, open source, document manager with tagging support

chore: performance optimization for list and grid perspective

Ilian Sapundshiev93df2eb303f0
diff --git a/package-lock.json b/package-lock.json
index 172a4a7e0..78f3cffa4 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -173,7 +173,7 @@
"yarn": "please-use-npm"
},
"optionalDependencies": {
- "@tagspacespro/tagspacespro": "5.0.236"
+ "@tagspacespro/tagspacespro": "5.0.237"
}
},
"node_modules/@ampproject/remapping": {
@@ -18551,9 +18551,9 @@
}
},
"node_modules/@tagspacespro/tagspacespro": {
- "version": "5.0.236",
- "resolved": "https://npm.pkg.github.com/download/@tagspacespro/tagspacespro/5.0.236/c09c0103b19b1ff485a722f3becca99f9815cfcb",
- "integrity": "sha512-XVJlvCLYLwwz0kNygwLOIjw23oyoSfpi3PV+D3P69rJyxjirAxZ75IQje9CsTLK+4LY1RwrODmtDvrm92ku/AQ==",
+ "version": "5.0.237",
+ "resolved": "https://npm.pkg.github.com/download/@tagspacespro/tagspacespro/5.0.237/b08845ebf7905fd074ff84d550d32b3ce6acc5bf",
+ "integrity": "sha512-2zLHtG65MezTOGfMZS4dVOGMfKJE8w46gbrgEsvuHBBYU6FLt/Rx75XEkvbpivsIB0/q/XHGrsclywRdNMzhtw==",
"license": "Proprietary",
"optional": true
},
diff --git a/package.json b/package.json
index 7b7ccf76b..d19319915 100644
--- a/package.json
+++ b/package.json
@@ -242,7 +242,7 @@
"zod-to-json-schema": "3.25.1"
},
"optionalDependencies": {
- "@tagspacespro/tagspacespro": "5.0.236"
+ "@tagspacespro/tagspacespro": "5.0.237"
},
"devDependencies": {
"@electron/rebuild": "4.0.3",
diff --git a/src/renderer/components/RenderPerspective.tsx b/src/renderer/components/RenderPerspective.tsx
index 8ff0c807d..90e1018db 100644
--- a/src/renderer/components/RenderPerspective.tsx
+++ b/src/renderer/components/RenderPerspective.tsx
@@ -16,7 +16,7 @@
*
*/
-import React, { useEffect, useReducer } from 'react';
+import React from 'react';
import AppConfig from '-/AppConfig';
@@ -28,11 +28,9 @@ import { PerspectiveSettingsContextProvider } from '-/hooks/PerspectiveSettingsC
import { ThumbGenerationContextProvider } from '-/hooks/ThumbGenerationContextProvider';
import { useCurrentLocationContext } from '-/hooks/useCurrentLocationContext';
import { useDirectoryContentContext } from '-/hooks/useDirectoryContentContext';
-import { useEditedEntryMetaContext } from '-/hooks/useEditedEntryMetaContext';
import { PerspectiveIDs } from '-/perspectives';
import { SortedDirContextProvider } from '-/perspectives/grid/hooks/SortedDirContextProvider';
import { Pro } from '-/pro';
-import useFirstRender from '-/utils/useFirstRender';
import { NativeTypes } from 'react-dnd-html5-backend';
const GridPerspective = React.lazy(
@@ -175,26 +173,8 @@ interface Props {}
function RenderPerspective(props: Props) {
const { currentLocationId } = useCurrentLocationContext();
const { currentPerspective } = useDirectoryContentContext();
- const { metaActions } = useEditedEntryMetaContext();
- const [ignored, forceUpdate] = useReducer((x) => x + 1, 0, undefined);
- const firstRender = useFirstRender();
-
- useEffect(() => {
- if (!firstRender && metaActions && metaActions.length > 0) {
- for (const action of metaActions) {
- if (action.action === 'perspectiveChange') {
- forceUpdate();
- }
- }
- }
- }, [metaActions]);
const showWelcomePanel = !currentLocationId;
- //!currentDirectoryPath && currentDirectoryEntries.length < 1;
-
- if (showWelcomePanel) {
- return AppConfig.ExtShowWelcomePanel ? <WelcomePanelAsync /> : null;
- }
function getPerspectiveComponent() {
if (currentPerspective === PerspectiveIDs.LIST) {
@@ -215,9 +195,13 @@ function RenderPerspective(props: Props) {
if (Pro && currentPerspective === PerspectiveIDs.CALENDAR) {
return <CalendarPerspectiveAsync />;
}
-
return <GridPerspectiveAsync />;
}
+
+ if (showWelcomePanel) {
+ return AppConfig.ExtShowWelcomePanel ? <WelcomePanelAsync /> : null;
+ }
+
const { FILE } = NativeTypes;
return (
<TargetFileBox style={{ height: '100%' }} accepts={[FILE]}>
diff --git a/src/renderer/components/TagContainerDnd.tsx b/src/renderer/components/TagContainerDnd.tsx
index 28d4f0da9..716ee1ae1 100644
--- a/src/renderer/components/TagContainerDnd.tsx
+++ b/src/renderer/components/TagContainerDnd.tsx
@@ -27,6 +27,7 @@ import TagContainer from './TagContainer';
import { TS } from '-/tagspaces.namespace';
import { useCurrentLocationContext } from '-/hooks/useCurrentLocationContext';
import { useTaggingActionsContext } from '-/hooks/useTaggingActionsContext';
+import { useSelectedEntriesRef } from '-/hooks/useSelectedEntriesRef';
import { useSelector } from 'react-redux';
import { getTagDelimiter } from '-/reducers/settings';
@@ -56,7 +57,6 @@ interface Props {
) => void;
editTagForEntry?: (path: string, tag: TS.Tag) => void;
deleteIcon?: Object;
- selectedEntries: Array<TS.FileSystemEntry>;
reorderTags?: boolean;
}
@@ -74,11 +74,14 @@ const TagContainerDnd = (props: Props) => {
changeTagOrder,
editTagForEntry,
moveTag,
- selectedEntries,
} = props;
const { addTags } = useTaggingActionsContext();
const { currentLocation } = useCurrentLocationContext();
+ // Read latest selectedEntries on demand from a ref so this component does
+ // not subscribe to selection re-renders. The drop handler fires on user
+ // gesture, not on render — reading ref.current at gesture time is correct.
+ const selectedEntriesRef = useSelectedEntriesRef();
const tagContainerRef = useRef<HTMLSpanElement>(null);
const tagDelimiter: string = useSelector(getTagDelimiter);
@@ -102,6 +105,7 @@ const TagContainerDnd = (props: Props) => {
}
} else if (dropResult && dropResult.entry) {
// console.log(`Dropped item: ${item.tag.title} onto file: ${dropResult.entry.path}!`);
+ const selectedEntries = selectedEntriesRef.current ?? [];
if (
selectedEntries.some((entry) => entry.path === dropResult.entry.path)
) {
diff --git a/src/renderer/components/TagLibrary.tsx b/src/renderer/components/TagLibrary.tsx
index 104bc6eb9..bd0819732 100644
--- a/src/renderer/components/TagLibrary.tsx
+++ b/src/renderer/components/TagLibrary.tsx
@@ -226,7 +226,6 @@ function TagLibrary({ reduceHeightBy }: Props) {
handleTagMenu={handleTagMenu}
moveTag={moveTag}
changeTagOrder={changeTagOrder}
- selectedEntries={selectedEntries}
/>
);
})}
diff --git a/src/renderer/components/TagsOverflowChip.tsx b/src/renderer/components/TagsOverflowChip.tsx
new file mode 100644
index 000000000..d6060c93d
--- /dev/null
+++ b/src/renderer/components/TagsOverflowChip.tsx
@@ -0,0 +1,109 @@
+/**
+ * TagSpaces - universal file and folder organizer
+ * Copyright (C) 2026-present TagSpaces GmbH
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License (version 3) as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
+
+import React, { useState } from 'react';
+import { Box, Popover } from '@mui/material';
+import { useTranslation } from 'react-i18next';
+import TagContainer from '-/components/TagContainer';
+import { TS } from '-/tagspaces.namespace';
+
+interface Props {
+ remaining: TS.Tag[];
+ entry: TS.FileSystemEntry;
+ handleTagMenu?: (
+ event: Object,
+ tag: TS.Tag,
+ entry: TS.FileSystemEntry,
+ ) => void;
+}
+
+// "+N" chip rendered after the visible tags. Click opens a popover that lists
+// the rest using the same TagContainer the cell would have rendered inline,
+// so styling, color, and click behaviour stay consistent.
+function TagsOverflowChip({ remaining, entry, handleTagMenu }: Props) {
+ const { t } = useTranslation();
+ const [anchorEl, setAnchorEl] = useState<HTMLElement | null>(null);
+
+ if (!remaining || remaining.length === 0) return null;
+
+ const open = Boolean(anchorEl);
+ const label = `+${remaining.length}`;
+
+ return (
+ <>
+ <Box
+ component="span"
+ role="button"
+ aria-label={t('core:moreTags', { count: remaining.length })}
+ title={t('core:moreTags', { count: remaining.length })}
+ onClick={(event) => {
+ event.stopPropagation();
+ setAnchorEl(event.currentTarget);
+ }}
+ sx={{
+ display: 'inline-flex',
+ alignItems: 'center',
+ height: 18,
+ padding: '0 6px',
+ margin: '2px 2px 0 2px',
+ borderRadius: 2,
+ fontSize: 12,
+ lineHeight: '18px',
+ cursor: 'pointer',
+ backgroundColor: 'rgba(0,0,0,0.45)',
+ color: '#fff',
+ userSelect: 'none',
+ '&:hover': { backgroundColor: 'rgba(0,0,0,0.65)' },
+ }}
+ >
+ {label}
+ </Box>
+ {open && (
+ <Popover
+ open={open}
+ anchorEl={anchorEl}
+ onClose={() => setAnchorEl(null)}
+ anchorOrigin={{ vertical: 'bottom', horizontal: 'left' }}
+ transformOrigin={{ vertical: 'top', horizontal: 'left' }}
+ onClick={(e) => e.stopPropagation()}
+ >
+ <Box
+ sx={{
+ padding: 1,
+ maxWidth: 320,
+ display: 'flex',
+ flexWrap: 'wrap',
+ gap: 0.5,
+ }}
+ >
+ {remaining.map((tag) => (
+ <TagContainer
+ tag={tag}
+ key={(entry?.path ?? '') + ':' + tag.title}
+ entry={entry}
+ handleTagMenu={handleTagMenu}
+ />
+ ))}
+ </Box>
+ </Popover>
+ )}
+ </>
+ );
+}
+
+export default React.memo(TagsOverflowChip);
diff --git a/src/renderer/hooks/DirectoryContentContextProvider.tsx b/src/renderer/hooks/DirectoryContentContextProvider.tsx
index 2689d4485..634e7cbdb 100644
--- a/src/renderer/hooks/DirectoryContentContextProvider.tsx
+++ b/src/renderer/hooks/DirectoryContentContextProvider.tsx
@@ -56,6 +56,7 @@ import {
cleanTrailingDirSeparator,
extractContainingDirectoryPath,
extractParentDirectoryPath,
+ extractTagsAsObjects,
getMetaFileLocationForDir,
getMetaFileLocationForFile,
getThumbFileLocationForDirectory,
@@ -647,10 +648,40 @@ export const DirectoryContentContextProvider = ({
return defaultGridSettings;
}
+ // Parse filename-encoded tags once per entry at load time. Cells used to
+ // call extractTagsAsObjects() in their render path; doing it here means
+ // 100 rendered cells skip 100 regex passes per re-render cycle. We keep the
+ // existing array reference for unchanged entries — we only mutate when an
+ // entry is missing parsedNameTags (first time we see it).
+ function ensureParsedNameTags(
+ dirEntries: TS.FileSystemEntry[],
+ ): TS.FileSystemEntry[] {
+ if (!dirEntries || dirEntries.length === 0) return dirEntries;
+ for (const entry of dirEntries) {
+ if (!entry || entry.parsedNameTags !== undefined) continue;
+ if (!entry.isFile) {
+ entry.parsedNameTags = [];
+ continue;
+ }
+ const loc = entry.locationID ? findLocation(entry.locationID) : undefined;
+ const dirSep = loc?.getDirSeparator() ?? AppConfig.dirSeparator;
+ try {
+ entry.parsedNameTags = extractTagsAsObjects(
+ entry.name,
+ tagDelimiter,
+ dirSep,
+ );
+ } catch {
+ entry.parsedNameTags = [];
+ }
+ }
+ return dirEntries;
+ }
+
function setCurrentDirectoryEntries(dirEntries: TS.FileSystemEntry[]) {
cancelAbort();
if (dirEntries && dirEntries.length > 0) {
- currentDirectoryEntries.current = dirEntries; //[...dirEntries];
+ currentDirectoryEntries.current = ensureParsedNameTags(dirEntries);
forceUpdate();
} else if (currentDirectoryEntries.current.length > 0) {
currentDirectoryEntries.current = [];
diff --git a/src/renderer/hooks/PaginationContextProvider.tsx b/src/renderer/hooks/PaginationContextProvider.tsx
index be1f90bdb..99de811b3 100644
--- a/src/renderer/hooks/PaginationContextProvider.tsx
+++ b/src/renderer/hooks/PaginationContextProvider.tsx
@@ -26,15 +26,13 @@ import { useEditedEntryMetaContext } from '-/hooks/useEditedEntryMetaContext';
type PaginationContextData = {
page: number;
- //pageFiles: TS.FileSystemEntry[];
- getResentPageFiles: () => TS.FileSystemEntry[];
+ pageFiles: TS.FileSystemEntry[];
setCurrentPage: (page?: number) => void;
};
export const PaginationContext = createContext<PaginationContextData>({
page: 1,
- //pageFiles: [],
- getResentPageFiles: undefined,
+ pageFiles: undefined,
setCurrentPage: undefined,
});
@@ -67,14 +65,6 @@ export const PaginationContextProvider = ({
}*/
}, [currentDirectoryPath, searchQuery, settings]); //, isSearchMode isMetaFolderExist]);
- /*const pageFiles: TS.FileSystemEntry[] = useMemo(() => {
- return getPageFiles(page, sortedDirContent);
- }, [page, sortedDirContent, settings]);*/
-
- function getResentPageFiles() {
- return getPageFiles(page, sortedDirContent);
- }
-
function getPageFiles(currentPage: number, dirContent: TS.FileSystemEntry[]) {
const gridPageLimit =
settings && settings.gridPageLimit
@@ -97,6 +87,11 @@ export const PaginationContextProvider = ({
return files;
}
+ const pageFiles = useMemo(
+ () => getPageFiles(page, sortedDirContent),
+ [page, sortedDirContent, settings, showDirectories],
+ );
+
function setCurrentPage(currentPage?: number) {
const cPage = currentPage ? currentPage : initPage;
if (page !== cPage) {
@@ -112,13 +107,14 @@ export const PaginationContextProvider = ({
}
}
- const context = useMemo(() => {
- return {
+ const context = useMemo(
+ () => ({
page,
- getResentPageFiles,
+ pageFiles,
setCurrentPage,
- };
- }, [page, currentDirectoryPath, sortedDirContent, settings]);
+ }),
+ [page, pageFiles],
+ );
return (
<PaginationContext.Provider value={context}>
diff --git a/src/renderer/hooks/PerspectiveSettingsContextProvider.tsx b/src/renderer/hooks/PerspectiveSettingsContextProvider.tsx
index 7f10fde74..dee88e620 100644
--- a/src/renderer/hooks/PerspectiveSettingsContextProvider.tsx
+++ b/src/renderer/hooks/PerspectiveSettingsContextProvider.tsx
@@ -45,6 +45,7 @@ type PerspectiveSettingsContextData = {
showEntriesDescription: boolean;
showTags: boolean;
gridPageLimit: number;
+ maxVisibleTags: number;
folderVizType: TS.FolderVizType;
calendarType?: TS.CalendarType;
calendarGroupByDateTags?: boolean;
@@ -75,6 +76,7 @@ export const PerspectiveSettingsContext =
showEntriesDescription: true,
showTags: true,
gridPageLimit: 100,
+ maxVisibleTags: 4,
showFolderContent: false,
layoutType: 'grid',
folderVizType: 'tree',
@@ -120,7 +122,10 @@ export const PerspectiveSettingsContextProvider = ({
settings.current = getSettings(currentPerspective, directoryMeta);
forceUpdate();
}
- }, [currentDirectoryPath, directoryMeta]);
+ // currentPerspective is in deps so per-perspective settings reload on
+ // perspective switch directly, instead of relying on the outer
+ // RenderPerspective forceUpdate/remount cascade we removed.
+ }, [currentDirectoryPath, directoryMeta, currentPerspective]);
useEffect(() => {
if (!firstRender && metaActions && metaActions.length > 0) {
@@ -318,6 +323,7 @@ export const PerspectiveSettingsContextProvider = ({
entrySize: settings.current.entrySize,
thumbnailMode: settings.current.thumbnailMode,
gridPageLimit: settings.current.gridPageLimit,
+ maxVisibleTags: settings.current.maxVisibleTags,
folderVizType: settings.current.folderVizType,
calendarType: settings.current.calendarType,
calendarGroupByDateTags: settings.current.calendarGroupByDateTags,
diff --git a/src/renderer/hooks/ThumbGenerationContextProvider.tsx b/src/renderer/hooks/ThumbGenerationContextProvider.tsx
index e4a4d15e0..f3ce9e0d6 100644
--- a/src/renderer/hooks/ThumbGenerationContextProvider.tsx
+++ b/src/renderer/hooks/ThumbGenerationContextProvider.tsx
@@ -145,7 +145,7 @@ export const ThumbGenerationContextProvider = ({
setFolderThumbnailPromise,
} = usePlatformFacadeContext();
const { metaActions } = useEditedEntryMetaContext();
- const { getResentPageFiles } = usePaginationContext();
+ const { pageFiles } = usePaginationContext();
const { setGeneratingThumbs } = useNotificationContext();
const useGenerateThumbnails = useSelector(getUseGenerateThumbnails);
const enableWS = useSelector(getEnableWS);
@@ -212,7 +212,7 @@ export const ThumbGenerationContextProvider = ({
}
if (genThumbs) {
let genEntries;
- const pageFiles = getResentPageFiles ? getResentPageFiles() : undefined; //in KanBan PaginationContext is not injected
+ // pageFiles is undefined in KanBan, where PaginationContext is not injected
if (entries.length > 0) {
genEntries = entries;
} else if (pageFiles && pageFiles.length > 0) {
diff --git a/src/renderer/hooks/useSelectedEntriesRef.ts b/src/renderer/hooks/useSelectedEntriesRef.ts
new file mode 100644
index 000000000..10ba943ea
--- /dev/null
+++ b/src/renderer/hooks/useSelectedEntriesRef.ts
@@ -0,0 +1,34 @@
+/**
+ * TagSpaces - universal file and folder organizer
+ * Copyright (C) 2026-present TagSpaces GmbH
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License (version 3) as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
+
+import { useEffect, useRef } from 'react';
+import { TS } from '-/tagspaces.namespace';
+import { useSelectedEntriesContext } from '-/hooks/useSelectedEntriesContext';
+
+// Returns a ref whose .current is always the latest selectedEntries array.
+// Read .current inside event handlers (onClick, onContextMenu, drag callbacks)
+// to avoid subscribing the consumer to selection re-renders. Do not read
+// .current during render — it is intentionally not a render dependency.
+export function useSelectedEntriesRef() {
+ const { selectedEntries } = useSelectedEntriesContext();
+ const ref = useRef<TS.FileSystemEntry[]>(selectedEntries);
+ useEffect(() => {
+ ref.current = selectedEntries;
+ }, [selectedEntries]);
+ return ref;
+}
diff --git a/src/renderer/locales/en/core.json b/src/renderer/locales/en/core.json
index 2e13bf62c..07374ced8 100644
--- a/src/renderer/locales/en/core.json
+++ b/src/renderer/locales/en/core.json
@@ -402,6 +402,10 @@
"showHideEntriesDescription": "Show description for files and folders",
"showHideDetails": "Show folder details",
"showTags": "Show tags for files and folders",
+ "maxVisibleTags": "Max visible tags per file",
+ "maxVisibleTagsHelper": "Files with more tags will show a +N chip; click to see the rest. 0 disables the cap.",
+ "moreTags": "{{count}} more tags",
+ "noLimit": "No limit",
"sort": "Sort",
"thirdPartyLibs": "Third Party Libraries",
"indexLocation": "Refresh Location Index",
diff --git a/src/renderer/perspectives/common/CellView.tsx b/src/renderer/perspectives/common/CellView.tsx
index 5b16af44d..56300f36f 100644
--- a/src/renderer/perspectives/common/CellView.tsx
+++ b/src/renderer/perspectives/common/CellView.tsx
@@ -30,6 +30,7 @@ import { useNotificationContext } from '-/hooks/useNotificationContext';
import { useOpenedEntryContext } from '-/hooks/useOpenedEntryContext';
import { usePerspectiveSettingsContext } from '-/hooks/usePerspectiveSettingsContext';
import { useSelectedEntriesContext } from '-/hooks/useSelectedEntriesContext';
+import { useSelectedEntriesRef } from '-/hooks/useSelectedEntriesRef';
import {
fileOperationsEnabled,
folderOperationsEnabled,
@@ -50,9 +51,16 @@ import { useSelector } from 'react-redux';
interface Props {
fsEntry: TS.FileSystemEntry;
index: number;
+ // Per-cell selection state computed once by the parent (GridPagination /
+ // List MainContainer). Passing booleans here — instead of the full
+ // selectedEntries array — lets the surrounding `memo()` actually skip
+ // re-renders when the global selection changes for some other entry.
+ selected: boolean;
+ selectionMode: boolean;
cellContent: (
fsEntry: TS.FileSystemEntry,
- selectedEntries: Array<TS.FileSystemEntry>,
+ selected: boolean,
+ selectionMode: boolean,
index: number,
handleGridContextMenu: (
event: React.MouseEvent<HTMLDivElement>,
@@ -68,7 +76,16 @@ interface Props {
}
function CellView(props: Props) {
- const { fsEntry, index, cellContent, isLast, orderTop, orderBottom } = props;
+ const {
+ fsEntry,
+ index,
+ cellContent,
+ selected,
+ selectionMode,
+ isLast,
+ orderTop,
+ orderBottom,
+ } = props;
const { showDirectories, singleClickAction } =
usePerspectiveSettingsContext();
const theme = useTheme();
@@ -79,12 +96,12 @@ function CellView(props: Props) {
const { openDirectory } = useDirectoryContentContext();
const { openFileNatively } = useIOActionsContext();
const { currentLocationId, currentLocation } = useCurrentLocationContext();
- const {
- selectedEntries,
- setSelectedEntries,
- addToSelection,
- lastSelectedEntry,
- } = useSelectedEntriesContext();
+ // Read latest selectedEntries on demand from a ref so this memoised
+ // component does not re-render on every selection change. Click handlers
+ // (shift-range, ctrl-toggle, drag selection) read .current at gesture time.
+ const { setSelectedEntries, addToSelection, lastSelectedEntry } =
+ useSelectedEntriesContext();
+ const selectedEntriesRef = useSelectedEntriesRef();
const { sortedDirContent, nativeDragModeEnabled } = useSortedDirContext();
const { showNotification } = useNotificationContext();
const selectedTabName = useSelector(getEntryContainerTab);
@@ -96,6 +113,7 @@ function CellView(props: Props) {
const handleGridContextMenu = (event, fsEntry: TS.FileSystemEntry) => {
event.preventDefault();
event.stopPropagation();
+ const selectedEntries = selectedEntriesRef.current ?? [];
const isEntryExist = selectedEntries.some(
(entry) => entry.uuid === fsEntry.uuid,
);
@@ -139,6 +157,7 @@ function CellView(props: Props) {
const handleGridCellClick = (event, fsEntry: TS.FileSystemEntry) => {
const selectHelperKey = AppConfig.isMacLike ? event.metaKey : event.ctrlKey;
+ const selectedEntries = selectedEntriesRef.current ?? [];
if (event.shiftKey) {
let lastSelectedIndex = -1;
if (lastSelectedEntry) {
@@ -223,9 +242,9 @@ function CellView(props: Props) {
}
if (item) {
const { entry } = item;
+ const selectedEntries = selectedEntriesRef.current ?? [];
let arrEntries;
if (
- selectedEntries &&
selectedEntries.length > 0 &&
selectedEntries.some((e) => e.path === entry.path)
) {
@@ -275,7 +294,8 @@ function CellView(props: Props) {
{cellContent(
fsEntry,
- selectedEntries,
+ selected,
+ selectionMode,
index,
handleGridContextMenu,
handleGridCellClick,
@@ -303,7 +323,8 @@ function CellView(props: Props) {
>
{cellContent(
fsEntry,
- selectedEntries,
+ selected,
+ selectionMode,
index,
handleGridContextMenu,
handleGridCellClick,
diff --git a/src/renderer/perspectives/grid/components/GridCell.tsx b/src/renderer/perspectives/grid/components/GridCell.tsx
index ef052600a..1dcb5ae7e 100644
--- a/src/renderer/perspectives/grid/components/GridCell.tsx
+++ b/src/renderer/perspectives/grid/components/GridCell.tsx
@@ -27,6 +27,7 @@ import EntryIcon from '-/components/EntryIcon';
import FileExtBadge from '-/components/FileExtBadge';
import TagContainer from '-/components/TagContainer';
import TagContainerDnd from '-/components/TagContainerDnd';
+import TagsOverflowChip from '-/components/TagsOverflowChip';
import TagsPreview from '-/components/TagsPreview';
import Tooltip from '-/components/Tooltip';
import TsIconButton from '-/components/TsIconButton';
@@ -35,6 +36,7 @@ import { useEditedEntryMetaContext } from '-/hooks/useEditedEntryMetaContext';
import { usePerspectiveSettingsContext } from '-/hooks/usePerspectiveSettingsContext';
import { useSelectedEntriesContext } from '-/hooks/useSelectedEntriesContext';
import { useTaggingActionsContext } from '-/hooks/useTaggingActionsContext';
+import { useCellVisibility } from '-/perspectives/grid/hooks/CellVisibilityContext';
import {
getSupportedFileTypes,
getTagDelimiter,
@@ -68,7 +70,13 @@ import {
extractTitle,
getThumbFileLocationForFile,
} from '@tagspaces/tagspaces-common/paths';
-import { useCallback, useEffect, useMemo, useState } from 'react';
+import React, {
+ useCallback,
+ useEffect,
+ useMemo,
+ useRef,
+ useState,
+} from 'react';
import { useTranslation } from 'react-i18next';
import { useSelector } from 'react-redux';
import { defaultSettings } from '../index';
@@ -123,10 +131,18 @@ function GridCell(props: Props) {
const { t } = useTranslation();
const theme = useTheme();
- const { entrySize, showEntriesDescription, showTags, thumbnailMode } =
- usePerspectiveSettingsContext();
+ const {
+ entrySize,
+ showEntriesDescription,
+ showTags,
+ thumbnailMode,
+ maxVisibleTags,
+ } = usePerspectiveSettingsContext();
const { metaActions } = useEditedEntryMetaContext();
- const { selectedEntries, selectEntry } = useSelectedEntriesContext();
+ // Intentionally do not subscribe to selectedEntries here. The cell receives
+ // its own `selected` boolean from the parent; selectEntry is only used in
+ // event handlers, where reading the latest selection from a ref is fine.
+ const { selectEntry } = useSelectedEntriesContext();
const { addTag, editTagForEntry } = useTaggingActionsContext();
const { findLocation } = useCurrentLocationContext();
const supportedFileTypes = useSelector(getSupportedFileTypes);
@@ -145,6 +161,12 @@ function GridCell(props: Props) {
// Thumbnail state and helpers
const [thumbSrc, setThumbSrc] = useState<string | undefined>(undefined);
+ // Visibility-driven loading: defer setThumbPath until the cell scrolls
+ // close to the viewport. The visibility context owns one shared
+ // IntersectionObserver for the whole page.
+ const cellRootRef = useRef<HTMLElement | null>(null);
+ const [isVisible, setIsVisible] = useState(false);
+ const visibility = useCellVisibility();
const getThumbUrl = useCallback(async (): Promise<string | undefined> => {
if (!gridCellLocation) return undefined;
@@ -189,8 +211,24 @@ function GridCell(props: Props) {
}, [gridCellLocation, fsEntry.path, fsEntry.meta, getThumbUrl]);
useEffect(() => {
- setThumbPath();
- }, [setThumbPath]);
+ if (isVisible) setThumbPath();
+ }, [isVisible, setThumbPath]);
+
+ // Subscribe the cell root to the shared IntersectionObserver. We only flip
+ // isVisible on first transition to true — once a cell has loaded its thumb
+ // we don't need to react further (the WeakSet inside the provider keeps
+ // visibility state for any future scroll-back re-render). Cells that go
+ // off-screen and come back will already have thumbSrc cached.
+ useEffect(() => {
+ const el = cellRootRef.current;
+ if (!el) return;
+ const cb = (visible: boolean) => {
+ if (visible) setIsVisible(true);
+ };
+ const initial = visibility.observe(el, cb);
+ if (initial) setIsVisible(true);
+ return () => visibility.unobserve(el, cb);
+ }, [visibility]);
useEffect(() => {
if (!firstRender && metaActions && metaActions.length > 0) {
@@ -257,14 +295,24 @@ function GridCell(props: Props) {
return desc;
}, [showEntriesDescription, fsEntry.meta?.description]);
+ // Prefer the value pre-parsed at load time by DirectoryContentContextProvider.
+ // Fallback to a fresh parse if the entry came in through a path that did not
+ // enrich it (defensive — should not normally happen for cells in the grid).
const fileNameTags = useMemo(() => {
if (!fsEntry.isFile) return [];
+ if (fsEntry.parsedNameTags !== undefined) return fsEntry.parsedNameTags;
return extractTagsAsObjects(
fsEntry.name,
tagDelimiter,
gridCellLocation?.getDirSeparator(),
);
- }, [fsEntry.isFile, fsEntry.name, tagDelimiter, gridCellLocation]);
+ }, [
+ fsEntry.isFile,
+ fsEntry.name,
+ fsEntry.parsedNameTags,
+ tagDelimiter,
+ gridCellLocation,
+ ]);
const fileSystemEntryTags: TS.Tag[] = fsEntry.meta?.tags ?? [];
@@ -276,10 +324,25 @@ function GridCell(props: Props) {
];
}, [fileSystemEntryTags, fileNameTags]);
+ // In multi-select (selectionMode) the drag operation is on the cell, not on
+ // the tag (file move, not tag reorder). Skip the per-tag DnD wiring in that
+ // mode — same logic as on read-only locations. Drops 2× useDrag/useDrop per
+ // tag × N tags × M cells of overhead during multi-select.
+ const useStaticTags = gridCellLocation.isReadOnly || selectionMode;
+ // Cap the number of inline tag chips. Files with more get a "+N" chip that
+ // opens the rest in a popover. 0 disables the cap.
+ const cap =
+ typeof maxVisibleTags === 'number' && maxVisibleTags > 0
+ ? maxVisibleTags
+ : Infinity;
+ const visibleTags =
+ entryTags.length > cap ? entryTags.slice(0, cap) : entryTags;
+ const overflowTags =
+ entryTags.length > cap ? entryTags.slice(cap) : undefined;
const renderTags = useCallback(() => {
let sideCarLength = 0;
- return entryTags.map((tag: TS.Tag, index) => {
- const tagContainer = gridCellLocation.isReadOnly ? (
+ return visibleTags.map((tag: TS.Tag, index) => {
+ const tagContainer = useStaticTags ? (
<TagContainer
tag={tag}
key={entryPath + tag.title}
@@ -294,7 +357,6 @@ function GridCell(props: Props) {
entry={fsEntry}
addTag={handleAddTag}
handleTagMenu={handleTagMenu}
- selectedEntries={selectedEntries}
editTagForEntry={handleEditTag}
reorderTags={reorderTags}
/>
@@ -305,13 +367,12 @@ function GridCell(props: Props) {
return tagContainer;
});
}, [
- entryTags,
- gridCellLocation,
+ visibleTags,
+ useStaticTags,
entryPath,
fsEntry,
handleTagMenu,
handleAddTag,
- selectedEntries,
handleEditTag,
reorderTags,
]);
@@ -398,6 +459,9 @@ function GridCell(props: Props) {
return (
<Card
+ ref={(node: HTMLElement | null) => {
+ cellRootRef.current = node;
+ }}
data-entry-id={fsEntry.uuid}
data-tid={`fsEntryName_${dataTidFormat(fsEntry.name)}`}
data-selected={selected}
@@ -429,7 +493,16 @@ function GridCell(props: Props) {
>
<Box sx={{ position: 'absolute' }}>
{showTags && entryTags.length > 0 ? (
- renderTags()
+ <>
+ {renderTags()}
+ {overflowTags && (
+ <TagsOverflowChip
+ remaining={overflowTags}
+ entry={fsEntry}
+ handleTagMenu={handleTagMenu}
+ />
+ )}
+ </>
) : (
<TagsPreview tags={entryTags} />
)}
@@ -526,4 +599,19 @@ function GridCell(props: Props) {
);
}
-export default GridCell;
+// Custom comparator: re-render only when something the cell actually displays
+// changes. This makes single-file selection cheap — only the previously- and
+// newly-selected cells repaint.
+export default React.memo(GridCell, (prev, next) => {
+ return (
+ prev.selected === next.selected &&
+ prev.selectionMode === next.selectionMode &&
+ prev.fsEntry === next.fsEntry &&
+ prev.fsEntry.meta === next.fsEntry.meta &&
+ prev.isLast === next.isLast &&
+ prev.handleTagMenu === next.handleTagMenu &&
+ prev.handleGridContextMenu === next.handleGridContextMenu &&
+ prev.handleGridCellClick === next.handleGridCellClick &&
+ prev.handleGridCellDblClick === next.handleGridCellDblClick
+ );
+});
diff --git a/src/renderer/perspectives/grid/components/GridPagination.tsx b/src/renderer/perspectives/grid/components/GridPagination.tsx
index 0966a135e..6eaf58d2c 100644
--- a/src/renderer/perspectives/grid/components/GridPagination.tsx
+++ b/src/renderer/perspectives/grid/components/GridPagination.tsx
@@ -33,6 +33,7 @@ import { usePaginationContext } from '-/hooks/usePaginationContext';
import { usePerspectiveSettingsContext } from '-/hooks/usePerspectiveSettingsContext';
import { useSelectedEntriesContext } from '-/hooks/useSelectedEntriesContext';
import CellView from '-/perspectives/common/CellView';
+import { CellVisibilityProvider } from '-/perspectives/grid/hooks/CellVisibilityContext';
import { useSortedDirContext } from '-/perspectives/grid/hooks/useSortedDirContext';
import { Pro } from '-/pro';
import { dataTidFormat } from '-/services/test';
@@ -71,13 +72,14 @@ interface Props {
desktopMode: boolean;
getCellContent: (
fsEntry: TS.FileSystemEntry,
- selectedEntries: Array<TS.FileSystemEntry>,
+ selected: boolean,
+ selectionMode: boolean,
index: number,
handleGridContextMenu,
handleGridCellClick,
handleGridCellDblClick,
isLast?: boolean,
- ) => void;
+ ) => any;
currentDirectoryPath: string;
onClick: (event: React.MouseEvent<HTMLDivElement>) => void;
setSelectedEntries: (selectedEntries: Array<TS.FileSystemEntry>) => void;
@@ -101,7 +103,7 @@ function GridPagination(props: Props) {
const { directoryMeta, getAllPropertiesPromise } =
useDirectoryContentContext();
const { sortedDirContent } = useSortedDirContext();
- const { page, getResentPageFiles, setCurrentPage } = usePaginationContext();
+ const { page, pageFiles, setCurrentPage } = usePaginationContext();
const { openEntry } = useOpenedEntryContext();
const thumbDialogContext = Pro?.contextProviders?.ThumbDialogContext
? useContext<TS.ThumbDialogContextData>(
@@ -111,7 +113,18 @@ function GridPagination(props: Props) {
const currentLocation = findLocation();
const theme = useTheme();
- const pageFiles = useMemo(() => getResentPageFiles(), [getResentPageFiles]);
+
+ // O(1) per-cell selection lookup. CellViews are memoised on the `selected`
+ // boolean alone, so swapping a Set in here means a single click only
+ // re-renders the previously-selected and the newly-selected cells.
+ const selectedUuidSet = useMemo(() => {
+ const s = new Set<string>();
+ if (selectedEntries) {
+ for (const e of selectedEntries) s.add(e.uuid);
+ }
+ return s;
+ }, [selectedEntries]);
+ const selectionMode = (selectedEntries?.length ?? 0) > 1;
// Memoize derived values for performance
const showPagination = useMemo(
@@ -436,29 +449,33 @@ function GridPagination(props: Props) {
</Grid>
<SelectionDragLayer />
<SelectionArea onSelect={handleSelect}>
- <GridCellsContainer>
- {pageFiles.length < 1 &&
- renderEmptyState(t('core:noFileFolderFound'))}
- {fileCount < 1 &&
- dirCount >= 1 &&
- !showDirectories &&
- renderEmptyState(t('core:noFileButFoldersFound'))}
- {pageFiles.map((entry, index) => (
- <CellView
- key={entry.uuid}
- fsEntry={entry}
- index={index}
- cellContent={getCellContent}
- isLast={index === pageFiles.length - 1}
- />
- ))}
- {pageFiles.length > 0 && (
- <>
- <Box sx={{ flexGrow: 1 }} />
- <Box sx={{ flexGrow: 1 }} />
- </>
- )}
- </GridCellsContainer>
+ <CellVisibilityProvider scrollRoot={containerEl}>
+ <GridCellsContainer>
+ {pageFiles.length < 1 &&
+ renderEmptyState(t('core:noFileFolderFound'))}
+ {fileCount < 1 &&
+ dirCount >= 1 &&
+ !showDirectories &&
+ renderEmptyState(t('core:noFileButFoldersFound'))}
+ {pageFiles.map((entry, index) => (
+ <CellView
+ key={entry.uuid}
+ fsEntry={entry}
+ index={index}
+ selected={selectedUuidSet.has(entry.uuid)}
+ selectionMode={selectionMode}
+ cellContent={getCellContent}
+ isLast={index === pageFiles.length - 1}
+ />
+ ))}
+ {pageFiles.length > 0 && (
+ <>
+ <Box sx={{ flexGrow: 1 }} />
+ <Box sx={{ flexGrow: 1 }} />
+ </>
+ )}
+ </GridCellsContainer>
+ </CellVisibilityProvider>
{showPagination && (
<TooltipTS title={folderSummary}>
<Pagination
diff --git a/src/renderer/perspectives/grid/components/GridSettingsDialog.tsx b/src/renderer/perspectives/grid/components/GridSettingsDialog.tsx
index 5defae033..c00ca9bff 100644
--- a/src/renderer/perspectives/grid/components/GridSettingsDialog.tsx
+++ b/src/renderer/perspectives/grid/components/GridSettingsDialog.tsx
@@ -70,6 +70,7 @@ function GridSettingsDialog(props: Props) {
thumbnailMode,
singleClickAction,
gridPageLimit,
+ maxVisibleTags,
haveLocalSetting,
resetLocalSetting,
setSettings,
@@ -359,6 +360,25 @@ function GridSettingsDialog(props: Props) {
</TsSelect>
{/* <FormHelperText>{t('core:pageLimitHelp')}</FormHelperText> */}
</FormControl>
+ <FormControl fullWidth={true} sx={{ marginTop: 1 }}>
+ <TsSelect
+ label={t('core:maxVisibleTags')}
+ name="maxVisibleTags"
+ defaultValue={maxVisibleTags ?? 4}
+ onChange={(event: React.ChangeEvent<HTMLInputElement>) => {
+ const parsed = parseInt(event.target.value, 10);
+ setSettings({
+ maxVisibleTags: Number.isNaN(parsed) ? 0 : parsed,
+ });
+ }}
+ >
+ <MenuItem value={0}>{t('core:noLimit')}</MenuItem>
+ <MenuItem value={2}>2</MenuItem>
+ <MenuItem value={4}>4</MenuItem>
+ <MenuItem value={6}>6</MenuItem>
+ <MenuItem value={10}>10</MenuItem>
+ </TsSelect>
+ </FormControl>
</DialogContent>
<TsDialogActions sx={{ justifyContent: 'space-between' }}>
{smallScreen ? (
diff --git a/src/renderer/perspectives/grid/components/MainContainer.tsx b/src/renderer/perspectives/grid/components/MainContainer.tsx
index 28556e673..9b10f0a92 100644
--- a/src/renderer/perspectives/grid/components/MainContainer.tsx
+++ b/src/renderer/perspectives/grid/components/MainContainer.tsx
@@ -278,7 +278,8 @@ function GridPerspective(props: Props) {
const getCellContent = useCallback(
(
fsEntry: TS.FileSystemEntry,
- selectedEntries: Array<TS.FileSystemEntry>,
+ selected: boolean,
+ selectionMode: boolean,
index: number,
handleGridContextMenu: (
event: React.MouseEvent<HTMLDivElement>,
@@ -288,15 +289,6 @@ function GridPerspective(props: Props) {
handleGridCellDblClick,
isLast?: boolean,
) => {
- let selected = false;
- if (
- selectedEntries &&
- selectedEntries.some((entry) => entry.path === fsEntry.path)
- ) {
- selected = true;
- }
-
- const selectionMode = selectedEntries.length > 1;
return (
<FileSourceDnd entry={fsEntry}>
<TagDropContainer entry={fsEntry}>
diff --git a/src/renderer/perspectives/grid/hooks/CellVisibilityContext.tsx b/src/renderer/perspectives/grid/hooks/CellVisibilityContext.tsx
new file mode 100644
index 000000000..0efb126dc
--- /dev/null
+++ b/src/renderer/perspectives/grid/hooks/CellVisibilityContext.tsx
@@ -0,0 +1,138 @@
+/**
+ * TagSpaces - universal file and folder organizer
+ * Copyright (C) 2026-present TagSpaces GmbH
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License (version 3) as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
+
+import React, {
+ createContext,
+ useCallback,
+ useContext,
+ useEffect,
+ useMemo,
+ useRef,
+} from 'react';
+
+type Visibility = boolean;
+type VisibilityCallback = (visible: Visibility) => void;
+
+type CellVisibilityContextData = {
+ // Subscribe an element to visibility updates. Returns the current visibility
+ // value so callers can short-circuit before the first observer entry fires.
+ // Pass `undefined` for the element to unsubscribe — use the same callback
+ // identity for both calls. Cells should call this from a useEffect that
+ // depends on the cell root ref.
+ observe: (el: Element | null, cb: VisibilityCallback) => Visibility;
+ unobserve: (el: Element | null, cb: VisibilityCallback) => void;
+};
+
+const noopCtx: CellVisibilityContextData = {
+ observe: () => true,
+ unobserve: () => {},
+};
+
+const CellVisibilityContext = createContext<CellVisibilityContextData>(noopCtx);
+
+type ProviderProps = {
+ scrollRoot: React.RefObject<HTMLElement>;
+ children: React.ReactNode;
+};
+
+// Single shared IntersectionObserver for all cells in a perspective. Cheaper
+// than one observer per cell when the page has 100+ entries. Uses a generous
+// rootMargin so thumbnails start resolving slightly before they scroll into
+// view, which masks the latency of disk / decrypt / data URL conversion.
+export function CellVisibilityProvider({
+ scrollRoot,
+ children,
+}: ProviderProps) {
+ const observerRef = useRef<IntersectionObserver | null>(null);
+ const callbacksRef = useRef<Map<Element, Set<VisibilityCallback>>>(new Map());
+ const visibleRef = useRef<WeakSet<Element>>(new WeakSet());
+
+ useEffect(() => {
+ if (typeof IntersectionObserver === 'undefined') {
+ // Fallback for environments without IntersectionObserver: pretend every
+ // cell is visible so the eager thumbnail path still works.
+ return;
+ }
+ const observer = new IntersectionObserver(
+ (entries) => {
+ for (const entry of entries) {
+ const visible = entry.isIntersecting;
+ if (visible) visibleRef.current.add(entry.target);
+ else visibleRef.current.delete(entry.target);
+ const set = callbacksRef.current.get(entry.target);
+ if (set) {
+ for (const cb of set) cb(visible);
+ }
+ }
+ },
+ {
+ root: scrollRoot.current ?? null,
+ rootMargin: '200px',
+ threshold: 0,
+ },
+ );
+ observerRef.current = observer;
+ // Re-observe any elements that registered before the observer was ready.
+ for (const el of callbacksRef.current.keys()) observer.observe(el);
+ return () => {
+ observer.disconnect();
+ observerRef.current = null;
+ };
+ }, [scrollRoot]);
+
+ const observe = useCallback(
+ (el: Element | null, cb: VisibilityCallback): Visibility => {
+ if (!el) return true;
+ let set = callbacksRef.current.get(el);
+ if (!set) {
+ set = new Set();
+ callbacksRef.current.set(el, set);
+ observerRef.current?.observe(el);
+ }
+ set.add(cb);
+ return visibleRef.current.has(el);
+ },
+ [],
+ );
+
+ const unobserve = useCallback(
+ (el: Element | null, cb: VisibilityCallback) => {
+ if (!el) return;
+ const set = callbacksRef.current.get(el);
+ if (!set) return;
+ set.delete(cb);
+ if (set.size === 0) {
+ callbacksRef.current.delete(el);
+ observerRef.current?.unobserve(el);
+ }
+ },
+ [],
+ );
+
+ const value = useMemo(() => ({ observe, unobserve }), [observe, unobserve]);
+
+ return (
+ <CellVisibilityContext.Provider value={value}>
+ {children}
+ </CellVisibilityContext.Provider>
+ );
+}
+
+export function useCellVisibility() {
+ return useContext(CellVisibilityContext);
+}
diff --git a/src/renderer/perspectives/grid/hooks/SortedDirContextProvider.tsx b/src/renderer/perspectives/grid/hooks/SortedDirContextProvider.tsx
index a098e326b..765c9b056 100644
--- a/src/renderer/perspectives/grid/hooks/SortedDirContextProvider.tsx
+++ b/src/renderer/perspectives/grid/hooks/SortedDirContextProvider.tsx
@@ -100,9 +100,9 @@ export const SortedDirContextProvider = ({
const sortedDirContent = useMemo(() => {
if (searchFilter) {
+ const needle = searchFilter.toLowerCase();
return sortByCriteria(currentDirectoryEntries, sortBy, orderBy).filter(
- (entry) =>
- entry.name.toLowerCase().includes(searchFilter.toLowerCase()),
+ (entry) => entry.name.toLowerCase().includes(needle),
);
}
if (sortBy === 'byRelevance') {
@@ -114,9 +114,7 @@ export const SortedDirContextProvider = ({
}
}
// not in search mode
- return sortByCriteria(currentDirectoryEntries, sortBy, orderBy).map(
- (o) => o,
- );
+ return sortByCriteria(currentDirectoryEntries, sortBy, orderBy);
}, [currentDirectoryEntries, searchFilter, sortBy, orderBy]);
const context = useMemo(() => {
diff --git a/src/renderer/perspectives/grid/index.tsx b/src/renderer/perspectives/grid/index.tsx
index 3d3e3e6bf..3c895c92d 100644
--- a/src/renderer/perspectives/grid/index.tsx
+++ b/src/renderer/perspectives/grid/index.tsx
@@ -27,5 +27,10 @@ export const defaultSettings = {
showEntriesDescription: true,
showTags: true,
gridPageLimit: 100,
+ // Cap the number of tag chips rendered per cell. Files with more tags show
+ // the first N + a "+M more" chip that opens the rest in a popover. Reduces
+ // worst-case per-cell render cost on heavily-tagged files. 0 disables the
+ // cap (render all tags inline).
+ maxVisibleTags: 4,
maxDescriptionPreviewLength: 100,
};
diff --git a/src/renderer/perspectives/list/components/MainContainer.tsx b/src/renderer/perspectives/list/components/MainContainer.tsx
index 7d75b9882..20bf68dd8 100644
--- a/src/renderer/perspectives/list/components/MainContainer.tsx
+++ b/src/renderer/perspectives/list/components/MainContainer.tsx
@@ -280,7 +280,8 @@ function ListPerspective(props: Props) {
const getCellContent = (
fsEntry: TS.FileSystemEntry,
- selectedEntries: Array<TS.FileSystemEntry>,
+ selected: boolean,
+ selectionMode: boolean,
index: number,
handleGridContextMenu: (
event: React.MouseEvent<HTMLDivElement>,
@@ -290,15 +291,6 @@ function ListPerspective(props: Props) {
handleGridCellDblClick,
isLast?: boolean,
) => {
- let selected = false;
- if (
- selectedEntries &&
- selectedEntries.some((entry) => entry.path === fsEntry.path)
- ) {
- selected = true;
- }
-
- const selectionMode = selectedEntries.length > 1;
return (
<FileSourceDnd entry={fsEntry}>
<TagDropContainer entry={fsEntry}>
diff --git a/src/renderer/perspectives/list/components/RowCell.tsx b/src/renderer/perspectives/list/components/RowCell.tsx
index 2168d4ad8..066ec52eb 100644
--- a/src/renderer/perspectives/list/components/RowCell.tsx
+++ b/src/renderer/perspectives/list/components/RowCell.tsx
@@ -26,6 +26,7 @@ import {
import FileExtBadge from '-/components/FileExtBadge';
import TagContainer from '-/components/TagContainer';
import TagContainerDnd from '-/components/TagContainerDnd';
+import TagsOverflowChip from '-/components/TagsOverflowChip';
import TagsPreview from '-/components/TagsPreview';
import Tooltip from '-/components/Tooltip';
import TsIconButton from '-/components/TsIconButton';
@@ -111,8 +112,11 @@ function RowCell(props: Props) {
const { t } = useTranslation();
const theme = useTheme();
- const { selectedEntries, selectEntry } = useSelectedEntriesContext();
- const { entrySize, showTags, thumbnailMode } =
+ // Intentionally do not subscribe to selectedEntries here. The cell receives
+ // its own `selected` boolean from the parent; selectEntry is only used in
+ // event handlers, where reading the latest selection from a ref is fine.
+ const { selectEntry } = useSelectedEntriesContext();
+ const { entrySize, showTags, thumbnailMode, maxVisibleTags } =
usePerspectiveSettingsContext();
const { addTag, editTagForEntry } = useTaggingActionsContext();
const { currentLocation } = useCurrentLocationContext();
@@ -155,17 +159,22 @@ function RowCell(props: Props) {
[fsEntry],
);
- const fileNameTags = useMemo(
- () =>
- fsEntry.isFile
- ? extractTagsAsObjects(
- fsEntry.name,
- tagDelimiter,
- currentLocation?.getDirSeparator(),
- )
- : [],
- [fsEntry.isFile, fsEntry.name, tagDelimiter, currentLocation],
- );
+ // Prefer the value pre-parsed at load time by DirectoryContentContextProvider.
+ const fileNameTags = useMemo(() => {
+ if (!fsEntry.isFile) return [];
+ if (fsEntry.parsedNameTags !== undefined) return fsEntry.parsedNameTags;
+ return extractTagsAsObjects(
+ fsEntry.name,
+ tagDelimiter,
+ currentLocation?.getDirSeparator(),
+ );
+ }, [
+ fsEntry.isFile,
+ fsEntry.name,
+ fsEntry.parsedNameTags,
+ tagDelimiter,
+ currentLocation,
+ ]);
const fileSystemEntryTags: TS.Tag[] = fsEntry.meta?.tags ?? [];
const sideCarTagsTitles = useMemo(
@@ -191,10 +200,22 @@ function RowCell(props: Props) {
const entryPath = fsEntry.path;
+ // In multi-select (selectionMode) the drag operation is on the cell, not on
+ // the tag. Skip the per-tag DnD wiring — same logic as read-only locations.
+ const useStaticTags = currentLocation?.isReadOnly || selectionMode;
+ // Cap inline tag chips; overflow goes into the TagsOverflowChip popover.
+ const cap =
+ typeof maxVisibleTags === 'number' && maxVisibleTags > 0
+ ? maxVisibleTags
+ : Infinity;
+ const visibleTags =
+ entryTags.length > cap ? entryTags.slice(0, cap) : entryTags;
+ const overflowTags =
+ entryTags.length > cap ? entryTags.slice(cap) : undefined;
const renderTags = useMemo(() => {
let sideCarLength = 0;
- return entryTags.map((tag: TS.Tag, index) => {
- const tagContainer = currentLocation?.isReadOnly ? (
+ return visibleTags.map((tag: TS.Tag, index) => {
+ const tagContainer = useStaticTags ? (
<TagContainer
tag={tag}
key={entryPath + tag.title}
@@ -209,7 +230,6 @@ function RowCell(props: Props) {
entry={fsEntry}
addTag={handleAddTag}
handleTagMenu={handleTagMenu}
- selectedEntries={selectedEntries}
editTagForEntry={editTagForEntry}
reorderTags={reorderTags}
/>
@@ -220,13 +240,12 @@ function RowCell(props: Props) {
return tagContainer;
});
}, [
- entryTags,
- currentLocation?.isReadOnly,
+ visibleTags,
+ useStaticTags,
entryPath,
fsEntry,
handleTagMenu,
addTag,
- selectedEntries,
editTagForEntry,
reorderTags,
]);
@@ -381,7 +400,20 @@ function RowCell(props: Props) {
}
>
{entryTitle}
- {showTags && entryTags.length > 0 ? renderTags : tagPlaceholder}
+ {showTags && entryTags.length > 0 ? (
+ <>
+ {renderTags}
+ {overflowTags && (
+ <TagsOverflowChip
+ remaining={overflowTags}
+ entry={fsEntry}
+ handleTagMenu={handleTagMenu}
+ />
+ )}
+ </>
+ ) : (
+ tagPlaceholder
+ )}
</Typography>
</Grid>
) : (
@@ -412,7 +444,20 @@ function RowCell(props: Props) {
</Tooltip>
<span>{description}</span>
</Typography>
- {showTags && entryTags.length > 0 ? renderTags : tagPlaceholder}
+ {showTags && entryTags.length > 0 ? (
+ <>
+ {renderTags}
+ {overflowTags && (
+ <TagsOverflowChip
+ remaining={overflowTags}
+ entry={fsEntry}
+ handleTagMenu={handleTagMenu}
+ />
+ )}
+ </>
+ ) : (
+ tagPlaceholder
+ )}
</Grid>
)}
{fsEntry.meta?.thumbPath && (
@@ -467,4 +512,20 @@ function RowCell(props: Props) {
);
}
-export default RowCell;
+// Custom comparator: re-render only when something the row actually displays
+// changes. Mirrors GridCell's memoization so single-file selection doesn't
+// repaint the entire visible page.
+export default React.memo(RowCell, (prev, next) => {
+ return (
+ prev.selected === next.selected &&
+ prev.selectionMode === next.selectionMode &&
+ prev.fsEntry === next.fsEntry &&
+ prev.fsEntry.meta === next.fsEntry.meta &&
+ prev.isLast === next.isLast &&
+ prev.showEntriesDescription === next.showEntriesDescription &&
+ prev.handleTagMenu === next.handleTagMenu &&
+ prev.handleGridContextMenu === next.handleGridContextMenu &&
+ prev.handleGridCellClick === next.handleGridCellClick &&
+ prev.handleGridCellDblClick === next.handleGridCellDblClick
+ );
+});
diff --git a/src/renderer/perspectives/list/index.tsx b/src/renderer/perspectives/list/index.tsx
index e12a332f2..0b921d5a0 100644
--- a/src/renderer/perspectives/list/index.tsx
+++ b/src/renderer/perspectives/list/index.tsx
@@ -28,5 +28,6 @@ export const defaultSettings = {
showEntriesDescription: true,
showTags: true,
gridPageLimit: 100,
+ maxVisibleTags: 4,
maxDescriptionPreviewLength: 100,
};
diff --git a/src/renderer/tagspaces.namespace.d.ts b/src/renderer/tagspaces.namespace.d.ts
index 390c567d3..cd27d05f3 100644
--- a/src/renderer/tagspaces.namespace.d.ts
+++ b/src/renderer/tagspaces.namespace.d.ts
@@ -207,6 +207,11 @@ export namespace TS {
url?: string;
meta?: FileSystemEntryMeta;
links?: Link[];
+ // Filename-encoded tags parsed once at load time. Cells read this instead
+ // of running extractTagsAsObjects() on every render. Optional because
+ // entries that flow through other paths (e.g. legacy callers, search
+ // results pre-enrichment) may not have it set yet.
+ parsedNameTags?: TS.Tag[];
}
interface SearchIndex extends FileSystemEntry {
@@ -451,6 +456,8 @@ export namespace TS {
entrySize?: EntrySizes;
thumbnailMode?: ThumbnailMode;
gridPageLimit?: number;
+ // Cap of visible tag chips per cell in Grid/List perspectives. 0 disables.
+ maxVisibleTags?: number;
galleryTypeGroup?: string[];
// isLocal?: boolean;
}