Skip to content

Bug: Support nonce for streaming scripts #26026

Closed
@kentcdodds

Description

@kentcdodds

React version: 18.2.0

Steps To Reproduce

  1. Have a server-rendered React app with a CSP that specifies a nonce for scripts
  2. Try to use suspense + streaming

The current behavior

As noted in @sebmarkbage's comment, nonce support should be added to the scripts that React injects for suspense + streaming. That doesn't appear to be happening. I can't find where in the source code those scripts are generated, but in the built code I notice there's no nonce support of any kind:

var startInlineScript = stringToPrecomputedChunk('<script>');
var endInlineScript = stringToPrecomputedChunk('</script>');
var startScriptSrc = stringToPrecomputedChunk('<script src="');
var startModuleSrc = stringToPrecomputedChunk('<script type="module" src="');
var endAsyncScript = stringToPrecomputedChunk('" async=""></script>');

That appears above a function called escapeBootstrapScriptContent which for the life of me I can't find in the react repo 🤷‍♂️

The expected behavior

I should be able to provide a nonce to React (presumably at the renderToPipeableStream and hydrateRoot calls?) so React can include those in the scripts it creates.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Status: UnconfirmedA potential issue that we haven't yet confirmed as a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions