diff --git a/frontend/src/app/AppLayout.jsx b/frontend/src/app/AppLayout.jsx index a54a655..b318601 100644 --- a/frontend/src/app/AppLayout.jsx +++ b/frontend/src/app/AppLayout.jsx @@ -196,13 +196,7 @@ const AppLayout = () => { const [selectedFolder, setSelectedFolder] = useState(routeFolderId || 'root'); const [currentFolder, setCurrentFolder] = useState(null); const [currentSubfolders, setCurrentSubfolders] = useState([]); - const [documents, setDocumentsState] = useState([]); - const setDocuments = useCallback((updater) => { - const stack = new Error('[trace] setDocuments invoked').stack?.split('\n').slice(1, 10); - console.log('[desk][trace] setDocuments invoked', { type: typeof updater }); - console.log('[desk][trace] setDocuments stack', stack); - setDocumentsState(updater); - }, []); + const [documents, setDocuments] = useState([]); const [documentsViewMode, setDocumentsViewMode] = useState(() => { if (typeof window === 'undefined') { return 'list'; @@ -351,37 +345,6 @@ const AppLayout = () => { } }, [appDispatch]); const [searchResults, setSearchResults] = useState(null); - const documentsTraceRef = useRef(documents); - const searchResultsTraceRef = useRef(searchResults); - useEffect(() => { - if (documentsTraceRef.current !== documents) { - const prev = documentsTraceRef.current || []; - const next = documents || []; - const stack = new Error('[trace] documents updated').stack?.split('\n').slice(1, 8); - console.log('[desk][trace] documents state updated', { - prevCount: prev.length, - nextCount: next.length, - sameRef: prev === next, - }); - console.log('[desk][trace] documents stack', stack); - documentsTraceRef.current = documents; - } - }, [documents]); - - useEffect(() => { - if (searchResultsTraceRef.current !== searchResults) { - const prev = searchResultsTraceRef.current || []; - const next = searchResults || []; - const stack = new Error('[trace] searchResults updated').stack?.split('\n').slice(1, 8); - console.log('[desk][trace] searchResults state updated', { - prevCount: Array.isArray(prev) ? prev.length : null, - nextCount: Array.isArray(next) ? next.length : null, - sameRef: prev === next, - }); - console.log('[desk][trace] searchResults stack', stack); - searchResultsTraceRef.current = searchResults; - } - }, [searchResults]); const [previewEntries, setPreviewEntries] = useState(() => new Map()); const previewInflightRef = useRef(new Map()); const previewReturnPathRef = useRef(null); diff --git a/frontend/src/desktop/DesktopWorkspace.jsx b/frontend/src/desktop/DesktopWorkspace.jsx index 6dea893..95b118e 100644 --- a/frontend/src/desktop/DesktopWorkspace.jsx +++ b/frontend/src/desktop/DesktopWorkspace.jsx @@ -32,7 +32,7 @@ import DesktopDocumentCard from './DesktopDocumentCard'; import './DesktopWorkspace.css'; const DEBUG_DRAG = false; -const DEBUG_FOCUS = true; +const DEBUG_FOCUS = false; const usePreviewMetadata = (documents, getDocumentAsset, ensureAssetUrl) => { const [metadataMap, setMetadataMap] = useState(() => new Map()); @@ -140,23 +140,6 @@ 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()); @@ -231,33 +214,8 @@ const DesktopWorkspace = ({ } = workspaceSnapshot; useEffect(() => { - const isDevEnv = () => { - if (typeof globalThis === 'undefined') { - return true; - } - const proc = globalThis.process; - if (!proc || typeof proc !== 'object') { - return true; - } - const env = proc.env; - if (!env || typeof env !== 'object') { - return true; - } - return env.NODE_ENV !== 'production'; - }; - const shouldWaitForPersisted = allowLayoutPersistence && !initialLoadDone; - if (isDevEnv()) { - console.log('[desk][layout] React effect -> ensureLayoutForItems', { - docSizeVersion, - initialLoadDone, - itemCount: items.length, - allowLayoutPersistence, - shouldWaitForPersisted, - }); - } - if (shouldWaitForPersisted) { return; } @@ -430,16 +388,10 @@ const DesktopWorkspace = ({ const focusTarget = () => { try { - if (DEBUG_FOCUS) { - console.log('[desk] focusCanvas -> attempting focus', canvas); - } canvas.focus({ preventScroll: true }); - if (DEBUG_FOCUS) { - console.log('[desk] focusCanvas: applied focus. activeElement:', document?.activeElement); - } } catch (error) { if (DEBUG_FOCUS) { - console.warn('[desk] focusTarget failed to focus canvas', error); + void error; } } }; @@ -449,22 +401,12 @@ const DesktopWorkspace = ({ return; } - if (DEBUG_FOCUS) { - console.log('[desk] requestCanvasFocus -> scheduling deferred focus'); - } - if (typeof window.requestAnimationFrame === 'function') { window.requestAnimationFrame(() => { - if (DEBUG_FOCUS) { - console.log('[desk] requestCanvasFocus -> executing deferred focus (rAF)'); - } focusTarget(); }); } else { setTimeout(() => { - if (DEBUG_FOCUS) { - console.log('[desk] requestCanvasFocus -> executing deferred focus (timeout)'); - } focusTarget(); }, 0); } diff --git a/frontend/src/desktop/tags/useDeskTagInteractions.js b/frontend/src/desktop/tags/useDeskTagInteractions.js index bd2048f..9a2750d 100644 --- a/frontend/src/desktop/tags/useDeskTagInteractions.js +++ b/frontend/src/desktop/tags/useDeskTagInteractions.js @@ -11,7 +11,7 @@ import { } from '../../documents/tagTransfer'; const TAG_REMOVE_DISTANCE = 160; -const DEBUG_DROP = true; +const DEBUG_DROP = false; const createDragPreview = (node, clientX, clientY) => { if (!(node instanceof HTMLElement)) { @@ -132,9 +132,7 @@ export const useDeskTagInteractions = ({ void (async () => { try { await removePromise; - if (DEBUG_DROP) { - console.log('[desk] finalizeTagDrag -> removed tag due to fling'); - } + void DEBUG_DROP; } catch (error) { console.error('Failed to remove tag after drag', error); scheduleShowNode(); diff --git a/frontend/src/desktop/useDocumentDrag.js b/frontend/src/desktop/useDocumentDrag.js index 3c4a605..664567f 100644 --- a/frontend/src/desktop/useDocumentDrag.js +++ b/frontend/src/desktop/useDocumentDrag.js @@ -123,7 +123,7 @@ const useDocumentDrag = (options = {}) => { capturedTarget.releasePointerCapture(pointerId); } catch (error) { if (debugDrag) { - console.warn('[desk] releasePointerCapture failed', error); + void error; } } } @@ -143,18 +143,6 @@ const useDocumentDrag = (options = {}) => { const handlePointerDown = useCallback( (event, docIdInput, options = {}) => { - if (debugDrag) { - console.log( - '[desk] handlePointerDown fired for doc', - docIdInput, - 'button', - event.button, - 'pointerType', - event.pointerType, - 'pointerId', - event.pointerId, - ); - } preventAll(event); const docId = docIdInput != null ? docIdInput : null; @@ -268,7 +256,7 @@ const useDocumentDrag = (options = {}) => { capturedTarget.setPointerCapture(event.pointerId); } catch (error) { if (debugDrag) { - console.warn('[desk] setPointerCapture failed', error); + void error; } } } @@ -424,22 +412,11 @@ const useDocumentDrag = (options = {}) => { (event) => { const state = dragStateRef.current; if (!state) { - if (debugDrag) { - console.log('[desk] handlePointerMove: no drag state for pointer', event.pointerId); + return; } - return; - } - if (state.pointerId !== event.pointerId) { - if (debugDrag) { - console.log( - '[desk] handlePointerMove: pointer mismatch expected', - state.pointerId, - 'got', - event.pointerId, - ); + if (state.pointerId !== event.pointerId) { + return; } - return; - } preventAll(event); if (state.isGroup) { @@ -550,7 +527,6 @@ const useDocumentDrag = (options = {}) => { setDragTransform(item.docId, payload); const node = itemRefs.current.get(item.docId); applyDomTransform(node, payload); - console.log('[desk] drag update', item.docId, payload.centerX, payload.centerY); }); state.lastClientX = event.clientX; @@ -565,9 +541,6 @@ const useDocumentDrag = (options = {}) => { return; } if (state.locked) { - if (debugDrag) { - console.log('[desk] handlePointerMove: locked drag for doc', state.docKey); - } return; } @@ -669,7 +642,6 @@ const useDocumentDrag = (options = {}) => { setDragTransform(state.docKey, transformPayload); const primaryNode = itemRefs.current.get(state.docKey); applyDomTransform(primaryNode, transformPayload); - console.log('[desk] drag update', state.docKey, transformPayload.centerX, transformPayload.centerY); const offsetX = pointerCanvasX - currentCenterX; const offsetY = pointerCanvasY - currentCenterY; @@ -710,9 +682,7 @@ const useDocumentDrag = (options = {}) => { state.localPointerOffsetY = updatedLocalOffsetY; } - if (debugDrag) { - console.log('[desk] handlePointerMove: moved doc', state.docKey, 'to', currentCenterX, currentCenterY); - } + void debugDrag; }, [ bringToFront, diff --git a/frontend/src/desktop/workspaceEngine.js b/frontend/src/desktop/workspaceEngine.js index 3da8c02..45d8898 100644 --- a/frontend/src/desktop/workspaceEngine.js +++ b/frontend/src/desktop/workspaceEngine.js @@ -17,23 +17,6 @@ export const ANGULAR_DAMPING = 11; export const TORQUE_TO_ACCELERATION = 0.006; export const SETTLE_ANGULAR_VELOCITY = 1.2; -const getNodeEnv = () => { - if (typeof globalThis === 'undefined') { - return undefined; - } - const proc = globalThis.process; - if (!proc || typeof proc !== 'object') { - return undefined; - } - const env = proc.env; - if (!env || typeof env !== 'object') { - return undefined; - } - return env.NODE_ENV; -}; - -const isDevEnvironment = () => getNodeEnv() !== 'production'; - export const applyDomTransform = ( node, { @@ -433,17 +416,6 @@ export class WorkspaceEngine { } updateConfig({ allowLayoutPersistence, tenantId, viewId }) { - if (isDevEnvironment()) { - console.log('[desk][config] updateConfig -> received', { - allowLayoutPersistence, - tenantId, - viewId, - currentAllow: this.allowLayoutPersistence, - currentTenant: this.tenantId, - currentView: this.viewId, - initialLoadDone: this.initialLoadDone, - }); - } const allowChanged = typeof allowLayoutPersistence === 'boolean' && allowLayoutPersistence !== this.allowLayoutPersistence; @@ -451,9 +423,6 @@ export class WorkspaceEngine { const viewChanged = viewId !== undefined && viewId !== this.viewId; if (!allowChanged && !tenantChanged && !viewChanged) { - if (isDevEnvironment()) { - console.log('[desk][config] updateConfig -> no changes'); - } if ( this.allowLayoutPersistence && this.tenantId @@ -461,9 +430,6 @@ export class WorkspaceEngine { && !this.initialLoadDone && !this.loadingPersisted ) { - if (isDevEnvironment()) { - console.log('[desk][config] updateConfig -> triggering load for pending persistence'); - } this.loadPersistedLayout(); } return; @@ -480,9 +446,6 @@ export class WorkspaceEngine { } if (!this.allowLayoutPersistence) { - if (isDevEnvironment()) { - console.log('[desk][config] updateConfig -> persistence disabled, clearing state'); - } this.persistedLayout = new Map(); this.layoutDirty = false; this.emit(); @@ -490,22 +453,10 @@ export class WorkspaceEngine { } if (!this.tenantId || !this.viewId) { - if (isDevEnvironment()) { - console.log('[desk][config] updateConfig -> missing tenant/view, waiting', { - tenantId: this.tenantId, - viewId: this.viewId, - }); - } return; } if (!this.initialLoadDone) { - if (isDevEnvironment()) { - console.log('[desk][config] updateConfig -> fetching persisted layout', { - tenantId: this.tenantId, - viewId: this.viewId, - }); - } this.loadPersistedLayout(); } } @@ -522,14 +473,6 @@ export class WorkspaceEngine { this.ensureLayoutForItems(); } this.recalcVisibleDocIds(); - if (isDevEnvironment()) { - console.log('[desk][config] setItems', { - itemCount: this.items.length, - canGenerateLayoutImmediately, - allowLayoutPersistence: this.allowLayoutPersistence, - initialLoadDone: this.initialLoadDone, - }); - } } setDocumentLookup(map) { @@ -563,14 +506,6 @@ export class WorkspaceEngine { this.ensureLayoutForItems(); this.recalcVisibleDocIds(); this.emit(); - if (isDevEnvironment()) { - console.log('[desk][config] setCanvasSize', { - width, - height, - allowLayoutPersistence: this.allowLayoutPersistence, - initialLoadDone: this.initialLoadDone, - }); - } } setDraggingId(docId) { @@ -909,31 +844,15 @@ export class WorkspaceEngine { } ensureLayoutForItems() { - if (this.allowLayoutPersistence && !this.initialLoadDone) { - if (isDevEnvironment()) { - console.log('[desk][layout] ensureLayoutForItems -> waiting for persisted layout to load'); - } - return; - } - const persistenceReady = !this.allowLayoutPersistence || !this.tenantId || !this.viewId || this.initialLoadDone; const canvasReady = Boolean(this.canvasSize.width && this.canvasSize.height); const sizesReady = !this.items.some((doc) => !this.ensureDocumentSize(doc)); if (!persistenceReady) { - if (isDevEnvironment()) { - console.log('[desk][layout] ensureLayoutForItems -> waiting for persisted layout to load', { - allowLayoutPersistence: this.allowLayoutPersistence, - initialLoadDone: this.initialLoadDone, - }); - } return; } if (!canvasReady) { - if (isDevEnvironment()) { - console.log('[desk][layout] ensureLayoutForItems -> canvas missing size', this.canvasSize); - } return; } if (!this.items.length) { @@ -945,9 +864,6 @@ export class WorkspaceEngine { } if (!sizesReady) { - if (isDevEnvironment()) { - console.log('[desk][layout] ensureLayoutForItems -> waiting for document sizes'); - } return; } @@ -956,11 +872,8 @@ export class WorkspaceEngine { const canvasWidth = this.canvasSize.width || DESK_DEFAULT_CANVAS_WIDTH; const canvasHeight = this.canvasSize.height || DESK_DEFAULT_CANVAS_HEIGHT; const docsNeedingLayout = []; - let generatedCount = 0; const currentEntries = new Map(this.layout); - let persistedAppliedCount = 0; - let reusedCurrentCount = 0; this.items.forEach((doc) => { if (!doc?.id) { @@ -982,8 +895,6 @@ export class WorkspaceEngine { const persisted = this.persistedLayout.get(docKey); const currentEntry = currentEntries.get(docKey) || null; - const hasPersisted = Boolean(persisted); - const hasCurrent = !hasPersisted && Boolean(currentEntry); let existing = persisted || currentEntry; if (existing) { const defaultCenterX = (minCenterX + maxCenterX) / 2; @@ -996,11 +907,6 @@ export class WorkspaceEngine { const z = existing.z ?? maxZ; maxZ = Math.max(maxZ, z); next.set(docKey, { centerX, centerY, rotation, z, width: docWidth, height: docHeight }); - if (hasPersisted) { - persistedAppliedCount += 1; - } else if (hasCurrent) { - reusedCurrentCount += 1; - } return; } @@ -1027,31 +933,14 @@ export class WorkspaceEngine { ); generatedLayout.forEach((entry, docId) => { next.set(docId, entry); - generatedCount += 1; }); maxZ = Math.max(maxZ, updatedMaxZ); - if (isDevEnvironment()) { - console.log('[desk][layout] ensureLayoutForItems -> generated layout for items', { - requested: docsNeedingLayout.length, - applied: generatedCount, - }); - } } this.layout = next; this.zCounter = Math.max(this.zCounter, maxZ); this.syncLayoutSnapshot(); this.recalcVisibleDocIds(); - if (isDevEnvironment()) { - console.log('[desk][layout] ensureLayoutForItems -> applied layout', { - items: this.items.length, - layoutSize: this.layout.size, - persistedAppliedCount, - reusedCurrentCount, - generatedCount, - initialLoadDone: this.initialLoadDone, - }); - } } recalcVisibleDocIds() { @@ -1222,38 +1111,14 @@ export class WorkspaceEngine { async loadPersistedLayout() { if (!this.allowLayoutPersistence || !this.tenantId || !this.viewId) { - if (isDevEnvironment()) { - console.log('[desk][load] loadPersistedLayout -> aborted, missing config', { - allowLayoutPersistence: this.allowLayoutPersistence, - tenantId: this.tenantId, - viewId: this.viewId, - }); - } return; } if (this.loadingPersisted || this.initialLoadDone) { - if (isDevEnvironment()) { - console.log('[desk][load] loadPersistedLayout -> already loading or done', { - loadingPersisted: this.loadingPersisted, - initialLoadDone: this.initialLoadDone, - }); - } return; } this.loadingPersisted = true; try { - if (isDevEnvironment()) { - console.log('[desk][load] loadPersistedLayout -> fetching', { - tenantId: this.tenantId, - viewId: this.viewId, - }); - } const records = await fetchLayoutRecords({ tenantId: this.tenantId, viewId: this.viewId }); - if (isDevEnvironment()) { - console.log('[desk][load] loadPersistedLayout -> fetched records', { - count: records.length, - }); - } const map = new Map(); records.forEach((record) => { if (!record || !record.documentId) { @@ -1276,12 +1141,6 @@ export class WorkspaceEngine { this.layoutSnapshot = new Map(this.layout); this.ensureLayoutForItems(); this.initialLoadDone = true; - if (isDevEnvironment()) { - console.log('[desk][load] loadPersistedLayout -> applied persisted layout', { - layoutSize: this.layout.size, - persistedSize: this.persistedLayout.size, - }); - } this.emit(); } catch (error) { console.warn('[desk] Failed to load persisted layout', error); @@ -1292,11 +1151,6 @@ export class WorkspaceEngine { if (!this.layout.size) { this.ensureLayoutForItems(); } - if (isDevEnvironment()) { - console.log('[desk][load] loadPersistedLayout -> fallback to generated layout', { - layoutSize: this.layout.size, - }); - } this.emit(); } }