1
1
import { ContextValue , SlotProps } from 'react-aria-components' ;
2
- import { createContext , ForwardedRef , forwardRef , HTMLAttributeReferrerPolicy , ReactNode , useCallback , useContext , useMemo , useReducer , useRef } from 'react' ;
2
+ import { createContext , ForwardedRef , forwardRef , HTMLAttributeReferrerPolicy , ReactNode , useCallback , useContext , useMemo , useReducer , useRef , version } from 'react' ;
3
3
import { DefaultImageGroup , ImageGroup } from './ImageCoordinator' ;
4
4
import { loadingStyle , useIsSkeleton , useLoadingAnimation } from './Skeleton' ;
5
5
import { mergeStyles } from '../style/runtime' ;
@@ -27,8 +27,11 @@ export interface ImageProps extends UnsafeStyles, SlotProps {
27
27
* [See MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img#decoding).
28
28
*/
29
29
decoding ?: 'async' | 'auto' | 'sync' ,
30
- // Only supported in React 19...
31
- // fetchPriority?: 'high' | 'low' | 'auto',
30
+ /**
31
+ * Provides a hint of the relative priority to use when fetching the image.
32
+ * [See MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img#fetchpriority).
33
+ */
34
+ fetchPriority ?: 'high' | 'low' | 'auto' ,
32
35
/**
33
36
* Whether the image should be loaded immediately or lazily when scrolled into view.
34
37
* [See MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img#loading).
@@ -146,6 +149,7 @@ export const Image = forwardRef(function Image(props: ImageProps, domRef: Forwar
146
149
alt,
147
150
crossOrigin,
148
151
decoding,
152
+ fetchPriority,
149
153
loading,
150
154
referrerPolicy,
151
155
slot
@@ -223,6 +227,7 @@ export const Image = forwardRef(function Image(props: ImageProps, domRef: Forwar
223
227
{ errorState }
224
228
{ ! errorState && (
225
229
< img
230
+ { ...getFetchPriorityProp ( fetchPriority ) }
226
231
src = { src }
227
232
alt = { alt }
228
233
crossOrigin = { crossOrigin }
@@ -235,5 +240,14 @@ export const Image = forwardRef(function Image(props: ImageProps, domRef: Forwar
235
240
className = { imgStyles ( { isRevealed, isTransitioning} ) } />
236
241
) }
237
242
</ div >
238
- ) , [ slot , hidden , domRef , UNSAFE_style , UNSAFE_className , styles , isAnimating , errorState , src , alt , crossOrigin , decoding , loading , referrerPolicy , onLoad , onError , isRevealed , isTransitioning ] ) ;
243
+ ) , [ slot , hidden , domRef , UNSAFE_style , UNSAFE_className , styles , isAnimating , errorState , src , alt , crossOrigin , decoding , fetchPriority , loading , referrerPolicy , onLoad , onError , isRevealed , isTransitioning ] ) ;
239
244
} ) ;
245
+
246
+ function getFetchPriorityProp ( fetchPriority ?: 'high' | 'low' | 'auto' ) : Record < string , string | undefined > {
247
+ const pieces = version . split ( '.' ) ;
248
+ const major = parseInt ( pieces [ 0 ] , 10 ) ;
249
+ if ( major >= 19 ) {
250
+ return { fetchPriority} ;
251
+ }
252
+ return { fetchpriority : fetchPriority } ;
253
+ }
0 commit comments