Repository navigation
fix(rrweb): Don't throw when tearing down a locked adoptedStyleSheets patch - #351
Merged
Merged
Conversation
… patch rrweb patches `adoptedStyleSheets` on each document and shadow root it records, copying `configurable` from the prototype. If the prototype's property was non-configurable, or another script locked our property (non-configurable redefine, `Object.seal`/`freeze`) during recording, cleanup threw `TypeError: Cannot redefine property: adoptedStyleSheets`. That aborted the rest of teardown and, in the Replay SDK, stopped the buffer-to-session restart. - Always install the patch as configurable, and remove it with `Reflect.deleteProperty`/`Reflect.defineProperty` instead of redefining it. - If it can't be removed, leave it behind as a pass-through and reuse it on the next recording. - Skip the patch if the host already has a non-configurable own property. - Run every teardown step in `record()` and `initObservers()` even if one throws, then rethrow the first error. Refs REPLAY-1019 Co-Authored-By: George Gritsouk <[email protected]>
gggritso
reviewed
Nov 5, 2026
gggritso
left a comment
Member
There was a problem hiding this comment.
Overall this makes sense but I have a lot of questions about the behaviour
Drop the per-host patch registry. Each observer keeps its own setter and a recording flag, and teardown removes the property only if it is still ours. If another script locked it meanwhile, it stays as a pass-through and later recordings skip the patch, as they do for any pre-existing lock. Also skip the patch when the host is sealed or frozen, explain why configurable: true is safe, rename callAllHandlers to runAllEvenIfOneThrows, keep the original hostId code, and drop the changeset, which this fork does not use for releases.
gggritso
reviewed
Nov 5, 2026
gggritso
left a comment
Member
There was a problem hiding this comment.
Starting to look good, a few more questions though
Rename runAllEvenIfOneThrows to runAllAndRethrowFirstError and pass record()'s final cleanup steps to it instead of wrapping it in try/finally. Rename the saved own descriptor and the patched setter so teardown's ownership check reads clearly, and write the configurable comment in the present tense. Replace the lock-parameterised test helper with one test per scenario that does its own setup and uses plain assertions. Shared recording helpers are installed in the page in beforeEach.
gggritso
reviewed
Nov 6, 2026
gggritso
left a comment
Member
There was a problem hiding this comment.
Looking good, just a few more tweaks needed before we can open this up
adoptedStyleSheets patch
…leSheets names runAll now runs every handler and returns the errors they threw. record()'s stop function and initObservers()'s cleanup rethrow the first one, so the SDK still sees the same failure as before. Rename the adoptedStyleSheets setter and active flag to say what they belong to, and reword the comments to name where each descriptor comes from and to say that the ownership check and the Reflect calls are there to be safe.
Member
|
@cursor review |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 4259a1e. Configure here.
gggritso
marked this pull request as ready for review
November 6, 2026 21:59
logaretm
approved these changes
Nov 9, 2026
gggritso
added a commit
to getsentry/sentry
that referenced
this pull request
Nov 12, 2026
…130930) Bumps the Sentry JavaScript SDK from 11.7.0 to [11.12.0](https://github.com/getsentry/sentry-javascript/releases/tag/11.12.0), mainly to pick up rrweb [2.46.0](https://github.com/getsentry/rrweb/releases/tag/2.46.0) (getsentry/sentry-javascript#26241). rrweb 2.46.0 fixes: - Clear leftover nodes when `document.open()` is skipped (getsentry/rrweb#350) - Don't record the default value of cleared inputs (getsentry/rrweb#349) - Keep adopted stylesheets on seek when their first host was removed (getsentry/rrweb#352) - Don't throw when tearing down a locked `adoptedStyleSheets` patch (getsentry/rrweb#351) Changes: - `@sentry/browser`, `@sentry/core`, `@sentry/node`, `@sentry/react`: 11.7.0 → 11.12.0 across `static/app`, `static/gsApp`, `static/gsAdmin`, `static/packages/scraps`, and `tests/js`. - `@sentry/rrweb`, `@sentry/rrweb-player`, `@sentry/rrweb-snapshot`: 2.45.0 → 2.46.0, so the replay player uses the same rrweb as the SDK. - `@sentry/rrweb-types`: 2.44.0 → 2.46.0. This drops the duplicate `@sentry/[email protected]` / `@sentry/[email protected]` entries from the lockfile. <!-- junior-request-attribution:start --> via **George Gritsouk**. <!-- junior-request-attribution:end --> <!-- junior-session-footer:start --> <!-- junior-conversation-id:slack%3AD0AR76A9F5G%3A1794502210.473359 --> Closes REPLAY-1029 Closes REPLAY-1019 -- [View Session](https://junior-prod.sentry.dev/conversations/slack%3AD0AR76A9F5G%3A1794502210.473359) [[Sentry]](https://sentry.sentry.io/explore/conversations/slack%3AD0AR76A9F5G%3A1794502210.473359/?project=4510944073809921) <!-- junior-session-footer:end --> Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com> Co-authored-by: George Gritsouk <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
rrweb patches
adoptedStyleSheetson every document so that it can capture dynamically added stylesheets. Setup copiedconfigurablefrom the currentadoptedStyleSheetsproperty, and teardown redefined the property. Teardown throwsTypeError: Cannot redefine property: adoptedStyleSheetsin two cases:adoptedStyleSheetsproperty was already non-configurable, so our own property started out locked (maybe an extension caused this), orObject.seal/Object.freezeondocument).When it throws, the rest of teardown is skipped. In the Replay SDK this happens inside
sendBufferedReplayOrFlush→stopRecording(), so the buffered replay never restarts in session mode, and we lose everything after the error.This PR makes a few changes.
Firstly, the
adoptedStyleSheetspatch is now marked asconfigurable: truewhich means it's always safe for us to remove the patch that we ourselves added. There is also a bit of checking to make sure that we are able to setadoptedStyleSheetsback to what it was before we tampered with it. UsingReflect.fails quietly instead of erroring out.Secondly, the teardown process is now a bit safer to run. If there's an exception thrown during one of the steps, the other steps still run.
I think it might be good for us to add some telemetry around this, but I'm not confident what it would be yet, so I left it out. I also think this might be a worthy upstream into
rrweb, but I'm not sure about that either.Closes REPLAY-1019
--
View Session [Sentry]