MCPcopy
hub / github.com/facebook/react / pushImg

Function pushImg

packages/react-dom-bindings/src/server/ReactFizzConfigDOM.js:3300–3461  ·  view source on GitHub ↗
(
  target: Array<Chunk | PrecomputedChunk>,
  props: Object,
  resumableState: ResumableState,
  renderState: RenderState,
  hoistableState: null | HoistableState,
  formatContext: FormatContext,
)

Source from the content-addressed store, hash-verified

3298}
3299
3300function pushImg(
3301 target: Array<Chunk | PrecomputedChunk>,
3302 props: Object,
3303 resumableState: ResumableState,
3304 renderState: RenderState,
3305 hoistableState: null | HoistableState,
3306 formatContext: FormatContext,
3307): null {
3308 const pictureOrNoScriptTagInScope =
3309 formatContext.tagScope & (PICTURE_SCOPE | NOSCRIPT_SCOPE);
3310 const {src, srcSet} = props;
3311 if (
3312 props.loading !== 'lazy' &&
3313 (src || srcSet) &&
3314 (typeof src === 'string' || src == null) &&
3315 (typeof srcSet === 'string' || srcSet == null) &&
3316 props.fetchPriority !== 'low' &&
3317 !pictureOrNoScriptTagInScope &&
3318 // We exclude data URIs in src and srcSet since these should not be preloaded
3319 !(
3320 typeof src === 'string' &&
3321 src[4] === ':' &&
3322 (src[0] === 'd' || src[0] === 'D') &&
3323 (src[1] === 'a' || src[1] === 'A') &&
3324 (src[2] === 't' || src[2] === 'T') &&
3325 (src[3] === 'a' || src[3] === 'A')
3326 ) &&
3327 !(
3328 typeof srcSet === 'string' &&
3329 srcSet[4] === ':' &&
3330 (srcSet[0] === 'd' || srcSet[0] === 'D') &&
3331 (srcSet[1] === 'a' || srcSet[1] === 'A') &&
3332 (srcSet[2] === 't' || srcSet[2] === 'T') &&
3333 (srcSet[3] === 'a' || srcSet[3] === 'A')
3334 )
3335 ) {
3336 // We have a suspensey image and ought to preload it to optimize the loading of display blocking
3337 // resumableState.
3338
3339 if (hoistableState !== null) {
3340 // Mark this boundary's state as having suspensey images.
3341 // Only do that if we have a ViewTransition that might trigger a parent Suspense boundary
3342 // to animate its appearing. Since that's the only case we'd actually apply suspensey images
3343 // for SSR reveals.
3344 const isInSuspenseWithEnterViewTransition =
3345 formatContext.tagScope & APPEARING_SCOPE;
3346 if (isInSuspenseWithEnterViewTransition) {
3347 hoistableState.suspenseyImages = true;
3348 }
3349 }
3350
3351 const sizes = typeof props.sizes === 'string' ? props.sizes : undefined;
3352 const key = getImageResourceKey(src, srcSet, sizes);
3353
3354 const promotablePreloads = renderState.preloads.images;
3355
3356 let resource = promotablePreloads.get(key);
3357 if (resource) {

Callers 1

pushStartInstanceFunction · 0.85

Calls 8

getCrossOriginStringFunction · 0.90
getImageResourceKeyFunction · 0.85
getPreloadAsHeaderFunction · 0.85
pushLinkImplFunction · 0.85
pushSelfClosingFunction · 0.85
addMethod · 0.80
setMethod · 0.80
getMethod · 0.65

Tested by

no test coverage detected