From 957b673fd3a278c331370bb3fb2552461335c986 Mon Sep 17 00:00:00 2001
From: Yen-Wei Liu
Date: Wed, 17 May 2023 17:01:30 +0000
Subject: [PATCH] Update preload links to support nonce and fetchpriority
---
.../src/server/ReactFizzConfigDOM.js | 3 +
.../src/__tests__/ReactDOMFloat-test.js | 76 +++++++++++++++++++
2 files changed, 79 insertions(+)
diff --git a/packages/react-dom-bindings/src/server/ReactFizzConfigDOM.js b/packages/react-dom-bindings/src/server/ReactFizzConfigDOM.js
index 353a534090b69..5314564242ed9 100644
--- a/packages/react-dom-bindings/src/server/ReactFizzConfigDOM.js
+++ b/packages/react-dom-bindings/src/server/ReactFizzConfigDOM.js
@@ -5510,6 +5510,7 @@ function preloadAsStylePropsFromProps(href: string, props: any): PreloadProps {
as: 'style',
href: href,
crossOrigin: props.crossOrigin,
+ fetchPriority: props.fetchPriority,
integrity: props.integrity,
media: props.media,
hrefLang: props.hrefLang,
@@ -5523,7 +5524,9 @@ function preloadAsScriptPropsFromProps(href: string, props: any): PreloadProps {
as: 'script',
href,
crossOrigin: props.crossOrigin,
+ fetchPriority: props.fetchPriority,
integrity: props.integrity,
+ nonce: props.nonce,
referrerPolicy: props.referrerPolicy,
};
}
diff --git a/packages/react-dom/src/__tests__/ReactDOMFloat-test.js b/packages/react-dom/src/__tests__/ReactDOMFloat-test.js
index 272d7996bb7ff..842b9c4153e2c 100644
--- a/packages/react-dom/src/__tests__/ReactDOMFloat-test.js
+++ b/packages/react-dom/src/__tests__/ReactDOMFloat-test.js
@@ -4531,6 +4531,43 @@ body {
);
});
+ // @gate enableFloat
+ it('respects attributes defined on the stylesheet element when preloading stylesheets during server rendering', async () => {
+ await act(() => {
+ const {pipe} = renderToPipeableStream(
+
+
+
+
+
+
+ hello world
+
+ ,
+ );
+ pipe(writable);
+ });
+
+ expect(getMeaningfulChildren(document)).toEqual(
+
+
+
+
+
+
+
+
+ hello world
+
+ ,
+ );
+ });
+
// @gate enableFloat
it('hoists stylesheet resources to the correct precedence', async () => {
await act(() => {
@@ -5913,6 +5950,45 @@ background-color: green;
);
});
+ // @gate enableFloat
+ it('respects attributes defined on the script element when preloading scripts during server rendering', async () => {
+ await act(() => {
+ const {pipe} = renderToPipeableStream(
+
+
+
+
+
+ hello world
+
+ ,
+ );
+ pipe(writable);
+ });
+
+ expect(getMeaningfulChildren(document)).toEqual(
+
+
+
+
+
+ hello world
+ ,
+ );
+ });
+
// @gate enableFloat
it('does not create script resources when inside an