Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/grumpy-ways-own.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'rrweb-snapshot': patch
---

Fix: CSS transitions are incorrectly being applied upon rebuild in Firefox. Presumably FF doesn't finished parsing the styles in time, and applies e.g. a default margin:0 to elements which have a non-zero margin set in CSS, along with a transition on them.

Related bug report to Firefox: https://bugzilla.mozilla.org/show_bug.cgi?id=1816672​
22 changes: 22 additions & 0 deletions packages/rrweb-snapshot/src/rebuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,28 @@ export function buildNodeWithSN(

if (childN.isShadow && isElement(node) && node.shadowRoot) {
node.shadowRoot.appendChild(childNode);
} else if (
n.type === NodeType.Document &&
childN.type == NodeType.Element
) {
const htmlElement = childNode as HTMLElement;
let body: HTMLBodyElement | null = null;
htmlElement.childNodes.forEach((child) => {
if (child.nodeName === 'BODY') body = child as HTMLBodyElement;
});
if (body) {
// this branch solves a problem in Firefox where css transitions are incorrectly
// being applied upon rebuild. Presumably FF doesn't finished parsing the styles
// in time, and applies e.g. a default margin:0 to elements which have a non-zero
// margin set in CSS, along with a transition on them
htmlElement.removeChild(body);
// append <head> and <style>s
node.appendChild(childNode);
// now append <body>
htmlElement.appendChild(body);
} else {
node.appendChild(childNode);
}
} else {
node.appendChild(childNode);
}
Expand Down