Skip to content

Commit

Permalink
support type in client
Browse files Browse the repository at this point in the history
  • Loading branch information
gnoff committed Feb 25, 2023
1 parent 05c88a2 commit f884574
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,12 @@ function getDocumentFromRoot(root: HoistableRoot): Document {
// ReactDOM.Preload
// --------------------------------------
type PreloadAs = ResourceType;
type PreloadOptions = {as: PreloadAs, crossOrigin?: string, integrity?: string};
type PreloadOptions = {
as: PreloadAs,
crossOrigin?: string,
integrity?: string,
type?: string,
};
function preload(href: string, options: PreloadOptions) {
if (__DEV__) {
validatePreloadArguments(href, options);
Expand Down Expand Up @@ -208,6 +213,7 @@ function preloadPropsFromPreloadOptions(
as,
crossOrigin: as === 'font' ? '' : options.crossOrigin,
integrity: options.integrity,
type: options.type,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4203,7 +4203,6 @@ type PreloadOptions = {
as: PreloadAs,
crossOrigin?: string,
integrity?: string,
media?: string,
type?: string,
};
export function preload(href: string, options: PreloadOptions) {
Expand Down
8 changes: 8 additions & 0 deletions packages/react-dom/src/__tests__/ReactDOMFloat-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2353,6 +2353,7 @@ body {

function ClientApp() {
ReactDOM.preload('foo', {as: 'style'});
ReactDOM.preload('font', {as: 'font', type: 'font/woff2'});
React.useInsertionEffect(() => ReactDOM.preload('bar', {as: 'script'}));
React.useLayoutEffect(() => ReactDOM.preload('baz', {as: 'font'}));
React.useEffect(() => ReactDOM.preload('qux', {as: 'style'}));
Expand All @@ -2372,6 +2373,13 @@ body {
<html>
<head>
<link rel="preload" as="style" href="foo" />
<link
rel="preload"
as="font"
href="font"
crossorigin=""
type="font/woff2"
/>
<link rel="preload" as="font" href="baz" crossorigin="" />
<link rel="preload" as="style" href="qux" />
</head>
Expand Down

0 comments on commit f884574

Please sign in to comment.