Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@
},
"peerDependencies": {
"@srcset/runtime": "workspace:^",
"react": ">=19",
"react-dom": ">=19"
"react": ">=19"
},
"devDependencies": {
"@size-limit/preset-small-lib": "^12.0.0",
Expand Down
22 changes: 1 addition & 21 deletions packages/react/src/Image.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,12 @@ import {
fireEvent
} from '@testing-library/react'
import { createRef } from 'react'
import type * as ReactDomModule from 'react-dom'
import { preload } from 'react-dom'
import { Image } from './Image.tsx'
import {
createSrc,
createSrcSet
} from '../test/src.mock.ts'

vi.mock('react-dom', async (importOriginal) => {
const original = await importOriginal<typeof ReactDomModule>()

return {
...original,
preload: vi.fn()
}
})

describe('react', () => {
describe('Image', () => {
it('should render img from variant with intrinsic size', () => {
Expand Down Expand Up @@ -119,7 +108,7 @@ describe('react', () => {
expect(image).toHaveAttribute('decoding', 'async')
})

it('should load eagerly with high priority and preload', () => {
it('should load eagerly with high priority', () => {
render(
<Image
alt='photo'
Expand All @@ -136,15 +125,6 @@ describe('react', () => {

expect(image).toHaveAttribute('loading', 'eager')
expect(image).toHaveAttribute('fetchpriority', 'high')
expect(preload).toHaveBeenCalledWith('/images/image@640w.jpg', {
as: 'image',
type: 'image/jpeg',
fetchPriority: 'high',
imageSrcSet: '/images/image@320w.jpg 320w, /images/image@640w.jpg 640w',
imageSizes: '100vw',
crossOrigin: 'anonymous',
referrerPolicy: 'no-referrer'
})
})

it('should show placeholder background until load', () => {
Expand Down
19 changes: 1 addition & 18 deletions packages/react/src/Image.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
useCallback,
useState
} from 'react'
import { preload } from 'react-dom'
import {
type SrcSetEntry,
getImageProps
Expand Down Expand Up @@ -42,9 +41,7 @@ export interface ImageProps extends Omit<ComponentProps<'img'>, 'src' | 'srcSet'
*/
placeholder?: string
/**
* Load the image eagerly with high priority and preload it.
* Do not use inside `Picture`: the preload would request the fallback
* format, while the browser picks one of the `source` elements.
* Load the image eagerly with high priority.
*/
priority?: boolean
}
Expand Down Expand Up @@ -100,20 +97,6 @@ export function Image({
finalHeight = src.height
}

if (priority && imageProps.src) {
// The request policy must match the image request,
// otherwise the preloaded response is not reusable.
preload(imageProps.src, {
as: 'image',
type: src?.type,
fetchPriority: 'high',
imageSrcSet: imageProps.srcSet,
imageSizes: props.sizes,
crossOrigin: props.crossOrigin,
referrerPolicy: props.referrerPolicy
})
}

return (
<img
{...props}
Expand Down