Skip to content

fix: do not throw on empty cdata #1702

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

pauldambra
Copy link
Contributor

we had a customer whose SVGs are created with styling provided in CDATA tags
these ended up in replay with empty text content and would throw in the player, making the entire recording unplayable

we should be able to record them, but, for now, at least to not fail when we try to playback

@Copilot Copilot AI review requested due to automatic review settings June 9, 2025 19:28
Copy link

changeset-bot bot commented Jun 9, 2025

⚠️ No Changeset found

Latest commit: 5e04833

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR prevents playback failures caused by empty CDATA sections by returning null instead of creating a CDATA node when the text content is empty.

  • Avoid throwing errors on empty CDATA
  • Add a conditional check to bypass CDATA creation for empty content
Comments suppressed due to low confidence (1)

packages/rrweb-snapshot/src/rebuild.ts:435

  • Ensure that returning null for empty CDATA is safely handled by the calling code. Consider adding a comment or test to verify that null values are appropriately processed to prevent unintended behavior downstream.
if (n.textContent.trim() === '') {

@eoghanmurray
Copy link
Contributor

Do you mean that the content didn't get recorded at all?
Could you provide the for the source so we can create a test case?

@@ -432,6 +432,9 @@ function buildNode(
}
return doc.createTextNode(n.textContent);
case NodeType.CDATA:
if (n.textContent.trim() === '') {
return null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest warning here before return

@pauldambra
Copy link
Contributor Author

pauldambra commented Jun 14, 2025 via email

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.

2 participants