File tree Expand file tree Collapse file tree 2 files changed +8
-2
lines changed Expand file tree Collapse file tree 2 files changed +8
-2
lines changed Original file line number Diff line number Diff line change 1
1
import * as React from 'react'
2
2
import type { RouterManagedTag } from '@tanstack/router-core'
3
+ import { useRouter } from './useRouter'
3
4
4
5
interface ScriptAttrs {
5
6
[ key : string ] : string | boolean | undefined
@@ -44,6 +45,8 @@ function Script({
44
45
attrs ?: ScriptAttrs
45
46
children ?: string
46
47
} ) {
48
+ const router = useRouter ( )
49
+
47
50
React . useEffect ( ( ) => {
48
51
if ( attrs ?. src ) {
49
52
const existingScript = document . querySelector (
@@ -115,7 +118,7 @@ function Script({
115
118
return undefined
116
119
} , [ attrs , children ] )
117
120
118
- if ( typeof window !== 'undefined' ) {
121
+ if ( ! router . isServer ) {
119
122
return null
120
123
}
121
124
Original file line number Diff line number Diff line change 1
1
import { Meta , Style , Title } from '@solidjs/meta'
2
2
import { onCleanup , onMount } from 'solid-js'
3
+ import { useRouter } from './useRouter'
3
4
import type { RouterManagedTag } from '@tanstack/router-core'
4
5
import type { JSX } from 'solid-js'
5
6
@@ -36,6 +37,8 @@ function Script({
36
37
attrs ?: ScriptAttrs
37
38
children ?: string
38
39
} ) : JSX . Element | null {
40
+ const router = useRouter ( )
41
+
39
42
onMount ( ( ) => {
40
43
if ( attrs ?. src ) {
41
44
const existingScript = document . querySelector (
@@ -95,7 +98,7 @@ function Script({
95
98
}
96
99
} )
97
100
98
- if ( typeof window !== 'undefined' ) {
101
+ if ( ! router . isServer ) {
99
102
return null
100
103
}
101
104
You can’t perform that action at this time.
0 commit comments