Skip to content

Commit b9d38a1

Browse files
fix(router): use router for script tag rendering
1 parent 3d00753 commit b9d38a1

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

packages/react-router/src/Asset.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as React from 'react'
22
import type { RouterManagedTag } from '@tanstack/router-core'
3+
import { useRouter } from './useRouter'
34

45
interface ScriptAttrs {
56
[key: string]: string | boolean | undefined
@@ -44,6 +45,8 @@ function Script({
4445
attrs?: ScriptAttrs
4546
children?: string
4647
}) {
48+
const router = useRouter()
49+
4750
React.useEffect(() => {
4851
if (attrs?.src) {
4952
const existingScript = document.querySelector(
@@ -115,7 +118,7 @@ function Script({
115118
return undefined
116119
}, [attrs, children])
117120

118-
if (typeof window !== 'undefined') {
121+
if (!router.isServer) {
119122
return null
120123
}
121124

packages/solid-router/src/Asset.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Meta, Style, Title } from '@solidjs/meta'
22
import { onCleanup, onMount } from 'solid-js'
3+
import { useRouter } from './useRouter'
34
import type { RouterManagedTag } from '@tanstack/router-core'
45
import type { JSX } from 'solid-js'
56

@@ -36,6 +37,8 @@ function Script({
3637
attrs?: ScriptAttrs
3738
children?: string
3839
}): JSX.Element | null {
40+
const router = useRouter()
41+
3942
onMount(() => {
4043
if (attrs?.src) {
4144
const existingScript = document.querySelector(
@@ -95,7 +98,7 @@ function Script({
9598
}
9699
})
97100

98-
if (typeof window !== 'undefined') {
101+
if (!router.isServer) {
99102
return null
100103
}
101104

0 commit comments

Comments
 (0)