Skip to content

fix: skip calling setAttribute on unchanged attr in diffProps #1691

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

juliecheng
Copy link
Contributor

There’s a bug (?) in Chrome where dynamically added CSS rules (via insertRule) get dropped if you call stylesheet.setAttribute('type', 'text/css') and the type is already text/css. Firefox does not drop these rules if the stylesheet already has type="text/css" and you try to set the attr again.

Note: this is specifically for when the stylesheet already has type="text/css" and we try to call setAttribute('type', 'text/css'). Calling stylesheet.setAttribute('some-other-attr', ‘foo') does not drop the styles.

Here is a script you can paste into the Chrome’s browser console to see the styles getting dropped

// Create a style element in document body
const style = document.createElement('style');
style.setAttribute('type', 'text/css');
document.body.appendChild(style);

// Add CSS rules via insertRule
style.sheet.insertRule('body { background-color: lightblue; }', 0);
style.sheet.insertRule('.test { color: red; font-weight: bold; }', 0);

// Log the initial state (should be 2)
console.log('CSS rules before setAttribute:', style.sheet.cssRules.length);

// Update attribute on the style element
style.setAttribute('type', 'text/css');

// Log the final state (should still be 2 but it'll be 0)
console.log('CSS rules after setAttribute:', style.sheet.cssRules.length);

if (style.sheet.cssRules.length === 0) {
  console.log('CSS rules were dropped');
}

Copy link

changeset-bot bot commented May 15, 2025

🦋 Changeset detected

Latest commit: bc4ab9e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 19 packages
Name Type
rrdom Patch
rrweb Patch
rrweb-snapshot Patch
rrdom-nodejs Patch
rrweb-player Patch
@rrweb/all Patch
@rrweb/replay Patch
@rrweb/record Patch
@rrweb/types Patch
@rrweb/packer Patch
@rrweb/utils Patch
@rrweb/web-extension Patch
rrvideo Patch
@rrweb/rrweb-plugin-console-record Patch
@rrweb/rrweb-plugin-console-replay Patch
@rrweb/rrweb-plugin-sequential-id-record Patch
@rrweb/rrweb-plugin-sequential-id-replay Patch
@rrweb/rrweb-plugin-canvas-webrtc-record Patch
@rrweb/rrweb-plugin-canvas-webrtc-replay Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@juliecheng juliecheng force-pushed the jc-skip-unchanged-attributes-in-diffProps branch from cf7d550 to d3263fc Compare May 15, 2025 18:19
@juliecheng juliecheng force-pushed the jc-skip-unchanged-attributes-in-diffProps branch from d3263fc to bc4ab9e Compare May 15, 2025 18:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant