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(replay): Fix potential broken CSS in styled-components #9234

Merged
merged 4 commits into from Oct 13, 2023

Conversation

billyvg
Copy link
Member

@billyvg billyvg commented Oct 12, 2023

Fixes an issue where the Replay integration can potentially break applications that use styled-components. styled-components relies on an exception being throw for CSS rules that are not supported by the browser engine. However, our SDK suppressed any exceptions thrown from within rrweb, so styled-components assumes that an unsupported rule was inserted successfully and increases a rule index, which causes following inserted rules to fail due to an out-of-bounds error.

This was a regression from v1 as we were always re-throwing the exception

Fixes #9170

@billyvg billyvg marked this pull request as ready for review October 12, 2023 18:28
@github-actions
Copy link
Contributor

github-actions bot commented Oct 12, 2023

size-limit report 📦

Path Size
@sentry/browser (incl. Tracing, Replay) - Webpack (gzipped) 84.26 KB (-0.01% 🔽)
@sentry/browser (incl. Tracing) - Webpack (gzipped) 31.43 KB (0%)
@sentry/browser - Webpack (gzipped) 22.02 KB (0%)
@sentry/browser (incl. Tracing, Replay) - ES6 CDN Bundle (gzipped) 78.78 KB (-0.01% 🔽)
@sentry/browser (incl. Tracing) - ES6 CDN Bundle (gzipped) 28.61 KB (0%)
@sentry/browser - ES6 CDN Bundle (gzipped) 21.02 KB (-0.01% 🔽)
@sentry/browser (incl. Tracing, Replay) - ES6 CDN Bundle (minified & uncompressed) 254.48 KB (-0.01% 🔽)
@sentry/browser (incl. Tracing) - ES6 CDN Bundle (minified & uncompressed) 86.76 KB (0%)
@sentry/browser - ES6 CDN Bundle (minified & uncompressed) 62.45 KB (0%)
@sentry/browser (incl. Tracing) - ES5 CDN Bundle (gzipped) 31.48 KB (-0.01% 🔽)
@sentry/react (incl. Tracing, Replay) - Webpack (gzipped) 84.29 KB (-0.01% 🔽)
@sentry/react - Webpack (gzipped) 22.06 KB (0%)
@sentry/nextjs Client (incl. Tracing, Replay) - Webpack (gzipped) 102.2 KB (-0.01% 🔽)
@sentry/nextjs Client - Webpack (gzipped) 50.96 KB (0%)

packages/replay/src/integration.ts Outdated Show resolved Hide resolved
@AbhiPrasad
Copy link
Member

We can do a release tomorrow with this.

// return true to suppress throwing the error inside of rrweb
return true;
errorHandler: (err: Error & {__rrweb__?: boolean}) => {
err.__rrweb__ = true;
Copy link
Member

Choose a reason for hiding this comment

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

Hmmm so one problem here is that we may throw/error on trying to set this on something that is e.g. frozen or similar. Can we instead still try-catch here and just re-throw certain kinds of exceptions, maybe?

I mean, maybe this is actually fine, but we could be getting other errors because of this, at some point, too 🤔

Copy link
Member

Choose a reason for hiding this comment

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

Or actually, can we just do:

errorHandler: (err: Error) => {
  try {
    // @ts-expect-error Set this so that replay SDK can ignore errors originating from rrweb
    err.__rrweb__ = true;
  } catch {
    // avoid any potential hazards here
  }

So still try-catch setting this prop, but bubble the error up to rrweb 🤔

Copy link
Member

Choose a reason for hiding this comment

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

I updated this like this, so we can merge & release this!

billyvg and others added 4 commits October 13, 2023 10:12
NOTE: This requires a bump to rrweb library

Fixes an issue where the Replay integration can potentially break applications that use `styled-components`. `styled-components` [relies on an exception being throw](https://github.com/styled-components/styled-components/blob/b7b374bb1ceff1699f7035b15881bc807110199a/packages/styled-components/src/sheet/Tag.ts#L32-L40) for CSS rules that are not supported by the browser engine. However, our SDK suppresses any exceptions thrown from within rrweb, so `styled-components` assumes that an unsupported rule was inserted successfully and increases a rule index, which causes following inserted rules to fail due to an out-of-bounds error.

getsentry/rrweb#111 introduces a change the adds metadata to exceptions that occur when calling `insertRule`, and this PR will re-throw those exceptions that will then bubble up to `styled-components`.

Fixes #9170
@mydea mydea force-pushed the fix-replay-fix-catching-exceptions-from-insertRule branch from b1876c5 to a66168f Compare October 13, 2023 08:16
@mydea mydea merged commit 73a808a into develop Oct 13, 2023
79 checks passed
@mydea mydea deleted the fix-replay-fix-catching-exceptions-from-insertRule branch October 13, 2023 09:14
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.

Sentry 7.73.0 causes styled-components to fail to render with styles/CSS
3 participants