From 9d5bff24709281b9ca5d107940e91539e192a463 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Fri, 26 Dec 2025 23:52:03 +0800 Subject: [PATCH] ui-next: serialize injected data correctly --- packages/ui-next/index.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/ui-next/index.ts b/packages/ui-next/index.ts index e2b16e870..2f4f0d741 100644 --- a/packages/ui-next/index.ts +++ b/packages/ui-next/index.ts @@ -4,10 +4,11 @@ import importMetaUrlPlugin from '@chialab/esbuild-plugin-meta-url'; import react from '@vitejs/plugin-react'; import c2k from 'koa2-connect/ts'; import { createServer, type Plugin } from 'vite'; -import { } from '@hydrooj/framework'; +import { serializer } from '@hydrooj/framework'; import { Context, getNodes } from 'hydrooj'; const INJECT_MARKER = ''; +const buildInject = (str: string) => ``; function hydroPlugins(): Plugin { const virtualModuleId = 'virtual:hydro-plugins'; @@ -44,7 +45,7 @@ export async function apply(ctx: Context) { 'Cross-Origin-Opener-Policy': 'same-origin', 'Cross-Origin-Embedder-Policy': 'require-corp', }, - allowedHosts: ['beta.hydro.ac'], + // allowedHosts: ['beta.hydro.ac'], }, appType: 'custom', root: __dirname, @@ -54,7 +55,7 @@ export async function apply(ctx: Context) { esbuildOptions: { plugins: [ // @ts-ignore - importMetaUrlPlugin, + importMetaUrlPlugin(), ], }, }, @@ -75,12 +76,14 @@ export async function apply(ctx: Context) { asFallback: false, priority: 100, async render(name, args, context) { - const htmlToRender = html.replace(INJECT_MARKER, ``); + }; + const serialized = JSON.stringify(data, serializer(false, context.handler)); + const htmlToRender = html.replace(INJECT_MARKER, buildInject(serialized)); return await vite.transformIndexHtml(context.handler.context.req.url!, htmlToRender); }, });