Skip to content

Commit 12062ac

Browse files
committed
changed 'rootEl' to 'lazyBoundary' and its type as well
1 parent 132fdbb commit 12062ac

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

packages/next/client/image.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,7 @@ export type ImageProps = Omit<
101101
quality?: number | string
102102
priority?: boolean
103103
loading?: LoadingValue
104-
//added 'rootEl' property of type HTMLElement, nullable for being able to set default value to null (see Below)
105-
rootEl?: HTMLElement | null
104+
lazyRoot?: React.RefObject<HTMLElement> | null
106105
lazyBoundary?: string
107106
placeholder?: PlaceholderValue
108107
blurDataURL?: string
@@ -317,7 +316,7 @@ export default function Image({
317316
unoptimized = false,
318317
priority = false,
319318
loading,
320-
rootEl = null, //setting to null for the Intersection Observer API to set html root element as 'root' by default
319+
lazyRoot = null,
321320
lazyBoundary = '200px',
322321
className,
323322
quality,
@@ -508,8 +507,7 @@ export default function Image({
508507
}
509508

510509
const [setRef, isIntersected] = useIntersection<HTMLImageElement>({
511-
//added 'root' to Options
512-
root: rootEl,
510+
root: lazyRoot?.current,
513511
rootMargin: lazyBoundary,
514512
disabled: !isLazy,
515513
})

packages/next/client/use-intersection.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
type UseIntersectionObserverInit = Pick<
88
IntersectionObserverInit,
99
'rootMargin' | 'root'
10-
> //added 'root' as a property
10+
>
1111

1212
type UseIntersection = { disabled?: boolean } & UseIntersectionObserverInit
1313
type ObserveCallback = (isVisible: boolean) => void
@@ -20,7 +20,6 @@ type Observer = {
2020
const hasIntersectionObserver = typeof IntersectionObserver !== 'undefined'
2121

2222
export function useIntersection<T extends Element>({
23-
//added 'root' as an option
2423
root,
2524
rootMargin,
2625
disabled,
@@ -43,11 +42,11 @@ export function useIntersection<T extends Element>({
4342
unobserve.current = observe(
4443
el,
4544
(isVisible) => isVisible && setVisible(isVisible),
46-
{ root, rootMargin } //added 'root' as an option
45+
{ root, rootMargin }
4746
)
4847
}
4948
},
50-
[isDisabled, root, rootMargin, visible] //added 'root' as a dependency
49+
[isDisabled, root, rootMargin, visible]
5150
)
5251

5352
useEffect(() => {

0 commit comments

Comments
 (0)