Repository: facebook/react
File: packages/react-dom-bindings/src/server/ReactFizzConfigDOM.js (JavaScript)

Code before:
    if (hasOwnProperty.call(props, propKey)) {
      const propValue = props[propKey];
      if (propValue == null) {
        continue;
      }
      switch (propKey) {
        case 'children':
        case 'dangerouslySetInnerHTML':
          throw new Error(
            `${tag} is a self-closing tag and must neither have \`children\` nor ` +
              'use `dangerouslySetInnerHTML`.',
          );
        default:
          pushAttribute(target, propKey, propValue);
          break;
      }
    }
  }

  target.push(endOfStartTagSelfClosing);
  return null;
}

function pushStartMenuItem(
  target: Array<Chunk | PrecomputedChunk>,
  props: Object,
): ReactNodeList {
  target.push(startChunkForTag('menuitem'));

  for (const propKey in props) {
    if (hasOwnProperty.call(props, propKey)) {
      const propValue = props[propKey];
      if (propValue == null) {
        continue;
      }
      switch (propKey) {
        case 'children':
        case 'dangerouslySetInnerHTML':
          throw new Error(
            'menuitems cannot have `children` nor `dangerouslySetInnerHTML`.',
          );
        default:
          pushAttribute(target, propKey, propValue);
          break;
      }
    }
  }

  target.push(endOfStartTag);
  return null;
}

Review comment (refactor):
Let's extract this stuff too like `getPreloadResource(...)`.

Code after:
    if (typeof imageSizes === 'string') {
      uniquePart += '[' + imageSizes + ']';
    }
  } else {
    uniquePart += '[][]' + href;
  }
  return getResourceKey('image', uniquePart);
}

function pushImg(
  target: Array<Chunk | PrecomputedChunk>,
  props: Object,
  resources: Resources,
): null {
  if (
    props.loading !== 'lazy' &&
    typeof props.src === 'string' &&
    props.fetchPriority !== 'low'
  ) {
    // We have a suspensey image and ought to preload it to optimize the loading of display blocking
    // resources.
    const {src, imageSrcSet, imageSizes} = props;
    const key = getImagePreloadKey(src, imageSrcSet, imageSizes);
    let resource = resources.preloadsMap.get(key);
    if (!resource) {
      resource = {
        type: 'preload',
        chunks: [],
        state: NoState,
        props: {
          rel: 'preload',
          as: 'image',
          // There is a bug in Safari where imageSrcSet is not respected on preload links
          // so we omit the href here if we have imageSrcSet b/c safari will load the wrong image.
          // This harms older browers that do not support imageSrcSet by making their preloads not work
          // but this population is shrinking fast and is already small so we accept this tradeoff.
          href: imageSrcSet ? undefined : src,
          imageSrcSet,
          imageSizes,
          crossOrigin: props.crossOrigin,
          integrity: props.integrity,
          type: props.type,
          fetchPriority: props.fetchPriority,
          referrerPolicy: props.referrerPolicy,
        },
      };
      resources.preloadsMap.set(key, resource);
      if (__DEV__) {
        markAsRenderedResourceDEV(resource, props);
      }
      pushLinkImpl(resource.chunks, resource.props);