clear fe functions after using them

This commit is contained in:
Chris Wanstrath 2025-12-12 11:57:30 -08:00
parent ddce0c8589
commit feb30369cf
2 changed files with 6 additions and 1 deletions

View File

@ -8,3 +8,7 @@ export function frontend(code: Function) {
export function feFunctions(): string[] { export function feFunctions(): string[] {
return funcs return funcs
} }
export function clearFeFunctions() {
funcs.length = 0
}

View File

@ -6,7 +6,7 @@ import color from 'kleur'
import { transpile } from './utils' import { transpile } from './utils'
import defaultLayout from './layout' import defaultLayout from './layout'
import { feFunctions } from './frontend' import { feFunctions, clearFeFunctions } from './frontend'
const SHOW_HTTP_LOG = true const SHOW_HTTP_LOG = true
const CSS_RESET = await Bun.file(join(import.meta.dir, '/reset.css')).text() const CSS_RESET = await Bun.file(join(import.meta.dir, '/reset.css')).text()
@ -101,6 +101,7 @@ export class Hype<
const res = c.res.clone() const res = c.res.clone()
const html = await res.text() const html = await res.text()
const newHtml = html.replace('</body>', `<script>${fns.join('\n')}</script></body>`) const newHtml = html.replace('</body>', `<script>${fns.join('\n')}</script></body>`)
clearFeFunctions()
c.res = new Response(newHtml, c.res) c.res = new Response(newHtml, c.res)
}) })