Skip to content
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import React, { MouseEventHandler, useEffect, useMemo, useRef } from 'react'
import { isNull } from '../../utils/type-utils'

/**
* VisibilityAndClickTracker is an internal component,
* its API might change without warning and without being signalled as a breaking change
*
*/
export function VisibilityAndClickTracker({
children,
onIntersect,
onClick,
trackView,
options,
...props
}: {
children: React.ReactNode
onIntersect: (entry: IntersectionObserverEntry) => void
onClick?: MouseEventHandler<HTMLDivElement>
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: onClick is optional here but required in the original PostHogFeature.tsx:99. This API inconsistency could lead to bugs when these components are actually used.

Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/react/src/components/internal/VisibilityAndClickTracker.tsx
Line: 19:19

Comment:
**logic:** `onClick` is optional here but required in the original `PostHogFeature.tsx:99`. This API inconsistency could lead to bugs when these components are actually used.

How can I resolve this? If you propose a fix, please make it concise.

trackView: boolean
options?: IntersectionObserverInit
}): JSX.Element {
const ref = useRef<HTMLDivElement>(null)

const observerOptions = useMemo(
() => ({
threshold: 0.1,
...options,
}),
// eslint-disable-next-line react-hooks/exhaustive-deps
[options?.threshold, options?.root, options?.rootMargin]
)
Comment on lines +25 to +32
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: The useMemo dependency array is incomplete. The original in PostHogFeature.tsx:106-116 uses a different pattern without useMemo, passing options directly to IntersectionObserver.

This useMemo approach could cause issues - if other properties of options change (not just threshold/root/rootMargin), the observer won't be recreated because observerOptions won't change.

Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/react/src/components/internal/VisibilityAndClickTracker.tsx
Line: 25:32

Comment:
**logic:** The `useMemo` dependency array is incomplete. The original in `PostHogFeature.tsx:106-116` uses a different pattern without `useMemo`, passing options directly to `IntersectionObserver`.

This `useMemo` approach could cause issues - if other properties of `options` change (not just threshold/root/rootMargin), the observer won't be recreated because `observerOptions` won't change.

How can I resolve this? If you propose a fix, please make it concise.


useEffect(() => {
if (isNull(ref.current) || !trackView) return

// eslint-disable-next-line compat/compat
const observer = new IntersectionObserver(([entry]) => onIntersect(entry), observerOptions)
observer.observe(ref.current)
return () => observer.disconnect()
}, [observerOptions, trackView, onIntersect])

return (
<div ref={ref} {...props} onClick={onClick}>
{children}
</div>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import React, { MouseEventHandler, useEffect, useMemo, useRef } from 'react'
import { isNull } from '../../utils/type-utils'

/**
* VisibilityAndClickTracker is an internal component,
* its API might change without warning and without being signalled as a breaking change
*
*/
export function VisibilityAndClickTracker({
children,
onIntersect,
onClick,
trackView,
options,
...props
}: {
children: React.ReactNode
onIntersect: (entry: IntersectionObserverEntry) => void
onClick?: MouseEventHandler<HTMLDivElement>
trackView: boolean
options?: IntersectionObserverInit
}): JSX.Element {
const ref = useRef<HTMLDivElement>(null)

const observerOptions = useMemo(
() => ({
threshold: 0.1,
...options,
}),
// eslint-disable-next-line react-hooks/exhaustive-deps
[options?.threshold, options?.root, options?.rootMargin]
)

useEffect(() => {
if (isNull(ref.current) || !trackView) return

// eslint-disable-next-line compat/compat
const observer = new IntersectionObserver(([entry]) => onIntersect(entry), observerOptions)
observer.observe(ref.current)
return () => observer.disconnect()
}, [observerOptions, trackView, onIntersect])

return (
<div ref={ref} {...props} onClick={onClick}>
{children}
</div>
)
}
Comment on lines +1 to +48
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: This file is a duplicate of VisibilityAndClickTracker.tsx (singular). Both files contain identical code. One should be deleted.

Based on PostHogFeature.tsx, there should be TWO different components:

  • VisibilityAndClickTracker (inner/simpler component)
  • VisibilityAndClickTrackers (outer wrapper with flag tracking)

Currently both files export the same simpler component.

Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/react/src/components/internal/VisibilityAndClickTrackers.tsx
Line: 1:48

Comment:
**logic:** This file is a duplicate of `VisibilityAndClickTracker.tsx` (singular). Both files contain identical code. One should be deleted.

Based on `PostHogFeature.tsx`, there should be TWO different components:
- `VisibilityAndClickTracker` (inner/simpler component)  
- `VisibilityAndClickTrackers` (outer wrapper with flag tracking)

Currently both files export the same simpler component.

How can I resolve this? If you propose a fix, please make it concise.

Loading