From 54637beffb2e344e706e2ed44ee8ec2bb127cabd Mon Sep 17 00:00:00 2001 From: john Date: Fri, 24 Jul 2026 14:21:06 +0800 Subject: [PATCH] fix preview sandbox and local analytics proxy --- mindspace-chat-save.test.mjs | 18 ++++++++++++++++++ src/components/ChatSharePreviewModal.tsx | 2 +- src/components/PageSavePreviewPanel.tsx | 2 +- vite.config.ts | 1 + 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/mindspace-chat-save.test.mjs b/mindspace-chat-save.test.mjs index d35c292..09f1706 100644 --- a/mindspace-chat-save.test.mjs +++ b/mindspace-chat-save.test.mjs @@ -117,6 +117,24 @@ test('buildChatSavePreviewUrls use local api routes', () => { ); }); +test('chat page previews keep generated scripts sandboxed and proxy analytics through Portal', async () => { + const [pageSavePreview, chatSharePreview, viteConfig] = await Promise.all([ + fs.readFile(new URL('./src/components/PageSavePreviewPanel.tsx', import.meta.url), 'utf8'), + fs.readFile(new URL('./src/components/ChatSharePreviewModal.tsx', import.meta.url), 'utf8'), + fs.readFile(new URL('./vite.config.ts', import.meta.url), 'utf8'), + ]); + + assert.match(pageSavePreview, /sandbox="allow-scripts allow-downloads"/); + assert.match(chatSharePreview, /sandbox="allow-scripts allow-popups allow-downloads"/); + for (const source of [pageSavePreview, chatSharePreview]) { + assert.doesNotMatch( + source, + /sandbox="[^"]*(?:allow-scripts[^"]*allow-same-origin|allow-same-origin[^"]*allow-scripts)[^"]*"/, + ); + } + assert.match(viteConfig, /['"]\/analytics['"]\s*:\s*portalTarget/); +}); + test('findPublishHtml resolves nested public html by basename', async () => { const root = await fs.mkdtemp(path.join(os.tmpdir(), 'memind-chat-save-')); const publishDir = path.join(root, 'MindSpace', USER_ID, 'public'); diff --git a/src/components/ChatSharePreviewModal.tsx b/src/components/ChatSharePreviewModal.tsx index 4362bfc..82d5b62 100644 --- a/src/components/ChatSharePreviewModal.tsx +++ b/src/components/ChatSharePreviewModal.tsx @@ -139,7 +139,7 @@ export function ChatSharePreviewModal({
-