Skip to content

Commit 1480587

Browse files
committed
fix(router): improve type safety for script attributes
1 parent e424427 commit 1480587

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

‎packages/react-router/src/Asset.tsx‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,10 @@ function Script({
8989
}
9090

9191
if (typeof children === 'string') {
92-
const typeAttr = attrs?.type ?? 'text/javascript'
93-
const nonceAttr = attrs?.nonce
92+
const typeAttr =
93+
typeof attrs?.type === 'string' ? attrs.type : 'text/javascript'
94+
const nonceAttr =
95+
typeof attrs?.nonce === 'string' ? attrs.nonce : undefined
9496
const existingScript = Array.from(
9597
document.querySelectorAll('script:not([src])'),
9698
).find((el) => {

‎packages/solid-router/src/Asset.tsx‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,10 @@ function Script({
7777
}
7878

7979
if (typeof children === 'string') {
80-
const typeAttr = attrs?.type ?? 'text/javascript'
81-
const nonceAttr = attrs?.nonce
80+
const typeAttr =
81+
typeof attrs?.type === 'string' ? attrs.type : 'text/javascript'
82+
const nonceAttr =
83+
typeof attrs?.nonce === 'string' ? attrs.nonce : undefined
8284
const existingScript = Array.from(
8385
document.querySelectorAll('script:not([src])'),
8486
).find((el) => {

0 commit comments

Comments
 (0)