Skip to content

Commit

Permalink
🐛 [REPLAY-312] use unpatched MutationObserver object (#866)
Browse files Browse the repository at this point in the history
  • Loading branch information
BenoitZugmeyer authored May 27, 2021
1 parent 4b7f047 commit 468d3d4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
4 changes: 2 additions & 2 deletions packages/rum-core/src/browser/domMutationCollection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ interface BrowserWindow extends Window {
}
}

function getMutationObserverConstructor(): MutationObserverConstructor | undefined {
export function getMutationObserverConstructor(): MutationObserverConstructor | undefined {
let constructor: MutationObserverConstructor | undefined
const browserWindow: BrowserWindow = window

// Angular uses Zone.js to provide a context persisting accross async tasks. Zone.js replaces the
// Angular uses Zone.js to provide a context persisting across async tasks. Zone.js replaces the
// global MutationObserver constructor with a patched version to support the context propagation.
// There is an ongoing issue[1][2] with this setup when using a MutationObserver within a Angular
// component: on some occasions, the callback is being called in an infinite loop, causing the
Expand Down
1 change: 1 addition & 0 deletions packages/rum-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ export { startRum } from './boot/rum'
export { LifeCycle, LifeCycleEventType } from './domain/lifeCycle'
export { ParentContexts } from './domain/parentContexts'
export { RumSession } from './domain/rumSession'
export { getMutationObserverConstructor } from './browser/domMutationCollection'
7 changes: 6 additions & 1 deletion packages/rum-recorder/src/domain/record/mutationObserver.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { monitor } from '@datadog/browser-core'
import { monitor, noop } from '@datadog/browser-core'
import { getMutationObserverConstructor } from '@datadog/browser-rum-core'
import { getNodeOrAncestorsInputPrivacyMode, nodeOrAncestorsShouldBeHidden } from './privacy'
import {
getElementInputValue,
Expand Down Expand Up @@ -29,6 +30,10 @@ type WithSerializedTarget<T> = T & { target: NodeWithSerializedNode }
* Buffers and aggregate mutations generated by a MutationObserver into MutationPayload
*/
export function startMutationObserver(controller: MutationController, mutationCallback: MutationCallBack) {
const MutationObserver = getMutationObserverConstructor()
if (!MutationObserver) {
return { stop: noop }
}
const mutationBatch = createMutationBatch((mutations) => {
processMutations(mutations.concat(observer.takeRecords() as RumMutationRecord[]), mutationCallback)
})
Expand Down

0 comments on commit 468d3d4

Please sign in to comment.