mirror of
https://github.com/hanzoai/react.git
synced 2026-09-24 17:02:27 +00:00
[Float] Forward nonce option in ReactDOM.preloadModule() (#36851)
This commit is contained in:
@@ -622,6 +622,7 @@ module.exports = {
|
||||
ReadableStreamReader: 'readonly',
|
||||
RequestInfo: 'readonly',
|
||||
RequestOptions: 'readonly',
|
||||
Required: 'readonly',
|
||||
StoreAsGlobal: 'readonly',
|
||||
symbol: 'readonly',
|
||||
SyntheticEvent: 'readonly',
|
||||
|
||||
@@ -118,7 +118,9 @@ export function preinitModuleForSSR(
|
||||
ReactDOMSharedInternals.d /* ReactDOMCurrentDispatcher */
|
||||
.M(/* preinitModuleScript */ href, {
|
||||
crossOrigin: getCrossOriginString(crossOrigin),
|
||||
integrity: undefined,
|
||||
nonce,
|
||||
fetchPriority: undefined,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -130,6 +132,8 @@ export function preinitScriptForSSR(
|
||||
ReactDOMSharedInternals.d /* ReactDOMCurrentDispatcher */
|
||||
.X(/* preinitScript */ href, {
|
||||
crossOrigin: getCrossOriginString(crossOrigin),
|
||||
integrity: undefined,
|
||||
fetchPriority: undefined,
|
||||
nonce,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -6621,6 +6621,29 @@ body {
|
||||
);
|
||||
});
|
||||
|
||||
it('supports nonce', async () => {
|
||||
function App({ssr}) {
|
||||
const prefix = ssr ? 'ssr ' : 'browser ';
|
||||
ReactDOM.preloadModule(prefix + 'module', {nonce: 'abc'});
|
||||
return <div>hello</div>;
|
||||
}
|
||||
await act(() => {
|
||||
renderToPipeableStream(<App ssr={true} />).pipe(writable);
|
||||
});
|
||||
expect(getMeaningfulChildren(document.body)).toEqual(
|
||||
<div id="container">
|
||||
<link rel="modulepreload" href="ssr module" nonce="abc" />
|
||||
<div>hello</div>
|
||||
</div>,
|
||||
);
|
||||
|
||||
ReactDOMClient.hydrateRoot(container, <App />);
|
||||
await waitForAll([]);
|
||||
expect(getMeaningfulChildren(document.head)).toEqual(
|
||||
<link rel="modulepreload" href="browser module" nonce="abc" />,
|
||||
);
|
||||
});
|
||||
|
||||
it('warns if you provide invalid arguments', async () => {
|
||||
function App() {
|
||||
ReactDOM.preloadModule();
|
||||
|
||||
@@ -192,6 +192,7 @@ export function preloadModule(href: string, options?: ?PreloadModuleOptions) {
|
||||
typeof options.integrity === 'string'
|
||||
? options.integrity
|
||||
: undefined,
|
||||
nonce: typeof options.nonce === 'string' ? options.nonce : undefined,
|
||||
fetchPriority:
|
||||
typeof options.fetchPriority === 'string'
|
||||
? options.fetchPriority
|
||||
|
||||
+8
-5
@@ -93,21 +93,24 @@ export type HostDispatcher = {
|
||||
L /* preload */: (
|
||||
href: string,
|
||||
as: string,
|
||||
options?: ?PreloadImplOptions,
|
||||
options?: ?Required<PreloadImplOptions>,
|
||||
) => void,
|
||||
m /* preloadModule */: (
|
||||
href: string,
|
||||
options?: ?PreloadModuleImplOptions,
|
||||
options?: ?Required<PreloadModuleImplOptions>,
|
||||
) => void,
|
||||
S /* preinitStyle */: (
|
||||
href: string,
|
||||
precedence: ?string,
|
||||
options?: ?PreinitStyleOptions,
|
||||
options?: ?Required<PreinitStyleOptions>,
|
||||
) => void,
|
||||
X /* preinitScript */: (
|
||||
src: string,
|
||||
options?: ?Required<PreinitScriptOptions>,
|
||||
) => void,
|
||||
X /* preinitScript */: (src: string, options?: ?PreinitScriptOptions) => void,
|
||||
M /* preinitModuleScript */: (
|
||||
src: string,
|
||||
options?: ?PreinitModuleScriptOptions,
|
||||
options?: ?Required<PreinitModuleScriptOptions>,
|
||||
) => void,
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user