Skip to content

Commit d71c0aa

Browse files
committed
fix: live preview related document handling and editor event leak threshold
Fix null liveDoc access when a related document is not found, guard against duplicate StylesheetAdded race, use consistent url key, and raise active-editor-changed leak threshold to 50.
1 parent fc2f55e commit d71c0aa

2 files changed

Lines changed: 12 additions & 8 deletions

File tree

src/LiveDevelopment/LiveDevMultiBrowser.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -189,15 +189,14 @@ define(function (require, exports, module) {
189189
* @param {string} url Absolute URL of the related document
190190
*/
191191
function _handleRelatedDocumentDeleted(url) {
192-
var liveDoc = _relatedDocuments[url];
192+
const liveDoc = _relatedDocuments[url];
193193
if (liveDoc) {
194194
delete _relatedDocuments[url];
195+
if (_server) {
196+
_server.remove(liveDoc);
197+
}
198+
_closeDocument(liveDoc);
195199
}
196-
197-
if (_server) {
198-
_server.remove(liveDoc);
199-
}
200-
_closeDocument(liveDoc);
201200
}
202201

203202
/**
@@ -313,12 +312,17 @@ define(function (require, exports, module) {
313312
var docPromise = DocumentManager.getDocumentForPath(path);
314313

315314
docPromise.done(function (doc) {
315+
// Re-check after async gap: another StylesheetAdded event may have
316+
// already created a live document for this URL while we were waiting.
317+
if (_relatedDocuments[url]) {
318+
return;
319+
}
316320
if ((_classForDocument(doc) === LiveCSSDocument) &&
317321
(!_liveDocument || (doc !== _liveDocument.doc))) {
318322
var liveDoc = _createLiveDocument(doc, doc._masterEditor, roots);
319323
if (liveDoc) {
320324
_server.add(liveDoc);
321-
_relatedDocuments[doc.url] = liveDoc;
325+
_relatedDocuments[url] = liveDoc;
322326
liveDoc.on("updateDoc", function (event, url) {
323327
var path = _server.urlToPath(url),
324328
doc = getLiveDocForPath(path);

src/editor/EditorManager.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -775,7 +775,7 @@ define(function (require, exports, module) {
775775

776776
// Set up event dispatching
777777
EventDispatcher.makeEventDispatcher(exports);
778-
EventDispatcher.setLeakThresholdForEvent(EVENT_ACTIVE_EDITOR_CHANGED, 30);
778+
EventDispatcher.setLeakThresholdForEvent(EVENT_ACTIVE_EDITOR_CHANGED, 50);
779779

780780
// File-based preferences handling
781781
exports.on(EVENT_ACTIVE_EDITOR_CHANGED, function (e, current) {

0 commit comments

Comments
 (0)