ignore style sheet changes before the target DOM was serialized

The serialized DOM will contains all the styles, so this looks safe.
This commit is contained in:
Yanzhen Yu
2020-03-22 00:36:20 +08:00
parent 02a33faaf9
commit 197526fbe8
5 changed files with 37 additions and 23 deletions

View File

@@ -523,19 +523,25 @@ function initInputObserver(
function initStyleSheetObserver(cb: styleSheetRuleCallback): listenerHandler {
const insertRule = CSSStyleSheet.prototype.insertRule;
CSSStyleSheet.prototype.insertRule = function(rule: string, index?: number) {
cb({
id: mirror.getId(this.ownerNode as INode),
adds: [{ rule, index }],
});
const id = mirror.getId(this.ownerNode as INode);
if (id !== -1) {
cb({
id,
adds: [{ rule, index }],
});
}
return insertRule.apply(this, arguments);
};
const deleteRule = CSSStyleSheet.prototype.deleteRule;
CSSStyleSheet.prototype.deleteRule = function(index: number) {
cb({
id: mirror.getId(this.ownerNode as INode),
removes: [{ index }],
});
const id = mirror.getId(this.ownerNode as INode);
if (id !== -1) {
cb({
id,
removes: [{ index }],
});
}
return deleteRule.apply(this, arguments);
};