Skip to content

Commit 39f2d29

Browse files
committed
fix: pinned md preview bypassed by force=true callers and reload
Block all _loadPreview calls when md viewer is pinned (even force=true) since previewDetails would be for the current editor file, not the pinned file. Handle reload button separately: use resendContent() to re-send the pinned document without clearing cache (reloadCurrentFile clears the cache expecting a re-send that never comes when pinned). Guard _openLivePreviewURL and _activeDocChanged to prevent LP iframe from replacing the pinned md viewer.
1 parent 8244ac5 commit 39f2d29

2 files changed

Lines changed: 25 additions & 2 deletions

File tree

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,6 +1023,14 @@ define(function (require, exports, module) {
10231023
}, "*");
10241024
}
10251025

1026+
/**
1027+
* Re-send the current document's content to the iframe without clearing cache.
1028+
* Used when pinned to refresh the preview without losing the cached DOM.
1029+
*/
1030+
function resendContent() {
1031+
_sendContent();
1032+
}
1033+
10261034
/**
10271035
* Set a callback for when the iframe requests edit mode.
10281036
* The callback should check entitlements and approve/deny.
@@ -1073,6 +1081,7 @@ define(function (require, exports, module) {
10731081
exports.deactivate = deactivate;
10741082
exports.isActive = isActive;
10751083
exports.reloadCurrentFile = reloadCurrentFile;
1084+
exports.resendContent = resendContent;
10761085
exports.setEditModeRequestHandler = setEditModeRequestHandler;
10771086
exports.setEditMode = setEditMode;
10781087
exports.setIframeReadyHandler = setIframeReadyHandler;

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -847,6 +847,12 @@ define(function (require, exports, module) {
847847
$pinUrlBtn.click(_togglePinUrl);
848848
$livePreviewPopBtn.click(_popoutLivePreview);
849849
$reloadBtn.click(()=>{
850+
if (_isMdviewrActive && urlPinned) {
851+
// When pinned, just re-send the pinned document's content
852+
MarkdownSync.resendContent();
853+
Metrics.countEvent(Metrics.EVENT_TYPE.LIVE_PREVIEW, "reloadBtn", "click");
854+
return;
855+
}
850856
if (_isMdviewrActive) {
851857
MarkdownSync.reloadCurrentFile();
852858
}
@@ -876,8 +882,7 @@ define(function (require, exports, module) {
876882
_setTitle(relativeOrFullPath, currentPreviewFile, "");
877883

878884
if (_isMdviewrActive) {
879-
if (urlPinned && !force) {
880-
// Pinned — don't switch the md viewer content
885+
if (urlPinned) {
881886
return;
882887
}
883888
// Mdviewr iframe already loaded, just update the sync for the new document
@@ -930,6 +935,12 @@ define(function (require, exports, module) {
930935
if(urlPinned && !force) {
931936
return;
932937
}
938+
// When md viewer is pinned, block ALL preview loads — the previewDetails
939+
// would be for the current editor file, not the pinned file
940+
if(urlPinned && _isMdviewrActive) {
941+
return;
942+
}
943+
933944
// Use mdviewr for markdown files (unless custom server is configured)
934945
if(previewDetails.isMarkdownFile && !previewDetails.isCustomServer && !previewDetails.isNoPreview) {
935946
_loadMdviewrPreview(previewDetails, force);
@@ -1205,6 +1216,9 @@ define(function (require, exports, module) {
12051216
_hideOverlay();
12061217
return;
12071218
}
1219+
if (_isMdviewrActive && urlPinned) {
1220+
return;
1221+
}
12081222
_loadPreview(true);
12091223
const currentPreviewDetails = await StaticServer.getPreviewDetails();
12101224
if(currentPreviewDetails.isHTMLFile && currentPreviewDetails.fullPath !== previewDetails.fullPath){

0 commit comments

Comments
 (0)