@@ -4,7 +4,6 @@ import { renderToString } from 'https://esm.sh/react-dom/server'
4
4
import util from '../../shared/util.ts'
5
5
import type { RenderResult , RouterURL } from '../../types.ts'
6
6
import events from '../core/events.ts'
7
- import { serverStyles } from "../core/style.ts"
8
7
import { RendererContext , RouterContext } from './context.ts'
9
8
import { AsyncUseDenoError , E400MissingComponent , E404Page } from './error.ts'
10
9
import { createPageProps } from './pageprops.ts'
@@ -15,7 +14,7 @@ export async function render(
15
14
App : ComponentType < any > | undefined ,
16
15
E404 : ComponentType | undefined ,
17
16
pageComponentChain : { url : string , Component ?: any } [ ] ,
18
- styles ? : { url : string , hash : string } [ ]
17
+ styles : { url : string , hash : string } [ ]
19
18
) {
20
19
const global = globalThis as any
21
20
const ret : Omit < RenderResult , 'url' | 'status' > = {
@@ -139,18 +138,18 @@ export async function render(
139
138
} )
140
139
scriptsElements . clear ( )
141
140
142
- // get inline- styles
143
- const rets = await Promise . all ( styles ?. filter ( ( { url } ) => ! url . startsWith ( '#inline-style-' ) ) . map ( ( { url, hash } ) => {
144
- const path = util . isLikelyHttpURL ( url ) ? '/-/' + url . split ( '://' ) [ 1 ] : ` ${ url } . ${ util . shortHash ( hash ) } `
145
- return import ( 'file:/ /' + util . cleanPath ( `${ Deno . cwd ( ) } /.aleph/ ${ buildMode } / ${ path } .js` ) )
146
- } ) || [ ] )
147
- rets . forEach ( ( { default : def } ) => util . isFunction ( def ) && def ( ) )
148
- styles ?. forEach ( ( { url } ) => {
149
- if ( serverStyles . has ( url ) ) {
150
- const css = serverStyles . get ( url ) !
151
- ret . head . push ( `<style type="text/css" data-module-id= ${ JSON . stringify ( url ) } ssr> ${ css } </style>` )
141
+ // apply styles
142
+ await Promise . all ( styles . map ( async ( { url, hash } ) => {
143
+ if ( ! url . startsWith ( '#inline-style-' ) ) {
144
+ const pathname = util . isLikelyHttpURL ( url ) ? '/- /' + url . split ( '://' ) [ 1 ] : `${ url } . ${ util . shortHash ( hash ) } `
145
+ const importUrl = 'file://' + util . cleanPath ( ` ${ Deno . cwd ( ) } /.aleph/ ${ buildMode } / ${ pathname } .js` )
146
+ const { default : applyCSS } = await import ( importUrl )
147
+ if ( util . isFunction ( applyCSS ) ) {
148
+ const { css } = applyCSS ( )
149
+ ret . head . push ( `<style type="text/css" data-module-id= ${ JSON . stringify ( url ) } ssr> ${ css } </style>` )
150
+ }
152
151
}
153
- } )
152
+ } ) )
154
153
155
154
defer ( )
156
155
return ret
0 commit comments