Skip to content

use document.baseURI for sheetHref when handling inline styles#49

Merged
pendo-ops merged 1 commit intopendo-mainfrom
meg-fix-stylesheet-href-when-base-tag-present
Jun 5, 2025
Merged

use document.baseURI for sheetHref when handling inline styles#49
pendo-ops merged 1 commit intopendo-mainfrom
meg-fix-stylesheet-href-when-base-tag-present

Conversation

@megboehlert
Copy link
Copy Markdown

No description provided.

@kode-toad
Copy link
Copy Markdown

kode-toad bot commented Jun 4, 2025

Failed pendo.io/jira-ref check. Please correct Jira references in the following commits:

9b4e13a

@megboehlert megboehlert force-pushed the meg-fix-stylesheet-href-when-base-tag-present branch from 9b4e13a to 627079f Compare June 4, 2025 19:43
@kode-toad
Copy link
Copy Markdown

kode-toad bot commented Jun 4, 2025

Failed pendo.io/jira-ref check. Please correct Jira references in the following commits:

627079f

Copy link
Copy Markdown

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 patch enhances stringifyStylesheet to prefer a <base href> when resolving inline <style> URLs and adds comprehensive tests around stylesheet stringification.

  • Prefer the document’s <base href> for inline stylesheet URL resolution before falling back to location.href
  • Expand stringifyStylesheet tests to cover missing rules, .rules vs .cssRules, external vs inline styles, error handling, and browser compatibility fixes
  • Include a changeset documenting the new behavior

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
packages/rrweb-snapshot/test/utils.test.ts Add a suite of tests for stringifyStylesheet, covering various input scenarios
packages/rrweb-snapshot/src/utils.ts Update stringifyStylesheet to check for <base href> in the owner document
.changeset/twelve-nails-occur.md Document preference for <base href> resolution in the changelog
Comments suppressed due to low confidence (2)

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

  • [nitpick] The test mock returns a string instead of an HTMLBaseElement; consider returning an object with an href property (e.g., mockBase) to better mimic real DOM behavior.
querySelector: (selector: string) => selector === 'base[href]' ? 'https://example.com/test/' : null,

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

  • Add a test case that uses a CSS rule with a relative URL (e.g., url('img.png')) to verify that it is correctly resolved against the <base href> when present.
it('uses <base href> if present for inline styles', () => {

// an inline <style> element
sheetHref = s.ownerNode.ownerDocument.location.href;
const doc = s.ownerNode.ownerDocument;
const baseEl = doc.querySelector('base[href]');
Copy link

Copilot AI Jun 4, 2025

Choose a reason for hiding this comment

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

[nitpick] Consider using the standard Document.baseURI property to resolve inline stylesheet URLs instead of manual querySelector logic for simpler and more reliable behavior.

Copilot uses AI. Check for mistakes.
@megboehlert megboehlert force-pushed the meg-fix-stylesheet-href-when-base-tag-present branch from 627079f to aaa0a98 Compare June 5, 2025 13:17
@kode-toad
Copy link
Copy Markdown

kode-toad bot commented Jun 5, 2025

Failed pendo.io/jira-ref check. Please correct Jira references in the following commits:

aaa0a98

@megboehlert megboehlert changed the title prefer base href for inline style urls, else fallback to doc.location use document.baseURI for sheetHref when handling inline styles Jun 5, 2025
@megboehlert megboehlert force-pushed the meg-fix-stylesheet-href-when-base-tag-present branch from aaa0a98 to c0e10ca Compare June 5, 2025 14:06
@kode-toad
Copy link
Copy Markdown

kode-toad bot commented Jun 5, 2025

Failed pendo.io/jira-ref check. Please correct Jira references in the following commits:

c0e10ca

Copy link
Copy Markdown

@juliecheng juliecheng left a comment

Choose a reason for hiding this comment

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

your change makes sense to me!

@guntherjh
Copy link
Copy Markdown

LGTM

@guntherjh
Copy link
Copy Markdown

[merge]

@pendo-ops pendo-ops merged commit 51a5376 into pendo-main Jun 5, 2025
3 of 8 checks passed
@kode-toad
Copy link
Copy Markdown

kode-toad bot commented Jun 5, 2025

Branch meg-fix-stylesheet-href-when-base-tag-present deleted

@kode-toad kode-toad bot deleted the meg-fix-stylesheet-href-when-base-tag-present branch June 5, 2025 18:43
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.

5 participants