Fix collab preview refresh: use src reassignment with cache-buster instead of contentWindow.reload

Cross-origin iframes may silently fail on contentWindow.location.reload().
Use src reassignment with cache-buster query param to force fresh load.
Increased debounce to 2.5s to give MkDocs more time to rebuild.

Bunker Admin
This commit is contained in:
bunker-admin 2026-03-27 13:41:02 -06:00
parent eb16815f91
commit 078bb6e313

View File

@ -938,20 +938,27 @@ export default function DocsPage() {
// Auto-refresh preview when remote changes arrive in collab mode
useEffect(() => {
if (!collab.active || !collab.yText) return;
if (!collab.active || !collab.yText || !selectedFile) return;
let refreshTimer: ReturnType<typeof setTimeout>;
const observer = () => {
clearTimeout(refreshTimer);
refreshTimer = setTimeout(() => {
previewIframeRef.current?.contentWindow?.location.reload();
}, 2000);
// Re-set src to force reload (avoids cross-origin issues with contentWindow.reload)
if (previewIframeRef.current && selectedFile) {
const url = filePathToMkDocsUrl(selectedFile);
// Append cache-buster to force fresh load
const buster = `_t=${Date.now()}`;
const sep = url.includes('?') ? '&' : '?';
previewIframeRef.current.src = url + sep + buster;
}
}, 2500);
};
collab.yText.observe(observer);
return () => {
collab.yText?.unobserve(observer);
clearTimeout(refreshTimer);
};
}, [collab.active, collab.yText]);
}, [collab.active, collab.yText, selectedFile]);
const handleToolbarSnippet = useCallback((snippetId: string) => {
if (snippetId === 'video-card') {