Skip to content

Commit 3fd5d98

Browse files
authored
Revert "Add lazyRoot optional property to next/image component (vercel#33290)"
This reverts commit 7452c0b.
1 parent b72eeae commit 3fd5d98

File tree

6 files changed

+5
-121
lines changed

6 files changed

+5
-121
lines changed

docs/api-reference/next/image.md

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ description: Enable Image Optimization with the built-in Image component.
1616

1717
| Version | Changes |
1818
| --------- | ------------------------------------------------------------------------------------------------- |
19-
| `v12.0.9` | `lazyRoot` prop added |
2019
| `v12.0.0` | `formats` configuration added.<br/>AVIF support added.<br/>Wrapper `<div>` changed to `<span>`. |
2120
| `v11.1.0` | `onLoadingComplete` and `lazyBoundary` props added. |
2221
| `v11.0.0` | `src` prop support for static import.<br/>`placeholder` prop added.<br/>`blurDataURL` prop added. |
@@ -222,12 +221,6 @@ A string (with similar syntax to the margin property) that acts as the bounding
222221

223222
[Learn more](https://developer.mozilla.org/en-US/docs/Web/API/IntersectionObserver/rootMargin)
224223

225-
### lazyRoot
226-
227-
A React [Ref](https://reactjs.org/docs/refs-and-the-dom.html) pointing to the Element which the [lazyBoundary](#lazyBoundary) calculates for the Intersection detection. Defaults to `null`, referring to the document viewport.
228-
229-
[Learn more](https://developer.mozilla.org/en-US/docs/Web/API/IntersectionObserver/root)
230-
231224
### unoptimized
232225

233226
When true, the source image will be served as-is instead of changing quality,

packages/next/client/image.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ export type ImageProps = Omit<
101101
quality?: number | string
102102
priority?: boolean
103103
loading?: LoadingValue
104-
lazyRoot?: React.RefObject<HTMLElement> | null
105104
lazyBoundary?: string
106105
placeholder?: PlaceholderValue
107106
blurDataURL?: string
@@ -322,7 +321,6 @@ export default function Image({
322321
unoptimized = false,
323322
priority = false,
324323
loading,
325-
lazyRoot = null,
326324
lazyBoundary = '200px',
327325
className,
328326
quality,
@@ -514,7 +512,6 @@ export default function Image({
514512
}
515513

516514
const [setIntersection, isIntersected] = useIntersection<HTMLImageElement>({
517-
rootRef: lazyRoot,
518515
rootMargin: lazyBoundary,
519516
disabled: !isLazy,
520517
})

packages/next/client/use-intersection.tsx

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,8 @@ import {
44
cancelIdleCallback,
55
} from './request-idle-callback'
66

7-
type UseIntersectionObserverInit = Pick<
8-
IntersectionObserverInit,
9-
'rootMargin' | 'root'
10-
>
11-
12-
type UseIntersection = { disabled?: boolean } & UseIntersectionObserverInit & {
13-
rootRef?: React.RefObject<HTMLElement> | null
14-
}
7+
type UseIntersectionObserverInit = Pick<IntersectionObserverInit, 'rootMargin'>
8+
type UseIntersection = { disabled?: boolean } & UseIntersectionObserverInit
159
type ObserveCallback = (isVisible: boolean) => void
1610
type Observer = {
1711
id: string
@@ -22,15 +16,14 @@ type Observer = {
2216
const hasIntersectionObserver = typeof IntersectionObserver !== 'undefined'
2317

2418
export function useIntersection<T extends Element>({
25-
rootRef,
2619
rootMargin,
2720
disabled,
2821
}: UseIntersection): [(element: T | null) => void, boolean] {
2922
const isDisabled: boolean = disabled || !hasIntersectionObserver
3023

3124
const unobserve = useRef<Function>()
3225
const [visible, setVisible] = useState(false)
33-
const [root, setRoot] = useState(rootRef ? rootRef.current : null)
26+
3427
const setRef = useCallback(
3528
(el: T | null) => {
3629
if (unobserve.current) {
@@ -44,11 +37,11 @@ export function useIntersection<T extends Element>({
4437
unobserve.current = observe(
4538
el,
4639
(isVisible) => isVisible && setVisible(isVisible),
47-
{ root, rootMargin }
40+
{ rootMargin }
4841
)
4942
}
5043
},
51-
[isDisabled, root, rootMargin, visible]
44+
[isDisabled, rootMargin, visible]
5245
)
5346

5447
useEffect(() => {
@@ -60,9 +53,6 @@ export function useIntersection<T extends Element>({
6053
}
6154
}, [visible])
6255

63-
useEffect(() => {
64-
if (rootRef) setRoot(rootRef.current)
65-
}, [rootRef])
6656
return [setRef, visible]
6757
}
6858

test/integration/image-component/default/pages/lazy-noref.js

Lines changed: 0 additions & 32 deletions
This file was deleted.

test/integration/image-component/default/pages/lazy-withref.js

Lines changed: 0 additions & 33 deletions
This file was deleted.

test/integration/image-component/default/test/index.test.js

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,37 +1008,6 @@ function runTests(mode) {
10081008
}
10091009
}
10101010
})
1011-
1012-
it('should load the image when the lazyRoot prop is used', async () => {
1013-
let browser
1014-
try {
1015-
//trying on '/lazy-noref' it fails
1016-
browser = await webdriver(appPort, '/lazy-withref')
1017-
1018-
await check(async () => {
1019-
const result = await browser.eval(
1020-
`document.getElementById('myImage').naturalWidth`
1021-
)
1022-
1023-
if (result < 400) {
1024-
throw new Error('Incorrectly loaded image')
1025-
}
1026-
1027-
return 'result-correct'
1028-
}, /result-correct/)
1029-
1030-
expect(
1031-
await hasImageMatchingUrl(
1032-
browser,
1033-
`http://localhost:${appPort}/_next/image?url=%2Ftest.jpg&w=828&q=75`
1034-
)
1035-
).toBe(true)
1036-
} finally {
1037-
if (browser) {
1038-
await browser.close()
1039-
}
1040-
}
1041-
})
10421011
}
10431012

10441013
describe('Image Component Tests', () => {

0 commit comments

Comments
 (0)