Skip to content

Commit

Permalink
🐛 ignore contenteditable elements for dead clicks
Browse files Browse the repository at this point in the history
  • Loading branch information
BenoitZugmeyer committed Jan 30, 2023
1 parent 5ad73a0 commit 8356e60
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ONE_SECOND } from '@datadog/browser-core'
import { ONE_SECOND, resetExperimentalFeatures, updateExperimentalFeatures } from '@datadog/browser-core'
import { FrustrationType } from '../../../rawRumEvent.types'
import type { Clock } from '../../../../../core/test/specHelper'
import { mockClock } from '../../../../../core/test/specHelper'
Expand Down Expand Up @@ -137,10 +137,12 @@ describe('isDead', () => {

beforeEach(() => {
isolatedDom = createIsolatedDom()
updateExperimentalFeatures(['dead_click_fixes'])
})

afterEach(() => {
isolatedDom.clear()
resetExperimentalFeatures()
})

it('considers as dead when the click has no page activity', () => {
Expand All @@ -164,6 +166,8 @@ describe('isDead', () => {
{ element: '<a id="foo">Foo</a>', expected: true },
{ element: '<a href="foo">Foo</a>', expected: false },
{ element: '<a href="foo">Foo<span target>bar</span></a>', expected: false },
{ element: '<div contenteditable>Foo bar</div>', expected: false },
{ element: '<div contenteditable>Foo<span target>bar</span></div>', expected: false },
]) {
it(`does not consider as dead when the click target is ${element}`, () => {
expect(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { elementMatches, ONE_SECOND } from '@datadog/browser-core'
import { elementMatches, isExperimentalFeatureEnabled, ONE_SECOND } from '@datadog/browser-core'
import { FrustrationType } from '../../../rawRumEvent.types'
import type { Click } from './trackClickActions'

Expand Down Expand Up @@ -64,5 +64,11 @@ export function isDead(click: Click) {
if (click.hasPageActivity || click.getUserActivity().input) {
return false
}
return !elementMatches(click.event.target, DEAD_CLICK_EXCLUDE_SELECTOR)
return !elementMatches(
click.event.target,
isExperimentalFeatureEnabled('dead_click_fixes')
? // contenteditable and their descendants don't always trigger meaningful changes when manipulated
`${DEAD_CLICK_EXCLUDE_SELECTOR},[contenteditable],[contenteditable] *`
: DEAD_CLICK_EXCLUDE_SELECTOR
)
}

0 comments on commit 8356e60

Please sign in to comment.