Skip to content

Commit c5670f3

Browse files
committed
fix: leaky listeners/event handlers in live document
also removed a reset function that doesnt seem to be userd rather than when thne live preview page was loaded, and at load time, the page is resetted/has no state anyway
1 parent bbc9205 commit c5670f3

File tree

3 files changed

+2
-45
lines changed

3 files changed

+2
-45
lines changed

src/LiveDevelopment/BrowserScripts/RemoteFunctions.js

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5332,38 +5332,6 @@ function RemoteFunctions(config = {}) {
53325332
cleanupPreviousElementState();
53335333
}
53345334

5335-
/**
5336-
* this is a hard reset function, it resets every live preview edit thing, whether it be UI boxes
5337-
* highlighting, any timers or anything
5338-
*/
5339-
function resetState() {
5340-
_stopAutoScroll();
5341-
5342-
if (_hoverHighlight) {
5343-
_hoverHighlight.clear();
5344-
_hoverHighlight = null;
5345-
}
5346-
if (_clickHighlight) {
5347-
_clickHighlight.clear();
5348-
_clickHighlight = null;
5349-
}
5350-
5351-
dismissUIAndCleanupState();
5352-
5353-
const allElements = window.document.querySelectorAll(`[${GLOBALS.DATA_BRACKETS_ID_ATTR}]`);
5354-
for (let i = 0; i < allElements.length; i++) {
5355-
if (allElements[i]._originalBackgroundColor !== undefined) {
5356-
clearElementBackground(allElements[i]);
5357-
}
5358-
}
5359-
5360-
if (config.mode === 'edit') {
5361-
_hoverHighlight = new Highlight("#c8f9c5", true);
5362-
_clickHighlight = new Highlight("#cfc", true);
5363-
}
5364-
}
5365-
5366-
53675335
/**
53685336
* This function is responsible to move the cursor to the end of the text content when we start editing
53695337
* @param {DOMElement} element
@@ -5659,7 +5627,6 @@ function RemoteFunctions(config = {}) {
56595627
"startEditing" : startEditing,
56605628
"finishEditing" : finishEditing,
56615629
"dismissUIAndCleanupState" : dismissUIAndCleanupState,
5662-
"resetState" : resetState,
56635630
"enableHoverListeners" : enableHoverListeners,
56645631
"handleDownloadEvent" : handleDownloadEvent,
56655632
"showToastMessage" : showToastMessage

src/LiveDevelopment/LiveDevMultiBrowser.js

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,6 @@ define(function (require, exports, module) {
435435
const urlString = `${url.origin}${url.pathname}`;
436436
if (_liveDocument && urlString === _resolveUrl(_liveDocument.doc.file.fullPath)) {
437437
_setStatus(STATUS_ACTIVE);
438-
resetLPEditState();
439438
}
440439
}
441440
Metrics.countEvent(Metrics.EVENT_TYPE.LIVE_PREVIEW, "connect",
@@ -719,17 +718,6 @@ define(function (require, exports, module) {
719718
}
720719
}
721720

722-
/**
723-
* this function is to completely reset the live preview edit
724-
* its done so that when live preview is opened/popped out, we can re-update the config so that
725-
* there are no stale markers and edit works perfectly
726-
*/
727-
function resetLPEditState() {
728-
if (_protocol) {
729-
_protocol.evaluate("_LD.resetState()");
730-
}
731-
}
732-
733721
/**
734722
* Originally unload and reload agents. It doesn't apply for this new implementation.
735723
* @return {jQuery.Promise} Already resolved promise.

src/LiveDevelopment/MultiBrowserImpl/documents/LiveDocument.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ define(function (require, exports, module) {
6464
this._onActiveEditorChange = this._onActiveEditorChange.bind(this);
6565
this._onCursorActivity = this._onCursorActivity.bind(this);
6666

67+
EditorManager.off(`activeEditorChange.LiveDocument-${this.doc.file.fullPath}`);
6768
EditorManager.on(`activeEditorChange.LiveDocument-${this.doc.file.fullPath}`, this._onActiveEditorChange);
6869

6970
if (editor) {
@@ -143,6 +144,7 @@ define(function (require, exports, module) {
143144

144145
if (this.editor) {
145146
this.setInstrumentationEnabled(true, true);
147+
this.editor.off("cursorActivity", this._onCursorActivity);
146148
this.editor.on("cursorActivity", this._onCursorActivity);
147149
this.updateHighlight();
148150
}

0 commit comments

Comments
 (0)