Skip to content

Commit

Permalink
Draft of the fix for adobe#5656.
Browse files Browse the repository at this point in the history
Does not work in case of a single browser because of adobe#10821.
  • Loading branch information
busykai authored and humphd committed May 20, 2015
1 parent ac66fd6 commit b895c4e
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 10 deletions.
22 changes: 16 additions & 6 deletions src/LiveDevelopment/MultiBrowserImpl/documents/LiveHTMLDocument.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,16 +206,26 @@ define(function (require, exports, module) {

var self = this,
result = HTMLInstrumentation.getUnappliedEditList(this.editor, change),
applyEditsPromise;
applyEditsPromise,
reloadPromise;

if (result.edits) {
applyEditsPromise = this.protocol.evaluate("_LD.applyDOMEdits(" + JSON.stringify(result.edits) + ")");

applyEditsPromise.always(function () {
if (result.reload) {
reloadPromise = this.protocol.reload();
reloadPromise.always(function () {
if (!isNestedTimer) {
PerfUtils.addMeasurement(perfTimerName);
PerfUtils.finalizeMeasurement(perfTimerName);
}
});
} else {
if (result.edits) {
applyEditsPromise = this.protocol.evaluate("_LD.applyDOMEdits(" + JSON.stringify(result.edits) + ")");

applyEditsPromise.always(function () {
if (!isNestedTimer) {
PerfUtils.addMeasurement(perfTimerName);
}
});
}
}

this.errors = result.errors || [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,16 @@ define(function (require, exports, module) {
return { errors: updater.errors };
}

// see if it makes sense to edit DOM or reload the page
if (HTMLDOMDiff.shouldReload(result.oldSubtree, result.newSubtree)) {
return {
dom: result.newDOM,
reload: true,
_wasIncremental: updater.isIncremental
};
}


var edits = HTMLDOMDiff.domdiff(result.oldSubtree, result.newSubtree);

// We're done with the nodeMap that was added to the subtree by the updater.
Expand Down Expand Up @@ -586,7 +596,10 @@ define(function (require, exports, module) {
// updated); the marks in the editor are more accurate.
// TODO: should we consider ripping through the dom and fixing up other offsets?
result.dom.fullBuild = false;
return { edits: result.edits };
return {
reload: result.reload,
edits: result.edits
};
} else {
if (cachedValue) {
cachedValue.invalid = true;
Expand Down
30 changes: 28 additions & 2 deletions src/language/HTMLDOMDiff.js
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,33 @@ define(function (require, exports, module) {

return edits;
}

/**
* @private
*
* Given old and new subtrees, detect conditions under which editing of
* the remote DOM will not result in a consistent state.
*
* Such conditions currently are:
* 1. Entire document replacement. Pasting entire HTML cannot be
* resonably DOM-edited.
* 2. If the edit has been made in a <script>.
*/
function shouldReload(oldNode, newNode) {
// if either new or old node is root element of the DOM
if (!oldNode.parent || !newNode.parent) {
return true;
}
if (oldNode.tag && oldNode.tag === "script") {
return true;
}
if (newNode.tag && newNode.tag === "script") {
return true;
}
return false;
}

// Public API
exports.domdiff = domdiff;
});
exports.domdiff = domdiff;
exports.shouldReload = shouldReload;
});
12 changes: 11 additions & 1 deletion src/language/HTMLInstrumentation.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@


/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50 */
/*jshint unused: false */
/*global define, $ */
/*unittests: HTML Instrumentation*/

Expand Down Expand Up @@ -180,7 +181,7 @@ define(function (require, exports, module) {
});
}
// Workaround for JSHint to not complain about the unused function
void(_dumpMarks);
//void(_dumpMarks);

/**
* Get the instrumented tagID at the specified position. Returns -1 if
Expand Down Expand Up @@ -548,6 +549,15 @@ define(function (require, exports, module) {
return { errors: updater.errors };
}

// see if it makes sense to edit DOM or reload the page
if (HTMLDOMDiff.shouldReload(result.oldSubtree, result.newSubtree)) {
return {
dom: result.newDOM,
reload: true,
_wasIncremental: updater.isIncremental
};
}

var edits = HTMLDOMDiff.domdiff(result.oldSubtree, result.newSubtree);

// We're done with the nodeMap that was added to the subtree by the updater.
Expand Down

0 comments on commit b895c4e

Please sign in to comment.