Skip to content
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

Capture stylesheets designated as rel="preload" #1374

Merged
merged 6 commits into from
Feb 12, 2024

Conversation

andrewpomeroy
Copy link
Contributor

@andrewpomeroy andrewpomeroy commented Dec 12, 2023

Encountered an issue where stylesheets failed to capture when they were referenced by link tag with rel="preload" instead of rel="stylesheet". This change will broaden the rules so that these preloaded stylesheets can also be recognized and captured at the snapshot phase.

For background: This attribute assignment is commonly used as a performance hack for the initial loading phase of a page—meant to allow stylesheets to be preloaded—and is usually combined with onload="this.rel = 'stylesheet'" so that it is still, upon load, recognized as a stylesheet at runtime. The snapshot phase, naturally, will miss these unless we tweak the link-tag pattern matching to look for it specifically. More info: https://stackoverflow.com/a/61889123

In addition, I added reinforced pattern matching for both .css file paths—for the aforementioned scenario and the existing .js / rel="prefetch" scenario—so that paths will still be matched if they include search parameters or fragments.

Copy link

changeset-bot bot commented Dec 12, 2023

🦋 Changeset detected

Latest commit: 96ceef2

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

This PR includes changesets to release 8 packages
Name Type
rrweb-snapshot Patch
rrweb Patch
rrdom Patch
rrdom-nodejs Patch
rrweb-player Patch
@rrweb/types Patch
@rrweb/web-extension Patch
rrvideo 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
Contributor

@Juice10 Juice10 left a comment

Choose a reason for hiding this comment

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

Thanks for creating this PR @andrewpomeroy! This is a nice addition to rrweb. I found two minor things, check them out and let me know what you think and then we can merge this.

packages/rrweb-snapshot/src/utils.ts Outdated Show resolved Hide resolved
packages/rrweb-snapshot/src/utils.ts Outdated Show resolved Hide resolved
@andrewpomeroy
Copy link
Contributor Author

Thanks @Juice10! Your suggestions make perfect sense. I went ahead and made those changes.

@andrewpomeroy
Copy link
Contributor Author

Hi @Juice10 ! It looks like this is now failing tests, which look to be the same tests currently failing on master. I tried checking out #1366 and fixing them myself, but didn't get much traction.

My team is looking to close out this issue on our end; no pressure at all intended, but what are the chances of this getting merged/released in the next few weeks? We just need to be able to make the call whether to fork or not. Thanks again for your contributions 🙂

@andrewpomeroy
Copy link
Contributor Author

@Juice10 Whoops, just saw your comment here https://rrweb.slack.com/archives/C01BYDC5C93/p1702300072935979?thread_ts=1701887171.474259&cid=C01BYDC5C93 ! I'm assuming it won't be much longer then 😄 Looking forward to it!

@Juice10
Copy link
Contributor

Juice10 commented Dec 21, 2023

@andrewpomeroy hang tight Andrew, unfortunately I wasn’t able to fix master in #1366 (I should close that one), but indeed as mentioned in slack I’m hoping to merge #1239 soon which does fix master, and then we can merge this PR and do a release.

@andrewpomeroy
Copy link
Contributor Author

Great to hear! Thanks for the update.

@Juice10 Juice10 self-assigned this Jan 5, 2024
@Juice10
Copy link
Contributor

Juice10 commented Feb 2, 2024

@andrewpomeroy hey Andrew, could you pull from master, ci is passing now

@Juice10 Juice10 merged commit 314a8dd into rrweb-io:master Feb 12, 2024
6 checks passed
jaj1014 pushed a commit to pendo-io/rrweb that referenced this pull request Apr 30, 2024
* feat(Snapshot): Capture stylesheets designated as `rel="preload"`

* fix(Snapshot): Harden asset file extension matching

* Add changeset

* chore: Lint

* Tweak regex, add try-catch block on URL constructor
@eoghanmurray
Copy link
Contributor

and is usually combined with onload="this.rel = 'stylesheet'" so that it is still, upon load, recognized as a stylesheet at runtime

Shouldn't this get picked up as a mutation? And I think the mutation should then serialize the stylesheet correctly?
I think we need a test for this scenario to either demonstrate the preload bit or remove it if it isn't necessary.

@andrewpomeroy
Copy link
Contributor Author

andrewpomeroy commented May 22, 2024

Shouldn't this get picked up as a mutation?

It's been a while since I've looked at this, but to the best of my memory— these mutations don't trigger a full snapshot, which is when the stylesheet-inlining process would take place.

eoghanmurray added a commit to eoghanmurray/rrweb that referenced this pull request May 22, 2024
…red twice after a mutation to rel="stylesheet" from rel="preload"
eoghanmurray added a commit to eoghanmurray/rrweb that referenced this pull request May 22, 2024
…red twice after a mutation to rel="stylesheet" from rel="preload"
@eoghanmurray
Copy link
Contributor

Yes, thanks — I actually have since written some tests and done some more work on this; the problem was that the mutation weren't doing anything when an attribute change caused a to 'become a stylesheet'
More details here:
#1483
which is still draft and WIP

eoghanmurray added a commit to eoghanmurray/rrweb that referenced this pull request May 22, 2024
…red twice after a mutation to rel="stylesheet" from rel="preload"
@andrewpomeroy
Copy link
Contributor Author

Gotcha. Good thinking! I'm all for it.

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.

None yet

3 participants