File tree Expand file tree Collapse file tree 1 file changed +9
-6
lines changed
packages/solid-router/src Expand file tree Collapse file tree 1 file changed +9
-6
lines changed Original file line number Diff line number Diff line change 1
1
import { Dynamic , isServer } from 'solid-js/web'
2
+ import { createResource } from 'solid-js'
2
3
import { Outlet } from './Match'
3
4
import type * as Solid from 'solid-js'
4
5
import type { AsyncRouteComponent } from './route'
@@ -42,13 +43,14 @@ export function lazyRouteComponent<
42
43
const load = ( ) => {
43
44
if ( typeof document === 'undefined' && ssr ?.( ) === false ) {
44
45
comp = ( ( ) => null ) as any
45
- return Promise . resolve ( )
46
+ return Promise . resolve ( comp )
46
47
}
47
48
if ( ! loadPromise ) {
48
49
loadPromise = importer ( )
49
50
. then ( ( res ) => {
50
51
loadPromise = undefined
51
52
comp = res [ exportName ?? 'default' ]
53
+ return comp
52
54
} )
53
55
. catch ( ( err ) => {
54
56
error = err
@@ -94,18 +96,19 @@ export function lazyRouteComponent<
94
96
throw error
95
97
}
96
98
97
- if ( ! comp ) {
98
- throw load ( )
99
- }
99
+ const [ compResource ] = createResource ( load , {
100
+ initialValue : comp ,
101
+ ssrLoadFrom : 'initial' ,
102
+ } )
100
103
101
104
if ( ssr ?.( ) === false ) {
102
105
return (
103
106
< ClientOnly fallback = { < Outlet /> } >
104
- < Dynamic component = { comp } { ...props } />
107
+ < Dynamic component = { compResource ( ) } { ...props } />
105
108
</ ClientOnly >
106
109
)
107
110
}
108
- return < Dynamic component = { comp } { ...props } />
111
+ return < Dynamic component = { compResource ( ) } { ...props } />
109
112
}
110
113
111
114
; ( lazyComp as any ) . preload = load
You can’t perform that action at this time.
0 commit comments