/** * WorkspaceKeepAlive * * Renders the WorkspacePage permanently at the MainLayout level so it * survives route changes. Visibility is toggled via CSS `display` * instead of mount / unmount, preserving messages, SSE connections, * files, and all other workspace state. * * Persistence is scoped per `(mandateId, instanceId)` — switching to a * different mandate or instance via the navigator unmounts the previous * page and mounts a fresh one (otherwise stale state from tenant A * leaks into tenant B). */ import React, { useRef } from 'react'; import { useLocation } from 'react-router-dom'; import { WorkspacePage } from './WorkspacePage'; const _WORKSPACE_ROUTE_RE = /\/mandates\/([^/]+)\/workspace\/([^/]+)/; interface WorkspaceKeepAliveProps { isVisible: boolean; } export const WorkspaceKeepAlive: React.FC = ({ isVisible }) => { const location = useLocation(); const cachedMandateIdRef = useRef(''); const cachedInstanceIdRef = useRef(''); const match = location.pathname.match(_WORKSPACE_ROUTE_RE); if (match?.[1] && match?.[2]) { cachedMandateIdRef.current = match[1]; cachedInstanceIdRef.current = match[2]; } const mandateId = cachedMandateIdRef.current; const instanceId = cachedInstanceIdRef.current; if (!instanceId) return null; const scopeKey = `${mandateId}:${instanceId}`; return (
); };