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

fix: check for stylesheets on current domain too #9

Merged
merged 2 commits into from
Jan 20, 2025

Conversation

pauldambra
Copy link
Member

first added in PostHog/posthog-js#1272 and PostHog/posthog-js#1275

with original PR description there


Problem

Relates to https://posthoghelp.zendesk.com/agent/tickets/14512 (and probably a bunch more support tickets)

This could also be related to rrweb-io/rrweb#1230

Addresses an issue in recordings where styles were being dropped during some route changes in SPAs

Reproduction

It's not fully clear to me how this happens or what the correct behaviour is but the problem exists when:

  1. You have a relative link element on the page:
<link href="./_app/immutable/assets/filename.css" rel="stylesheet">
  1. This gets loaded into the documents styleSheets array with the href set as https://domainname.com/_app/immutable/assets/filename.css

  2. Sometime later the domain changes away from the index page to another root e.g. https://domainname.com/home

  3. When taking the next full snapshot rrweb tries to fetch the stylesheet associated with the href:

const stylesheet = Array.from(doc.styleSheets).find((s) => {
  return s.href === (n as HTMLLinkElement).href;
});
  1. n.href now evaluates to https://domainname.com/home/_app/immutable/assets/filename.css which no longer matches the href of the stylesheet on the document and hence cannot be "found". Presumably the href on the document stylesheet does not change because the SPA is not doing a full page transition

Changes

This PR adds a backup check to look for the CSS on the root of the domain

  • It only does this for CSS files
  • It only does the lookup if a stylesheet cannot initially be found

This feels like the safest change for now but will get the opinion of others in the rrweb community too

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
Copy link
Contributor

Size Change: +5.23 kB (+0.05%)

Total Size: 10.3 MB

