-
Notifications
You must be signed in to change notification settings - Fork 212
chore: rearrange things for re-use within the react SDK #2515
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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] | ||
| ) | ||
|
Comment on lines
+25
to
+32
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. logic: The This Prompt To Fix With AIThis 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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. logic: This file is a duplicate of Based on
Currently both files export the same simpler component. Prompt To Fix With AIThis 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. |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic:
onClickis optional here but required in the originalPostHogFeature.tsx:99. This API inconsistency could lead to bugs when these components are actually used.Prompt To Fix With AI