Repository navigation
🐛 Fix Session Replay of shadow DOM adoptedStyleSheets - #5119
Closed
cristihasna wants to merge 2 commits into
Closed
cristihasna wants to merge 2 commits into
cristihasna wants to merge 2 commits into
Conversation
|
All contributors have signed the CLA ✍️ ✅ |
Author
|
I have read the CLA Document and I hereby sign the CLA |
Contributor
|
Thank you for the PR, @cristihasna. The stylesheet ID issue you reported has been addressed in #5157. The other issue will be addressed soon. I'm going to close this PR in favor of those other PRs. |
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Motivation
Web components that style their shadow roots via constructed stylesheets
(
shadowRoot.adoptedStyleSheets, the default for Stencil and common with Lit) are replayedwithout styles or with another component's styles. Fixes #5117.
Two recorder issues:
serializeStyleSheetalways emittedAddStyleSheet(the playerassigns ids sequentially) but only allocated a recorder id for unseen sheets. When one
CSSStyleSheetis shared by several shadow roots, recorder and player ids diverge, and latershadow roots reference the wrong sheet.
adoptedStyleSheetswere only read when a node was firstserialized, so stylesheets adopted afterwards (e.g. lazy-loaded components adopting styles on
first render) were never recorded until the next full snapshot.
Changes
serializeStyleSheetreturns the existing id for already-serialized sheets and only emitsAddStyleSheetwhen a new id is allocated. This also avoids sending the same CSS repeatedly.#document/#shadow-rootare remembered in theRecordingScope(serializedAdoptedStyleSheets). At the end of each mutation batch they arecompared with the current
adoptedStyleSheets, and anAttachedStyleSheetschange is emittedwhen they differ. This covers both reassignment and in-place
push(). State is cleared onresetIds()(full snapshots) and when a shadow root's host is removed.serializeStyleSheets.ts.Known limitations (unchanged from before):
adoptedStyleSheetswith no subsequent DOM mutation is only recorded on the nextmutation batch.
insertRule/deleteRule/replace/replaceSync) are notrecorded. The
StyleSheetRulerecord references the owner node, which constructed sheets don'thave, so this would need a schema change.
This change was written with the help of an AI coding agent. I reviewed it, and verified it
against a local patch of
@datadog/browser-rum7.14.0 applied to an affected application.Test instructions
yarn test:unit --spec packages/browser-rum/src/domain/record/trackers/trackMutation.spec.ts --spec packages/browser-rum/src/domain/record/serialization/serializeNode.stylesheet.spec.tsyarn test:e2e -g "recorder with shadow DOM"stylesheet, plus one element adopting its stylesheet asynchronously, record a session and
check that every shadow root is styled correctly in the replay.
Checklist