Closed
Description
React version: 18.2.0
Steps To Reproduce
- Have a server-rendered React app with a CSP that specifies a nonce for scripts
- 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.