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

Code before:
  if (resourceState !== EXISTS) {
    // We are going to create this resource now so it is marked as Exists
    resumableState.styleResources[key] = EXISTS;

    if (__DEV__) {
      if (resourceState) {
        console.error(
          'React encountered a hoistable style tag for the same href as a preload: "%s". When using a style tag to inline styles you should not also preload it as a stylsheet.',
          href,
        );
      }
    }

    if (!styleQueue) {
      // This is the first time we've encountered this precedence we need
      // to create a StyleQueue.
      styleQueue = {
        precedence: stringToChunk(escapeTextForBrowser(precedence)),
        rules: ([]: Array<Chunk | PrecomputedChunk>),
        hrefs: [stringToChunk(escapeTextForBrowser(href))],
        sheets: (new Map(): Map<string, StylesheetResource>),
        nonce: nonce && stringToChunk(escapeTextForBrowser(nonce)),
      };
      renderState.styles.set(precedence, styleQueue);
    } else {
      if (!('nonce' in styleQueue)) {
        // `styleQueue` could have been created by `preinit` where `nonce` is not required
        styleQueue.nonce = nonce && stringToChunk(escapeTextForBrowser(nonce));
      }
      if (__DEV__) {
        if (nonce !== styleQueue.nonce) {
          console.error(
            'React encountered a hoistable style tag with "%s" nonce. It doesn\'t match the previously encountered nonce "%s". They have to be the same',
            nonce && stringToChunk(escapeTextForBrowser(nonce)),
            styleQueue.nonce,
          );
        }
      }
      // We have seen this precedence before and need to track this href
      styleQueue.hrefs.push(stringToChunk(escapeTextForBrowser(href)));
    }
    pushStyleContents(styleQueue.rules, props);
  }
  if (styleQueue) {
    // We need to track whether this boundary should wait on this resource or not.
    // Typically this resource should always exist since we either had it or just created
    // it. However, it's possible when you resume that the style has already been emitted
    // and then it wouldn't be recreated in the RenderState and there's no need to track
    // it again since we should've hoisted it to the shell already.
    if (hoistableState) {
      hoistableState.styles.add(styleQueue);

Review comment (suggestion):
The nonce should be known early even if using preinitStyle. we can assume whatever nonce was used at styleQueue creation time is sufficient for all other style rules and don't need this lazy nonce check.

We can separately add a dev only warning which indicates when you are passing incompatible nonces to style tags. You would do this by having a dev only extra property like

```
const styleQueue = {
  ...
}
if (__DEV__) {
  styleQueue.__nonceString = nonce
}
```

It wouldn't be part of the type and you'd have to type cast to any when you read it

Code after:
    }
    if (__DEV__) {
      checkHtmlStringCoercion(children);
    }
    value = '' + children;
  }

  if (typeof value === 'string' && value[0] === '\n') {
    // text/html ignores the first character in these tags if it's a newline
    // Prefer to break application/xml over text/html (for now) by adding
    // a newline specifically to get eaten by the parser. (Alternately for
    // textareas, replacing "^\n" with "\r\n" doesn't get eaten, and the first
    // \r is normalized out by HTMLTextAreaElement#value.)
    // See: <http://www.w3.org/TR/html-polyglot/#newlines-in-textarea-and-pre>
    // See: <http://www.w3.org/TR/html5/syntax.html#element-restrictions>
    // See: <http://www.w3.org/TR/html5/syntax.html#newlines>
    // See: Parsing of "textarea" "listing" and "pre" elements
    //  from <http://www.w3.org/TR/html5/syntax.html#parsing-main-inbody>
    target.push(leadingNewline);
  }

  // ToString and push directly instead of recurse over children.
  // We don't really support complex children in the value anyway.
  // This also currently avoids a trailing comment node which breaks textarea.
  if (value !== null) {
    if (__DEV__) {
      checkAttributeStringCoercion(value, 'value');
    }
    target.push(stringToChunk(encodeHTMLTextNode('' + value)));
  }

  return null;
}

function pushMeta(
  target: Array<Chunk | PrecomputedChunk>,
  props: Object,
  renderState: RenderState,
  textEmbedded: boolean,
  formatContext: FormatContext,
): null {
  const noscriptTagInScope = formatContext.tagScope & NOSCRIPT_SCOPE;
  const isFallback = formatContext.tagScope & FALLBACK_SCOPE;
  if (
    formatContext.insertionMode === SVG_MODE ||
    noscriptTagInScope ||
    props.itemProp != null
  ) {
    return pushSelfClosing(target, props, 'meta', formatContext);
  } else {
    if (textEmbedded) {