Skip to content

Commit 042553c

Browse files
committed
fix(replay): Fix potential broken CSS in styled-components
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
1 parent e507110 commit 042553c

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

packages/replay/src/integration.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,14 @@ export class Replay implements Integration {
145145
// collect fonts, but be aware that `sentry.io` needs to be an allowed
146146
// origin for playback
147147
collectFonts: true,
148-
errorHandler: (err: Error) => {
148+
errorHandler: (err: Error & {__rrweb__?: boolean, __source__?: string}) => {
149149
try {
150-
// @ts-expect-error Set this so that replay SDK can ignore errors originating from rrweb
151150
err.__rrweb__ = true;
151+
152+
// Re-throw as styled-components relies on thrown exception when CSS rule fails to be inserted.
153+
if (err.__source__ === 'CSSStyleSheet.insertRule') {
154+
throw err;
155+
}
152156
} catch {
153157
// avoid any potential hazards here
154158
}

0 commit comments

Comments
 (0)