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

feat: Add build flags to allow noop iframe/canvas/shadow dom managers #114

Merged
merged 3 commits into from Oct 18, 2023

Conversation

mydea
Copy link
Member

@mydea mydea commented Oct 17, 2023

This PR adds 3 new build flags to rrweb:

  • __RRWEB_EXCLUDE_CANVAS__
  • __RRWEB_EXCLUDE_SHADOW_DOM__
  • __RRWEB_EXCLUDE_IFRAME__

If you set these to true at build time, it will replace the regular ShadowDomManager / CanvasManager / IframeManager with a noop variant of these managers.

All of these together shave off about 8 KB gzipped from our replay bundles, if set to true.

For now, we'll probably keep this enabled by default, but at least we have a path for users to shake this out if they don't need these features.

Note: I played with some other approaches, e.g. instead of having the noop class make these e.g. iframeManager: IframeManager | undefined, but I think overall the code to guard against using this everywhere ends up being a similar amount of bytes, plus we need to spread this much more through the codebase, making rebasing on upstream master etc. potentially harder. This way, IMHO it should be the easiest way to keep this as contained as possible.

Note 2: In scenarios where you do not set the build flags at all (so neither to true or false), this will actually slightly increase the bundle size 😬 but it's a very tiny increase which is OK I'd say.

@mydea mydea self-assigned this Oct 17, 2023
@mydea
Copy link
Member Author

mydea commented Oct 17, 2023

PR to implement this in replay: getsentry/sentry-javascript#9274

Copy link
Member

@Lms24 Lms24 left a comment

Choose a reason for hiding this comment

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

Great change!

Copy link
Member

@Lms24 Lms24 left a comment

Choose a reason for hiding this comment

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

For now, we'll probably keep this enabled by default, but at least we have a path for users to shake this out if they don't need these features

I think this is a good approach. This means it works like our other tree shaking flags and users can opt out in the same way. Easier documentation and more consistency across our packages 👍

@mydea mydea merged commit d051b3c into sentry-v2 Oct 18, 2023
13 checks passed
@mydea mydea deleted the fn/allow-noop branch October 18, 2023 08:43
mydea added a commit to getsentry/sentry-javascript that referenced this pull request Oct 19, 2023
This depends on getsentry/rrweb#114 to be merged
first, but allows to configure build time flags to shake out certain
rrweb features that may not be used.

It also adds a size limit entry that shows the total bundle size with
everything that can be shaken out removed, incl. debug stuff. Bundle
size is about ~11kb gzipped less in this scenario, which is not bad.
billyvg pushed a commit that referenced this pull request Oct 20, 2023
…#114)

This PR adds 3 new build flags to rrweb:

* `__RRWEB_EXCLUDE_CANVAS__`
* `__RRWEB_EXCLUDE_SHADOW_DOM__`
* `__RRWEB_EXCLUDE_IFRAME__`

If you set these to `true` at build time, it will replace the regular
`ShadowDomManager` / `CanvasManager` / `IframeManager` with a noop
variant of these managers.

All of these together shave off about 8 KB gzipped from our replay
bundles, if set to `true`.

For now, we'll probably keep this enabled by default, but at least we
have a path for users to shake this out if they don't need these
features.

Note: I played with some other approaches, e.g. instead of having the
noop class make these e.g. `iframeManager: IframeManager | undefined`,
but I think overall the code to guard against using this everywhere ends
up being a similar amount of bytes, plus we need to spread this much
more through the codebase, making rebasing on upstream master etc.
potentially harder. This way, IMHO it should be the easiest way to keep
this as contained as possible.
billyvg pushed a commit that referenced this pull request Apr 26, 2024
…#114)

This PR adds 3 new build flags to rrweb:

* `__RRWEB_EXCLUDE_CANVAS__`
* `__RRWEB_EXCLUDE_SHADOW_DOM__`
* `__RRWEB_EXCLUDE_IFRAME__`

If you set these to `true` at build time, it will replace the regular
`ShadowDomManager` / `CanvasManager` / `IframeManager` with a noop
variant of these managers.

All of these together shave off about 8 KB gzipped from our replay
bundles, if set to `true`.

For now, we'll probably keep this enabled by default, but at least we
have a path for users to shake this out if they don't need these
features.

Note: I played with some other approaches, e.g. instead of having the
noop class make these e.g. `iframeManager: IframeManager | undefined`,
but I think overall the code to guard against using this everywhere ends
up being a similar amount of bytes, plus we need to spread this much
more through the codebase, making rebasing on upstream master etc.
potentially harder. This way, IMHO it should be the easiest way to keep
this as contained as possible.
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

5 participants