Skip to content

Commit f2f2382

Browse files
committed
fix(live-preview): keep CM edits from being undone by stale md viewer reports
The md viewer flushes its own debounced edit when the same file is switched to again, and that report could reach Phoenix just after the next CM edit. MarkdownSync applied it, silently undoing the CM change, and the viewer then synced back the reverted text. This made the "editing code block content in CM sync to viewer" test flaky on CI. While a CM change is still waiting to be sent to the iframe, the iframe has not seen it, so its content reports are stale: ignore them and let the pending update bring the iframe up to date.
1 parent ab75b6e commit f2f2382

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ define(function (require, exports, module) {
272272
}
273273
clearTimeout(_debounceTimer);
274274
_debounceTimer = setTimeout(function () {
275+
_debounceTimer = null;
275276
_sendUpdate(_lastChangeOrigin);
276277
_lastChangeOrigin = null;
277278
}, DEBOUNCE_TO_IFRAME_MS);
@@ -359,6 +360,7 @@ define(function (require, exports, module) {
359360
}
360361

361362
clearTimeout(_debounceTimer);
363+
_debounceTimer = null;
362364
clearTimeout(_scrollSyncTimer);
363365
clearTimeout(_selectionSyncTimer);
364366

@@ -672,6 +674,15 @@ define(function (require, exports, module) {
672674
return;
673675
}
674676

677+
// A CM change is still waiting to go to the iframe, so the iframe made this
678+
// before it had that change: applying it would undo the change. The pending
679+
// update brings the iframe up to date instead. (e.g. the iframe flushes its
680+
// own debounced edit when the same file is switched to again, and that can
681+
// land just after the user's next CM edit.)
682+
if (_debounceTimer) {
683+
return;
684+
}
685+
675686
const markdown = data.markdown;
676687
const remoteSyncId = data._syncId;
677688

0 commit comments

Comments
 (0)