Filename Size Change
packages/all/dist/all.cjs 555 kB +384 B (+0.07%)
packages/all/dist/all.js 554 kB +384 B (+0.07%)
packages/all/dist/all.umd.cjs 558 kB +384 B (+0.07%)
packages/all/dist/all.umd.min.cjs 272 kB +155 B (+0.06%)
packages/record/dist/record.cjs 376 kB +384 B (+0.1%)
packages/record/dist/record.js 376 kB +384 B (+0.1%)
packages/record/dist/record.umd.cjs 379 kB +384 B (+0.1%)
packages/record/dist/record.umd.min.cjs 182 kB +155 B (+0.09%)
packages/rrweb-snapshot/dist/rrweb-snapshot.cjs 163 kB +384 B (+0.24%)
packages/rrweb-snapshot/dist/rrweb-snapshot.js 162 kB +384 B (+0.24%)
packages/rrweb-snapshot/dist/rrweb-snapshot.umd.cjs 165 kB +384 B (+0.23%)
packages/rrweb-snapshot/dist/rrweb-snapshot.umd.min.cjs 81.4 kB +155 B (+0.19%)
packages/rrweb/dist/rrweb.cjs 537 kB +384 B (+0.07%)
packages/rrweb/dist/rrweb.js 537 kB +384 B (+0.07%)
packages/rrweb/dist/rrweb.umd.cjs 539 kB +384 B (+0.07%)
packages/rrweb/dist/rrweb.umd.min.cjs 262 kB +155 B (+0.06%)
ℹ️ View Unchanged
Filename Size
packages/packer/dist/base-B40z8PPs.cjs 18.3 kB
packages/packer/dist/base-B40z8PPs.umd.cjs 19.4 kB
packages/packer/dist/base-B40z8PPs.umd.min.cjs 10.1 kB
packages/packer/dist/base-BrE4jft0.js 18.2 kB
packages/packer/dist/pack.cjs 347 B
packages/packer/dist/pack.js 285 B
packages/packer/dist/pack.umd.cjs 2.25 kB
packages/packer/dist/pack.umd.min.cjs 1.73 kB
packages/packer/dist/packer.cjs 257 B
packages/packer/dist/packer.js 136 B
packages/packer/dist/packer.umd.cjs 1.28 kB
packages/packer/dist/packer.umd.min.cjs 1.25 kB
packages/packer/dist/unpack.cjs 769 B
packages/packer/dist/unpack.js 702 B
packages/packer/dist/unpack.umd.cjs 1.79 kB
packages/packer/dist/unpack.umd.min.cjs 1.57 kB
packages/plugins/rrweb-plugin-canvas-webrtc-record/dist/rrweb-plugin-canvas-webrtc-record.cjs 37.6 kB
packages/plugins/rrweb-plugin-canvas-webrtc-record/dist/rrweb-plugin-canvas-webrtc-record.js 37.5 kB
packages/plugins/rrweb-plugin-canvas-webrtc-record/dist/rrweb-plugin-canvas-webrtc-record.umd.cjs 38.7 kB
packages/plugins/rrweb-plugin-canvas-webrtc-record/dist/rrweb-plugin-canvas-webrtc-record.umd.min.cjs 22.9 kB
packages/plugins/rrweb-plugin-canvas-webrtc-replay/dist/rrweb-plugin-canvas-webrtc-replay.cjs 34.3 kB
packages/plugins/rrweb-plugin-canvas-webrtc-replay/dist/rrweb-plugin-canvas-webrtc-replay.js 34.2 kB
packages/plugins/rrweb-plugin-canvas-webrtc-replay/dist/rrweb-plugin-canvas-webrtc-replay.umd.cjs 35.4 kB
packages/plugins/rrweb-plugin-canvas-webrtc-replay/dist/rrweb-plugin-canvas-webrtc-replay.umd.min.cjs 21.2 kB
packages/plugins/rrweb-plugin-console-record/dist/rrweb-plugin-console-record.cjs 15 kB
packages/plugins/rrweb-plugin-console-record/dist/rrweb-plugin-console-record.js 14.9 kB
packages/plugins/rrweb-plugin-console-record/dist/rrweb-plugin-console-record.umd.cjs 16.1 kB
packages/plugins/rrweb-plugin-console-record/dist/rrweb-plugin-console-record.umd.min.cjs 8.03 kB
packages/plugins/rrweb-plugin-console-replay/dist/rrweb-plugin-console-replay.cjs 5.01 kB
packages/plugins/rrweb-plugin-console-replay/dist/rrweb-plugin-console-replay.js 4.9 kB
packages/plugins/rrweb-plugin-console-replay/dist/rrweb-plugin-console-replay.umd.cjs 6.07 kB
packages/plugins/rrweb-plugin-console-replay/dist/rrweb-plugin-console-replay.umd.min.cjs 3.27 kB
packages/plugins/rrweb-plugin-sequential-id-record/dist/rrweb-plugin-sequential-id-record.cjs 681 B
packages/plugins/rrweb-plugin-sequential-id-record/dist/rrweb-plugin-sequential-id-record.js 548 B
packages/plugins/rrweb-plugin-sequential-id-record/dist/rrweb-plugin-sequential-id-record.umd.cjs 1.76 kB
packages/plugins/rrweb-plugin-sequential-id-record/dist/rrweb-plugin-sequential-id-record.umd.min.cjs 1.47 kB
packages/plugins/rrweb-plugin-sequential-id-replay/dist/rrweb-plugin-sequential-id-replay.cjs 933 B
packages/plugins/rrweb-plugin-sequential-id-replay/dist/rrweb-plugin-sequential-id-replay.js 820 B
packages/plugins/rrweb-plugin-sequential-id-replay/dist/rrweb-plugin-sequential-id-replay.umd.cjs 2.01 kB
packages/plugins/rrweb-plugin-sequential-id-replay/dist/rrweb-plugin-sequential-id-replay.umd.min.cjs 1.61 kB
packages/replay/dist/replay.cjs 388 kB
packages/replay/dist/replay.js 388 kB
packages/replay/dist/replay.umd.cjs 391 kB
packages/replay/dist/replay.umd.min.cjs 194 kB
packages/replay/dist/style.css 2.45 kB
packages/replay/dist/style.min.css 1.97 kB
packages/rrdom-nodejs/dist/rrdom-nodejs.cjs 132 kB
packages/rrdom-nodejs/dist/rrdom-nodejs.js 131 kB
packages/rrdom-nodejs/dist/rrdom-nodejs.umd.cjs 134 kB
packages/rrdom-nodejs/dist/rrdom-nodejs.umd.min.cjs 66.9 kB
packages/rrdom/dist/rrdom.cjs 150 kB
packages/rrdom/dist/rrdom.js 149 kB
packages/rrdom/dist/rrdom.umd.cjs 152 kB
packages/rrdom/dist/rrdom.umd.min.cjs 74.1 kB
packages/rrweb-player/dist/events.js 159 kB
packages/rrweb-player/dist/global.css 240 B
packages/rrweb-player/dist/rrweb-player.cjs 460 kB
packages/rrweb-player/dist/rrweb-player.js 460 kB
packages/rrweb-player/dist/rrweb-player.umd.cjs 463 kB
packages/rrweb-player/dist/rrweb-player.umd.min.cjs 223 kB
packages/rrweb-player/dist/style.css 5.57 kB
packages/rrweb-player/dist/style.min.css 5 kB
packages/rrweb/dist/style.css 2.45 kB
packages/rrweb/dist/style.min.css 1.97 kB
packages/types/dist/types.cjs 5.63 kB
packages/types/dist/types.js 5.38 kB
packages/types/dist/types.umd.cjs 6.66 kB
packages/types/dist/types.umd.min.cjs 3.41 kB
packages/utils/dist/utils.cjs 6.07 kB
packages/utils/dist/utils.js 5.57 kB
packages/utils/dist/utils.umd.cjs 7.1 kB
packages/utils/dist/utils.umd.min.cjs 3.98 kB

compressed-size-action

@pauldambra pauldambra merged commit 5fc8029 into main Jan 20, 2025
10 checks passed
@pauldambra pauldambra deleted the fix/style-sheet-domain branch January 20, 2025 22:30
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

1 participant