1- import { Component , createComponent , lazy as solidLazy } from "solid-js" ;
2- import { getRequestEvent } from "solid-js/web" ;
1+ import { Component , lazy as solidLazy } from "solid-js" ;
2+ import { getRequestEvent , isServer } from "solid-js/web" ;
33import { getManifest } from "solid-start:get-manifest" ;
4- import { Asset } from "../server/types .ts" ;
5- import { useAssets } from "./assets .ts" ;
4+ import { useAssets } from "../server/assets/index .ts" ;
5+ import { Asset , PageEvent } from "../server/types .ts" ;
66
77const assetsById : Record < string , Asset [ ] > = { } ;
88
@@ -16,12 +16,12 @@ const getAssets = async (id: string) => {
1616 return assets ;
1717} ;
1818
19- const collectAssets = function < T extends ( ) => Promise < { default : Component < any > } > > ( fn : T ) : T {
20- const wrapper : any = async ( ) => {
19+ const withAssets = function < T extends ( ) => Promise < { default : Component < any > } > > ( fn : T ) : T {
20+ const wrapper = async ( ) => {
2121 const mod = await fn ( ) ;
2222
2323 // This id$$ export is generated by the lazy vite plugin
24- const id = ( mod as any ) . id$$ ;
24+ const id : string = ( mod as any ) . id$$ ;
2525 if ( ! id ) return mod ;
2626
2727 if ( ! mod . default ) {
@@ -34,19 +34,18 @@ const collectAssets = function <T extends () => Promise<{ default: Component<any
3434
3535 return {
3636 default : ( props : any ) => {
37- // TODO: How to get nonce on the client
38- const { nonce } = ( getRequestEvent ( ) as any ) ?? { } ;
37+ const { nonce } = getRequestEvent ( ) as PageEvent ;
3938 useAssets ( assets , nonce ) ;
4039
41- return createComponent ( mod . default , props ) ;
40+ return mod . default ( props ) ;
4241 }
4342 } ;
4443 } ;
4544
46- return wrapper ;
45+ return wrapper as T ;
4746} ;
4847
49- const lazy = < T extends Component < any > > ( fn : ( ) => Promise < { default : T } > ) =>
50- solidLazy ( collectAssets ( fn ) ) ;
48+ const lazy = ! isServer ? solidLazy : < T extends Component < any > > ( fn : ( ) => Promise < { default : T } > ) =>
49+ solidLazy ( withAssets ( fn ) ) ;
5150
5251export default lazy ;
0 commit comments