-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
fix: use document.baseURI for sheetHref when handling inline styles #1700
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
fix: use document.baseURI for sheetHref when handling inline styles #1700
Conversation
🦋 Changeset detectedLatest commit: 43689b7 The changes in this PR will be included in the next version bump. This PR includes changesets to release 19 packages
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 |
There was a problem hiding this 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 logic for handling inline stylesheets by using document.baseURI to resolve URLs in inline styles.
- Updated utils.ts to use baseURI over location.href for inline <style> elements.
- Added comprehensive test cases in utils.test.ts to cover scenarios when rules are missing, using cssRules, and verifying URL absolutification with baseURI.
- Included a changeset file detailing the patch update for rrweb-snapshot.
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 test cases for the new stringifyStylesheet behavior |
packages/rrweb-snapshot/src/utils.ts | Modified inline stylesheet URL resolution to use ownerDocument.baseURI instead of location.href |
.changeset/twelve-nails-occur.md | Documented the changes and the rationale behind prioritizing the base href resolution |
packages/rrweb-snapshot/src/utils.ts
Outdated
@@ -120,7 +120,7 @@ export function stringifyStylesheet(s: CSSStyleSheet): string | null { | |||
let sheetHref = s.href; | |||
if (!sheetHref && s.ownerNode && s.ownerNode.ownerDocument) { | |||
// an inline <style> element | |||
sheetHref = s.ownerNode.ownerDocument.location.href; | |||
sheetHref = s.ownerNode.ownerDocument.baseURI; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sheetHref = s.ownerNode.ownerDocument.baseURI; | |
sheetHref = s.ownerNode.baseURI; |
I don't think the ownerDocument bit is necessary anymore!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call out! I opened a new PR with this change.
5e2d383
to
43689b7
Compare
new PR with requested changes here |
Prioritize using the href from base tag (if present) when stringifying urls in inline stylesheets. Document.baseURI does just this. If a base tag is not present, it falls back to location.href.