@@ -106,7 +106,7 @@ import '@stacksjs/browser'
106106 * Inject STX signals runtime into the template.
107107 * The runtime provides client-side reactivity.
108108 */
109- export function injectSignalsRuntime ( template : string , options : StxOptions ) : string {
109+ export async function injectSignalsRuntime ( template : string , options : StxOptions ) : Promise < string > {
110110 // Don't inject if actual signals runtime is already present
111111 // Check for the runtime's unique signature (state, derived, effect assignment),
112112 // not just any 'window.stx =' which could be scope registration from includes
@@ -130,8 +130,8 @@ export function injectSignalsRuntime(template: string, options: StxOptions): str
130130 }
131131
132132 // Use cached runtime (identical for every page, never changes during dev session)
133- const { getCachedSignalsRuntime } = require ( './caching' )
134- const runtime = getCachedSignalsRuntime ( options . debug )
133+ const { getCachedSignalsRuntime } = await import ( './caching' )
134+ const runtime = await getCachedSignalsRuntime ( options . debug )
135135 const runtimeScript = `<script data-stx-scoped>${ runtime } </script>`
136136
137137 // Inject before the first <script in the ENTIRE document, not just <head>.
@@ -163,7 +163,7 @@ export function injectSignalsRuntime(template: string, options: StxOptions): str
163163 * The router is provided by the canonical router in packages/router/src/client.ts.
164164 * It guards against double-initialization so it's safe to inject alongside @stxRouter.
165165 */
166- export function injectRouterScript ( template : string , options ?: StxOptions ) : string {
166+ export async function injectRouterScript ( template : string , options ?: StxOptions ) : Promise < string > {
167167 // Only inject into full HTML pages (not template fragments or components)
168168 if ( ! template . includes ( '</body>' ) ) {
169169 return template
@@ -190,10 +190,10 @@ export function injectRouterScript(template: string, options?: StxOptions): stri
190190 }
191191
192192 // Build mode: emit a placeholder reference instead of inlining the full router script.
193- const { getCachedRouterScript } = require ( './caching' )
193+ const { getCachedRouterScript } = await import ( './caching' )
194194 const routerScript = options ?. buildMode === 'compile'
195195 ? `<script src="/__stx/router.__STX_HASH__.js"></script>`
196- : `<script>${ getCachedRouterScript ( ) } </script>`
196+ : `<script>${ await getCachedRouterScript ( ) } </script>`
197197
198198 // Use string concatenation to avoid $-interpretation in .replace()
199199 const bodyCloseIdx = template . lastIndexOf ( '</body>' )
0 commit comments