fix
This commit is contained in:
@@ -140,6 +140,23 @@ const DesktopWorkspace = ({
|
||||
|
||||
const allowLayoutPersistence = Boolean(tenantId && viewId && viewId.startsWith('folder:'));
|
||||
|
||||
const itemsTraceRef = useRef(items);
|
||||
useEffect(() => {
|
||||
if (itemsTraceRef.current !== items) {
|
||||
const prev = itemsTraceRef.current || [];
|
||||
const next = items || [];
|
||||
const stack = new Error('[trace] items updated').stack?.split('\n').slice(1, 8);
|
||||
console.log('[desk][trace] items value changed', {
|
||||
prevCount: prev.length,
|
||||
nextCount: next.length,
|
||||
sameRef: prev === next,
|
||||
fromSearch: Boolean(searchResults),
|
||||
});
|
||||
console.log('[desk][trace] items stack', stack);
|
||||
itemsTraceRef.current = items;
|
||||
}
|
||||
}, [items, searchResults]);
|
||||
|
||||
const containerRef = useRef(null);
|
||||
const itemRefs = useRef(new Map());
|
||||
const dragTransformsRef = useRef(new Map());
|
||||
@@ -149,7 +166,6 @@ const DesktopWorkspace = ({
|
||||
const [previewSnapshots, setPreviewSnapshots] = useState(() => new Map());
|
||||
const [docSizeVersion, setDocSizeVersion] = useState(0);
|
||||
const docSizeMapRef = useRef(new Map());
|
||||
const documentLookupRef = useRef(new Map());
|
||||
const ensureDocumentSize = useCallback((doc) => {
|
||||
if (!doc?.id) {
|
||||
return null;
|
||||
@@ -168,10 +184,6 @@ const DesktopWorkspace = ({
|
||||
return map;
|
||||
}, [items]);
|
||||
|
||||
useEffect(() => {
|
||||
documentLookupRef.current = documentLookup;
|
||||
}, [documentLookup]);
|
||||
|
||||
const engineRef = useRef(null);
|
||||
if (!engineRef.current) {
|
||||
engineRef.current = new WorkspaceEngine({
|
||||
@@ -187,12 +199,20 @@ const DesktopWorkspace = ({
|
||||
}, [engine, allowLayoutPersistence, tenantId, viewId]);
|
||||
|
||||
useEffect(() => {
|
||||
engine.setItems(items);
|
||||
}, [engine, items]);
|
||||
const nextItems = searchResults ? searchResults : documents;
|
||||
engine.setItems(nextItems || []);
|
||||
}, [engine, documents, searchResults]);
|
||||
|
||||
useEffect(() => {
|
||||
engine.setDocumentLookup(documentLookup);
|
||||
}, [engine, documentLookup]);
|
||||
const map = new Map();
|
||||
items.forEach((doc) => {
|
||||
const key = doc?.id != null ? String(doc.id) : null;
|
||||
if (key) {
|
||||
map.set(key, doc);
|
||||
}
|
||||
});
|
||||
engine.setDocumentLookup(map);
|
||||
}, [engine, items]);
|
||||
|
||||
useEffect(() => {
|
||||
engine.setEnsureDocumentSize(ensureDocumentSize);
|
||||
|
||||
Reference in New Issue
Block a user