Skip to content

Commit 6753a2c

Browse files
committed
fix(livepreview): use unique iframe id for mdviewer to avoid duplicate DOM ids
The mdviewer iframe now uses id="panel-md-preview-frame" instead of sharing "panel-live-preview-frame" with the HTML preview iframe. Fixes duplicate ID causing test failures in Device Size & Resize Ruler.
1 parent 37c3158 commit 6753a2c

3 files changed

Lines changed: 8 additions & 4 deletions

File tree

src/extensionsIntegrated/Phoenix-live-preview/live-preview.css

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
height: 100%;
2626
}
2727

28-
#panel-live-preview-frame{
28+
#panel-live-preview-frame,
29+
#panel-md-preview-frame {
2930
background-color: white;
3031
position: relative;
3132
}

src/extensionsIntegrated/Phoenix-live-preview/main.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ define(function (require, exports, module) {
125125

126126
const LIVE_PREVIEW_PANEL_ID = "live-preview-panel";
127127
const LIVE_PREVIEW_IFRAME_ID = "panel-live-preview-frame";
128+
const MDVIEWR_IFRAME_ID = "panel-md-preview-frame";
128129
const _sandboxAttr = Phoenix.isTestWindow ? "" :
129130
'sandbox="allow-same-origin allow-popups allow-popups-to-escape-sandbox allow-scripts allow-forms allow-modals allow-pointer-lock"';
130131
const LIVE_PREVIEW_IFRAME_HTML = `
@@ -137,12 +138,12 @@ define(function (require, exports, module) {
137138

138139
// Mdviewer renders untrusted markdown — tighter sandbox than live preview:
139140
// no allow-same-origin (prevents malicious scripts from accessing Phoenix context),
140-
// no allow-forms, allow-modals, allow-pointer-lock (not needed for markdown editing).
141+
// no allow-forms, allow-pointer-lock (not needed for markdown editing).
141142
// Communication works via MarkdownSync's own message handler (bypasses EventManager origin check).
142143
const _mdSandboxAttr = Phoenix.isTestWindow ? "" :
143144
'sandbox="allow-scripts allow-popups allow-popups-to-escape-sandbox allow-modals"';
144145
const MDVIEWR_IFRAME_HTML = `
145-
<iframe id="${LIVE_PREVIEW_IFRAME_ID}" title="Live Preview" style="border: none"
146+
<iframe id="${MDVIEWR_IFRAME_ID}" title="Markdown Preview" style="border: none"
146147
width="100%" height="100%" seamless="true"
147148
src='about:blank'
148149
${_mdSandboxAttr}>

src/extensionsIntegrated/Phoenix-live-preview/utils.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737

3838
define(function (require, exports, module) {
3939
const LIVE_PREVIEW_IFRAME_ID = "panel-live-preview-frame";
40+
const MDVIEWR_IFRAME_ID = "panel-md-preview-frame";
4041
const EditorManager = require("editor/EditorManager");
4142
function getExtension(filePath) {
4243
filePath = filePath || '';
@@ -98,7 +99,8 @@ define(function (require, exports, module) {
9899
if(!editor){
99100
return;
100101
}
101-
if (document.activeElement === document.getElementById(LIVE_PREVIEW_IFRAME_ID)) {
102+
if (document.activeElement === document.getElementById(LIVE_PREVIEW_IFRAME_ID) ||
103+
document.activeElement === document.getElementById(MDVIEWR_IFRAME_ID)) {
102104
editor.focus();
103105
}
104106
}

0 commit comments

Comments
 (0)