Skip to content

fix: use node.baseURI for stringifying stylesheet hrefs #1705

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

megboehlert
Copy link

Prioritize using the href from base tag (if present) when stringifying urls in inline stylesheets. Node.baseURI does just this. If a base tag is not present, it falls back to location.href.

@Copilot Copilot AI review requested due to automatic review settings June 17, 2025 14:26
Copy link

changeset-bot bot commented Jun 17, 2025

🦋 Changeset detected

Latest commit: 1bfa38c

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

This PR includes changesets to release 19 packages
Name Type
rrweb-snapshot Patch
rrweb Patch
rrdom 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

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 updates the stylesheet stringification logic to use ownerNode.baseURI for resolving URLs in inline <style> sheets and adds corresponding tests.

  • Swap fallback from ownerDocument.location.href to ownerNode.baseURI
  • Add unit tests for null rules, .cssRules fallback, and inline stylesheet baseURI resolution
  • Include a changeset entry for the patch release

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
packages/rrweb-snapshot/test/utils.test.ts Added tests for stringifyStylesheet handling of missing rules, .cssRules, and inline baseURI resolution
packages/rrweb-snapshot/src/utils.ts Changed fallback logic in stringifyStylesheet to use ownerNode.baseURI instead of ownerDocument.location.href
.changeset/lucky-trainers-joke.md Added patch-level changeset note
Comments suppressed due to low confidence (2)

packages/rrweb-snapshot/test/utils.test.ts:302

  • [nitpick] Consider adding a test case to verify that when stylesheet.href is present alongside ownerNode.baseURI, the function still prefers stylesheet.href over baseURI.
    it('uses ownerNode.baseURI for inline styles', () => {

packages/rrweb-snapshot/test/utils.test.ts:293

  • [nitpick] It may be worth adding a test for the scenario where .rules is defined but .cssRules is missing, to ensure .rules is correctly prioritized.
    it('stringifies rules using .cssRules if .rules is missing', () => {

eoghanmurray
eoghanmurray previously approved these changes Jun 23, 2025
@eoghanmurray
Copy link
Contributor

eoghanmurray commented Jun 23, 2025

Would you mind running rrweb/packages/rrweb-snapshot$ yarn prettier -w test/utils.test.ts and check in result so I can merge?

@megboehlert
Copy link
Author

@eoghanmurray pushed the lint fix just now

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