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
2026-04-01 12:00:00 +08:00
parent 79a7191916
commit bd5aa59589
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);
};