mirror of
https://github.com/hanzoai/next.js.git
synced 2026-10-30 14:46:38 +00:00
This reverts commit 7f677d1. Cannot reproduce the `vercel-site` failure
cited in #68176, and there's no apparent reason why this PR would cause
that
44 lines
963 B
JavaScript
44 lines
963 B
JavaScript
'use client'
|
|
import Image from 'next/image'
|
|
import { useCallback, useEffect, useState } from 'react'
|
|
|
|
export default function Home() {
|
|
const [displayImage, setDisplayImage] = useState(true)
|
|
|
|
const refWithCleanup = useCallback((el) => {
|
|
if (!el) {
|
|
throw new Error(
|
|
'callback refs that returned a cleanup should never be called with null'
|
|
)
|
|
}
|
|
|
|
return () => {
|
|
console.log('callback ref was cleaned up')
|
|
}
|
|
}, [])
|
|
|
|
useEffect(() => {
|
|
setDisplayImage(false)
|
|
}, [])
|
|
|
|
return (
|
|
<main>
|
|
<h1>Should call ref cleanup on unmount</h1>
|
|
<section>
|
|
{displayImage ? (
|
|
<div style={{ position: 'relative', width: 10, height: 10 }}>
|
|
<Image
|
|
ref={refWithCleanup}
|
|
priority
|
|
fill
|
|
src="/test.jpg"
|
|
alt="alt"
|
|
sizes="10px"
|
|
/>
|
|
</div>
|
|
) : null}
|
|
</section>
|
|
</main>
|
|
)
|
|
}
|