11// @refresh skip
2- import App from "solid-start:app" ;
3- import type { Component , JSX } from "solid-js" ;
2+ import type { Component } from "solid-js" ;
43import {
54 Hydration ,
65 HydrationScript ,
76 NoHydration ,
87 getRequestEvent ,
9- ssr ,
10- useAssets
8+ ssr
119} from "solid-js/web" ;
10+ import App from "solid-start:app" ;
1211
1312import { ErrorBoundary , TopErrorBoundary } from "../shared/ErrorBoundary.tsx" ;
14- import { renderAsset } from "./renderAsset.tsx" ;
15- import type { Asset , DocumentComponentProps , PageEvent } from "./types.ts" ;
13+ import { useAssets } from "./assets/index.ts" ;
1614import { getSsrManifest } from "./manifest/ssr-manifest.ts" ;
15+ import type { DocumentComponentProps , PageEvent } from "./types.ts" ;
1716
1817const docType = ssr ( "<!DOCTYPE html>" ) ;
1918
20- function matchRoute ( matches : any [ ] , routes : any [ ] , matched = [ ] ) : any [ ] | undefined {
21- for ( let i = 0 ; i < routes . length ; i ++ ) {
22- const segment = routes [ i ] ;
23- if ( segment . path !== matches [ 0 ] . path ) continue ;
24- let next : any = [ ...matched , segment ] ;
25- if ( segment . children ) {
26- const nextMatches = matches . slice ( 1 ) ;
27- if ( nextMatches . length === 0 ) continue ;
28- next = matchRoute ( nextMatches , segment . children , next ) ;
29- if ( ! next ) continue ;
30- }
31- return next ;
32- }
33- }
34-
3519/**
3620 *
3721 * Read more: https://docs.solidjs.com/solid-start/reference/server/start-server
@@ -41,60 +25,16 @@ export function StartServer(props: { document: Component<DocumentComponentProps>
4125
4226 // @ts -ignore
4327 const nonce = context . nonce ;
44-
45- let assets : Asset [ ] = [ ] ;
46- Promise . resolve ( )
47- . then ( async ( ) => {
48- const manifest = getSsrManifest ( "ssr" ) ;
49-
50- let assetPromises : Promise < Asset [ ] > [ ] = [ ] ;
51- // @ts -ignore
52- if ( context . router && context . router . matches ) {
53- // @ts -ignore
54- const matches = [ ...context . router . matches ] ;
55- while ( matches . length && ( ! matches [ 0 ] . info || ! matches [ 0 ] . info . filesystem ) ) matches . shift ( ) ;
56- const matched = matches . length && matchRoute ( matches , context . routes ) ;
57- if ( matched ) {
58- for ( let i = 0 ; i < matched . length ; i ++ ) {
59- const segment = matched [ i ] ;
60- assetPromises . push ( manifest . getAssets ( segment [ "$component" ] . src ) ) ;
61- }
62- } else if ( import . meta. env . DEV )
63- console . warn (
64- `No route matched for preloading js assets for path ${ new URL ( context . request . url ) . pathname } `
65- ) ;
66- }
67- assets = await Promise . all ( assetPromises ) . then ( a =>
68- // dedupe assets
69- [ ...new Map ( a . flat ( ) . map ( item => [ item . attrs . key , item ] ) ) . values ( ) ] . filter ( asset =>
70- import . meta. env . START_ISLANDS
71- ? false
72- : ( asset . attrs as JSX . LinkHTMLAttributes < HTMLLinkElement > ) . rel === "modulepreload" &&
73- ! context . assets . find ( ( a : Asset ) => a . attrs . key === asset . attrs . key )
74- )
75- ) ;
76- } )
77- . catch ( console . error ) ;
78-
79- useAssets ( ( ) => ( assets . length ? assets . map ( m => renderAsset ( m ) ) : undefined ) ) ;
28+ useAssets ( context . assets , nonce ) ;
8029
8130 return (
8231 < NoHydration >
8332 { docType as unknown as any }
8433 < TopErrorBoundary >
8534 < props . document
86- assets = {
87- < >
88- < HydrationScript />
89- { context . assets . map ( ( m : any ) => renderAsset ( m , nonce ) ) }
90- </ >
91- }
35+ assets = { < HydrationScript /> }
9236 scripts = {
9337 < >
94- < script
95- nonce = { nonce }
96- innerHTML = { `window.manifest = ${ JSON . stringify ( context . manifest ) } ` }
97- />
9838 < script
9939 type = "module"
10040 nonce = { nonce }
0 commit comments