Skip to content

Commit

Permalink
fix: toolbar selector fangling (#20325)
Browse files Browse the repository at this point in the history
  • Loading branch information
pauldambra authored Feb 14, 2024
1 parent b675cad commit a33ded1
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 18 deletions.
6 changes: 3 additions & 3 deletions frontend/src/toolbar/elements/Elements.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import './Elements.scss'

import { useActions, useValues } from 'kea'
import { compactNumber } from 'lib/utils'
import React from 'react'
import { Fragment } from 'react'

import { ElementInfoWindow } from '~/toolbar/elements/ElementInfoWindow'
import { elementsLogic } from '~/toolbar/elements/elementsLogic'
Expand Down Expand Up @@ -75,7 +75,7 @@ export function Elements(): JSX.Element {

{heatmapElements.map(({ rect, count, clickCount, rageclickCount, element }, index) => {
return (
<React.Fragment key={`heatmap-${index}`}>
<Fragment key={`heatmap-${index}`}>
<HeatmapElement
rect={rect}
style={{
Expand Down Expand Up @@ -155,7 +155,7 @@ export function Elements(): JSX.Element {
{compactNumber(rageclickCount)}&#128545;
</HeatmapLabel>
)}
</React.Fragment>
</Fragment>
)
})}

Expand Down
7 changes: 5 additions & 2 deletions frontend/src/toolbar/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { finder } from '@medv/finder'
import { CLICK_TARGET_SELECTOR, CLICK_TARGETS, escapeRegex, TAGS_TO_IGNORE } from 'lib/actionUtils'
import { cssEscape } from 'lib/utils/cssEscape'
import { querySelectorAllDeep } from 'query-selector-shadow-dom'
import wildcardMatch from 'wildcard-match'

import { ActionStepForm, BoxColor, ElementRect } from '~/toolbar/types'
import { ActionStepType, StringMatching } from '~/types'
Expand Down Expand Up @@ -43,9 +42,13 @@ export function elementToQuery(element: HTMLElement, dataAttributes: string[]):

try {
return finder(element, {
attr: (name) => dataAttributes.some((dataAttribute) => wildcardMatch(dataAttribute)(name)),
tagName: (name) => !TAGS_TO_IGNORE.includes(name),
seedMinLength: 5, // include several selectors e.g. prefer .project-homepage > .project-header > .project-title over .project-title
attr: (name) => {
// preference to data attributes if they exist
// that aren't in the PostHog preferred list - they were returned early above
return name.startsWith('data-')
},
})
} catch (error) {
console.warn('Error while trying to find a selector for element', element, error)
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
"@dnd-kit/utilities": "^3.2.1",
"@floating-ui/react": "^0.16.0",
"@lottiefiles/react-lottie-player": "^3.4.7",
"@medv/finder": "^2.1.0",
"@medv/finder": "^3.1.0",
"@microlink/react-json-view": "^1.21.3",
"@monaco-editor/react": "4.4.6",
"@posthog/icons": "0.5.1",
Expand Down Expand Up @@ -173,7 +173,6 @@
"tailwindcss": "^3.4.0",
"use-debounce": "^9.0.3",
"use-resize-observer": "^8.0.0",
"wildcard-match": "^5.1.2",
"zxcvbn": "^4.4.2"
},
"devDependencies": {
Expand Down
15 changes: 4 additions & 11 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a33ded1

Please sign in to comment.