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 11import { Dynamic , isServer } from 'solid-js/web'
2+ import { createResource } from 'solid-js'
23import { Outlet } from './Match'
34import type * as Solid from 'solid-js'
45import type { AsyncRouteComponent } from './route'
@@ -42,13 +43,14 @@ export function lazyRouteComponent<
4243 const load = ( ) => {
4344 if ( typeof document === 'undefined' && ssr ?.( ) === false ) {
4445 comp = ( ( ) => null ) as any
45- return Promise . resolve ( )
46+ return Promise . resolve ( comp )
4647 }
4748 if ( ! loadPromise ) {
4849 loadPromise = importer ( )
4950 . then ( ( res ) => {
5051 loadPromise = undefined
5152 comp = res [ exportName ?? 'default' ]
53+ return comp
5254 } )
5355 . catch ( ( err ) => {
5456 error = err
@@ -94,18 +96,19 @@ export function lazyRouteComponent<
9496 throw error
9597 }
9698
97- if ( ! comp ) {
98- throw load ( )
99- }
99+ const [ compResource ] = createResource ( load , {
100+ initialValue : comp ,
101+ ssrLoadFrom : 'initial' ,
102+ } )
100103
101104 if ( ssr ?.( ) === false ) {
102105 return (
103106 < ClientOnly fallback = { < Outlet /> } >
104- < Dynamic component = { comp } { ...props } />
107+ < Dynamic component = { compResource ( ) } { ...props } />
105108 </ ClientOnly >
106109 )
107110 }
108- return < Dynamic component = { comp } { ...props } />
111+ return < Dynamic component = { compResource ( ) } { ...props } />
109112 }
110113
111114 ; ( lazyComp as any ) . preload = load
You can’t perform that action at this time.
0 commit comments