Skip to content

Commit

Permalink
Delay call until all attributes are present on the new node, in case …
Browse files Browse the repository at this point in the history
…the AssetManager needs to interrogate other attributes to determine how to manage, e.g. <link with href depending on rel="stylesheet"
  • Loading branch information
eoghanmurray committed Mar 25, 2024
1 parent 842fc54 commit 5389f62
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/rrweb-snapshot/src/rebuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ function buildNode(
* We need to parse them last so they can overwrite conflicting attributes.
*/
const specialAttributes: { [key: string]: string | number } = {};
const managedAttributes: [Element, number, string][] = [];
for (const name in n.attributes) {
if (!Object.prototype.hasOwnProperty.call(n.attributes, name)) {
continue;
Expand Down Expand Up @@ -258,13 +259,15 @@ function buildNode(
continue;
} else {
node.setAttribute(name, value.toString());

options.assetManager?.manageAttribute(node, n.id, name);
managedAttributes.push([node, n.id, name]);
}
} catch (error) {
// skip invalid attribute
}
}
for (const ma of managedAttributes) {
options.assetManager?.manageAttribute(...ma);
}

for (const name in specialAttributes) {
const value = specialAttributes[name];
Expand Down

0 comments on commit 5389f62

Please sign in to comment.