-
Notifications
You must be signed in to change notification settings - Fork 47.3k
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
Update preload links to support nonce and fetchpriority #26826
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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( | ||
<html> | ||
<head> | ||
<link rel="stylesheet" fetchPriority="high" href="foo" /> | ||
</head> | ||
<body> | ||
<link rel="stylesheet" fetchPriority="low" href="notaresource" /> | ||
<div>hello world</div> | ||
</body> | ||
</html>, | ||
); | ||
pipe(writable); | ||
}); | ||
|
||
expect(getMeaningfulChildren(document)).toEqual( | ||
<html> | ||
<head> | ||
<link rel="preload" as="style" fetchpriority="high" href="foo" /> | ||
<link | ||
rel="preload" | ||
as="style" | ||
fetchpriority="low" | ||
href="notaresource" | ||
/> | ||
<link rel="stylesheet" fetchpriority="high" href="foo" /> | ||
</head> | ||
<body> | ||
<link rel="stylesheet" fetchpriority="low" href="notaresource" /> | ||
<div>hello world</div> | ||
</body> | ||
</html>, | ||
); | ||
}); | ||
|
||
// @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( | ||
<html> | ||
<head /> | ||
<body> | ||
<script src="foo" fetchPriority="high" nonce="1234" /> | ||
<script src="bar" fetchPriority="low" nonce="1234" /> | ||
hello world | ||
</body> | ||
</html>, | ||
); | ||
pipe(writable); | ||
}); | ||
|
||
expect(getMeaningfulChildren(document)).toEqual( | ||
<html> | ||
<head> | ||
<link | ||
rel="preload" | ||
href="foo" | ||
fetchpriority="high" | ||
nonce="1234" | ||
as="script" | ||
/> | ||
<link | ||
rel="preload" | ||
href="bar" | ||
fetchpriority="low" | ||
nonce="1234" | ||
as="script" | ||
/> | ||
</head> | ||
<body>hello world</body> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I noticed the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. getMeaningfulChildren filters out some scripts like instruction scripts. Sometimes it can't tell whether a script is meaningful so you can render it with a specail attribute |
||
</html>, | ||
); | ||
}); | ||
|
||
// @gate enableFloat | ||
it('does not create script resources when inside an <svg> context', async () => { | ||
await act(() => { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't make these changes to
preloadPropsFromPreloadOptions
. It seems like that's used forReactDOM.preload
- please let me know if I should make similar changes there as wellThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@liuyenwei we should support this for preload and preinit functions if you want to open a separate PR for that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sounds good, i can make that change as well. thanks @gnoff !