feat: HTML 预览支持未保存草稿(沙箱内 srcdoc,不破坏 origin 安全) - #11
Open
Electricitysheep wants to merge 1 commit into
Open
Conversation
Closes the 'HTML 预览渲染的是已保存文件(不反映未保存草稿)' limitation from the README, without breaking the preview's origin-safety model: - html-preview.ts: dependency-free htmlPreviewTarget decision — a dirty HTML draft renders through srcdoc ONLY while the sandbox is enabled (a sandboxed srcdoc frame is opaque; it cannot touch the GUI origin). With the sandbox disabled, srcdoc is refused and the saved-file route stays, because an unsandboxed srcdoc frame would inherit the GUI origin. - TextEditor: the preview iframe uses the decision (src vs srcDoc), with a 'previewing draft' hint bar; relative assets in draft mode are unavailable by construction (srcdoc has no real base URL). - tests: html-preview.spec.ts 5/5 (clean/dirty/sandbox-off/non-HTML/null draft). Full suite: 413 tests, 7 pre-existing Windows-only failures unchanged.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概述
解决 README「已知限制」中的 HTML 预览渲染的是已保存文件(不反映未保存草稿),且不破坏预览的 origin 安全模型:
htmlPreviewTarget(src/client/html-preview.ts):srcdoc渲染——沙箱化 srcdoc frame 是 opaque origin,无法触碰 GUI origin(安全)TextEditor的预览 iframe 改用该决策(srcvssrcDoc),并在草稿预览时显示提示条("预览中:未保存草稿(相对资源不可用…)")——srcdoc 无真实 base URL,相对资源在草稿模式下按构造不可用,已注明测试
tests/html-preview.spec.ts5/5:干净 → route / dirty+沙箱 → srcdoc / dirty+沙箱关闭 → 拒绝 srcdoc(安全) / 非 HTML 忽略草稿 / draft 为 null 保持 routepnpm typecheck✅pnpm build✅pnpm test:413 tests,406 通过 + 7 个 Windows 平台既有失败(与本 PR 无关,macOS/CI 全绿)破坏性变更
无(仅新增可选草稿预览行为;缺省/干净/沙箱关闭时保持原状)。