-
Notifications
You must be signed in to change notification settings - Fork 208
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
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
📝 No Changeset FoundThis PR doesn't include a changeset. A changeset (and the release label) is required to release a new version. How to add a changesetRun this command and follow the prompts: pnpm changesetRemember: Never use |
This stack of pull requests is managed by Graphite. Learn more about stacking. |
|
Size Change: 0 B Total Size: 4.86 MB ℹ️ View Unchanged
|
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.
2 files reviewed, 3 comments
| 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> | ||
| ) | ||
| } |
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: 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.| const observerOptions = useMemo( | ||
| () => ({ | ||
| threshold: 0.1, | ||
| ...options, | ||
| }), | ||
| // eslint-disable-next-line react-hooks/exhaustive-deps | ||
| [options?.threshold, options?.root, options?.rootMargin] | ||
| ) |
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: 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.| }: { | ||
| children: React.ReactNode | ||
| onIntersect: (entry: IntersectionObserverEntry) => void | ||
| onClick?: MouseEventHandler<HTMLDivElement> |
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: 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.bf050dc to
7dd3ef8
Compare
e4f12fb to
7caa257
Compare
7caa257 to
e00ce28
Compare
7dd3ef8 to
465f7e2
Compare
e00ce28 to
bee42de
Compare
Merge activity
|

#2504 had weird unrelated build errors, let's split it up
i know i need to reuse the visibility and click trackers that are hidden in PostHogFeature, so split them out