/**
* Small runtime-safe Fast Refresh preamble helper.
*
* Keep this separate from `bundler/dev.ts`: SSR runtimes import the helper
* while edge bundles must not pull the dev bundler, build graph, or TypeScript
* compiler into production worker output.
*/
export function generateFastRefreshPreamble(
glueUrl: string,
runtimeUrl: string,
): string {
// Both URLs must be non-empty. If either is missing (e.g. vendor
// shim build failed), the caller should skip this preamble entirely.
if (!glueUrl || !runtimeUrl) {
return ``;
}
// JSON.stringify escapes the URLs safely for inline `` sequence in the
// URL bytes breaking the enclosing tag. This is the same defense
// Vite uses in its own preamble emitter.
const glueLit = JSON.stringify(glueUrl).split("").join('<"+"/');
const runtimeLit = JSON.stringify(runtimeUrl).split("").join('<"+"/');
return ``;
}