improve rrdom robustness (#1091)

This commit is contained in:
Yun Feng
2023-02-09 20:10:32 +11:00
committed by GitHub
parent 3a26e36f6f
commit 4ee86fe66d
7 changed files with 872 additions and 176 deletions

View File

@@ -230,14 +230,24 @@ export class Replayer {
else if (data.source === IncrementalSource.StyleDeclaration)
this.applyStyleDeclaration(data, styleSheet);
},
afterAppend: (node: Node, id: number) => {
for (const plugin of this.config.plugins || []) {
if (plugin.onBuild) plugin.onBuild(node, { id, replayer: this });
}
},
};
this.iframe.contentDocument &&
diff(
this.iframe.contentDocument,
this.virtualDom,
replayerHandler,
this.virtualDom.mirror,
);
if (this.iframe.contentDocument)
try {
diff(
this.iframe.contentDocument,
this.virtualDom,
replayerHandler,
this.virtualDom.mirror,
);
} catch (e) {
console.warn(e);
}
this.virtualDom.destroyTree();
this.usingVirtualDom = false;
@@ -858,6 +868,8 @@ export class Replayer {
);
}
// Skip the plugin onBuild callback in the virtual dom mode
if (this.usingVirtualDom) return;
for (const plugin of this.config.plugins || []) {
if (plugin.onBuild)
plugin.onBuild(builtNode, {
@@ -1475,6 +1487,8 @@ export class Replayer {
return;
}
const afterAppend = (node: Node | RRNode, id: number) => {
// Skip the plugin onBuild callback for virtual dom
if (this.usingVirtualDom) return;
for (const plugin of this.config.plugins || []) {
if (plugin.onBuild) plugin.onBuild(node, { id, replayer: this });
}