use document.baseURI for sheetHref when handling inline styles#49
Conversation
|
Failed pendo.io/jira-ref check. Please correct Jira references in the following commits: |
9b4e13a to
627079f
Compare
|
Failed pendo.io/jira-ref check. Please correct Jira references in the following commits: |
There was a problem hiding this comment.
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 tolocation.href - Expand
stringifyStylesheettests to cover missing rules,.rulesvs.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', () => {
packages/rrweb-snapshot/src/utils.ts
Outdated
| // an inline <style> element | ||
| sheetHref = s.ownerNode.ownerDocument.location.href; | ||
| const doc = s.ownerNode.ownerDocument; | ||
| const baseEl = doc.querySelector('base[href]'); |
There was a problem hiding this comment.
[nitpick] Consider using the standard Document.baseURI property to resolve inline stylesheet URLs instead of manual querySelector logic for simpler and more reliable behavior.
627079f to
aaa0a98
Compare
|
Failed pendo.io/jira-ref check. Please correct Jira references in the following commits: |
aaa0a98 to
c0e10ca
Compare
|
Failed pendo.io/jira-ref check. Please correct Jira references in the following commits: |
|
LGTM |
|
[merge] |
|
Branch meg-fix-stylesheet-href-when-base-tag-present deleted |
No description provided.