-
Notifications
You must be signed in to change notification settings - Fork 47k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug: Support nonce for streaming scripts #26026
Comments
This already exists on Sorry for the noise. |
To be clear, this only exists for inline scripts via |
@danieltott Mind filing a new issue with more details? |
Seems reasonable. PR? |
Updated issue and PR in progress - will update later tonight 👍 |
Would adding nonce support to the other script types be a bug or a feature? |
External runtime should have it too.
|
Actually I think #24883 covers it (with my comment additions). I'm not sure if adding a new issue is appropriate/useful, since it'll be pretty much the same. @sebmarkbage As far as scripts rendered inside the tree, it's actually a non-issue when using If you're not using |
@sebmarkbage can you clarify? I'm adjusting the code in
I'm new to the React codebase so just want to make sure I cover my bases. |
You can add a However, we also might need to add it to the code that adds a script tag to load the external runtime.
However, I'm not sure if it need it for all |
@sebmarkbage I filed a PR here: #26738 Pretty sure I handled all the cases we'd need to cover. |
@sebmarkbage generally I'm of the mind that we should not auto-nonce preinits or user scripts. I opened #26744 to add the ability to provide a nonce while preiniting |
This patch provides the `nonce` option to the React `renderToPipeableStream` function so that React will add it to scripts dynamically injected (e.g. the `<Suspense>` inline scripts). Ref: https://react.dev/reference/react-dom/server/renderToPipeableStream#parameters Ref: facebook/react#26026 (comment) Ref: remix-run/remix#5156 (comment)
So that React passes the nonce to the script tags it generates when using <Suspense>. See facebook/react#26026
React version: 18.2.0
Steps To Reproduce
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:
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
andhydrateRoot
calls?) so React can include those in the scripts it creates.The text was updated successfully, but these errors were encountered: