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

🐛 [RUM-2280] fix duplicated mutations when using Shadow DOM #2527

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions packages/rum/src/domain/record/record.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,22 @@ describe('record', () => {
expect(innerMutationData.isChecked).toBe(true)
})

it('should record the change event inside a shadow root only once, regardless if the DOM is serialized multiple times', () => {
Copy link
Member Author

Choose a reason for hiding this comment

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

This test is on input events, as it is easier to test. Mutations are asynchronous and since the original "Shadow Root Controller" was replaced by a new one, calling flushMutations() did not flush both of them.

Anyway, one test should be enough to avoid regression.

const radio = appendElement('<input type="radio"/>', createShadow()) as HTMLInputElement
startRecording()

recordApi.takeSubsequentFullSnapshot()

radio.checked = true
radio.dispatchEvent(createNewEvent('change', { target: radio, composed: false }))

const inputRecords = getEmittedRecords().filter(
(record) => record.type === RecordType.IncrementalSnapshot && record.data.source === IncrementalSource.Input
)

expect(inputRecords.length).toBe(1)
})

it('should clean the state once the shadow dom is removed to avoid memory leak', () => {
const shadowRoot = createShadow()
appendElement('<div class="toto"></div>', shadowRoot)
Expand Down
3 changes: 3 additions & 0 deletions packages/rum/src/domain/record/shadowRootsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ export const initShadowRootsController = (

const shadowRootsController: ShadowRootsController = {
addShadowRoot: (shadowRoot: ShadowRoot) => {
if (controllerByShadowRoot.has(shadowRoot)) {
return
}
const { stop: stopMutationObserver, flush } = initMutationObserver(
mutationCb,
configuration,
Expand Down