Skip to content

Commit

Permalink
🐛 [RUM-2280] fix duplicated mutations when using Shadow DOM
Browse files Browse the repository at this point in the history
  • Loading branch information
BenoitZugmeyer committed Dec 11, 2023
1 parent f611ff5 commit db65956
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
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', () => {
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

0 comments on commit db65956

Please sign in to comment.