Skip to content

Commit 2dd6340

Browse files
Rakshit MandloiRakshit Mandloi
authored andcommitted
Fix getComputedStyle TypeError by adding DOM Element check
- Add nodeType check to ensure original is a DOM Element before calling getComputedStyle - Prevents TypeError when non-Element objects are passed to serializeOpacity - Uses nodeType === 1 to check for Element nodes (more compatible than instanceof)
1 parent 12a8af6 commit 2dd6340

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

packages/dom/src/transform-dom.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@ export function serializeScrollState(original, clone) {
2222
export function serializeOpacity(original, clone) {
2323
if (!original || !clone) return;
2424

25+
// Check if original is a DOM Element
26+
if (!original.nodeType || original.nodeType !== 1) return;
27+
2528
// Get computed opacity for the original element
2629
const opacity = window.getComputedStyle(original).opacity;
2730

2831
// Set opacity attribute for any non-default opacity value
29-
3032
clone.setAttribute('data-percy-opacity', opacity);
3133
}
3234

0 commit comments

Comments
 (0)