Skip to content

Commit 73ce3f9

Browse files
committed
fix and refactor opts args
1 parent 8ebab8f commit 73ce3f9

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

packages/next/src/server/app-render/rsc/preloads.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,28 @@ Files in the rsc directory are meant to be packaged as part of the RSC graph usi
77
import ReactDOM from 'react-dom'
88

99
export function preloadStyle(href: string, crossOrigin?: string | undefined) {
10-
ReactDOM.preload(href, { as: 'style', crossOrigin })
10+
const opts: any = { as: 'style' }
11+
if (typeof crossOrigin === 'string') {
12+
opts.crossOrigin = crossOrigin
13+
}
14+
ReactDOM.preload(href, opts)
1115
}
1216

1317
export function preloadFont(
1418
href: string,
1519
type: string,
1620
crossOrigin?: string | undefined
1721
) {
18-
;(ReactDOM as any).preload(href, { as: 'font', type, crossOrigin })
22+
const opts: any = { as: 'font', type }
23+
if (typeof crossOrigin === 'string') {
24+
opts.crossOrigin = crossOrigin
25+
}
26+
ReactDOM.preload(href, opts)
1927
}
2028

2129
export function preconnect(href: string, crossOrigin?: string | undefined) {
22-
if (typeof crossOrigin === 'string') {
23-
;(ReactDOM as any).preconnect(href, { crossOrigin })
24-
} else {
25-
;(ReactDOM as any).preconnect(href)
26-
}
30+
;(ReactDOM as any).preconnect(
31+
href,
32+
typeof crossOrigin === 'string' ? { crossOrigin } : undefined
33+
)
2734
}

0 commit comments

Comments
 (0)