Skip to content

Commit 4b30782

Browse files
aboseclaude
andcommitted
fix: race condition in _loadPreview causing stale iframe overwrites
_togglePinUrl() calls _loadPreview(true) without awaiting it, so multiple concurrent _loadPreview calls can interleave. When the earlier call's getPreviewDetails() involves slow async I/O (e.g. FileSystem.existsAsync for SVG files on Chrome's virtual filesystem), a newer _loadPreview call can complete first and set the correct iframe URL. The older call then resumes with stale previewDetails and overwrites the iframe, breaking the live preview. Add a generation counter so that after the await, a _loadPreview call detects if a newer call was initiated and bails out, preventing stale results from clobbering the current preview state. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 0494d2b commit 4b30782

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

  • src/extensionsIntegrated/Phoenix-live-preview

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,8 @@ define(function (require, exports, module) {
545545
let panel,
546546
urlPinned,
547547
currentLivePreviewURL = "",
548-
currentPreviewFile = '';
548+
currentPreviewFile = '',
549+
_loadGeneration = 0;
549550

550551
function _blankIframe() {
551552
// we have to remove the dom node altog as at time chrome fails to clear workers if we just change
@@ -795,8 +796,12 @@ define(function (require, exports, module) {
795796
if(!isPreviewLoadable){
796797
return;
797798
}
799+
const thisGeneration = ++_loadGeneration;
798800
// panel-live-preview-title
799801
let previewDetails = await StaticServer.getPreviewDetails();
802+
if(thisGeneration !== _loadGeneration) {
803+
return; // A newer _loadPreview call has been made; this one is stale
804+
}
800805
if(urlPinned && !force) {
801806
return;
802807
}

0 commit comments

Comments
 (0)