From 58b173a0f4a2b27511b5d1d09a998ae040b09078 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Thu, 25 Dec 2025 12:25:03 +0800 Subject: [PATCH] ui-next: inject args into vite html --- packages/ui-next/index.html | 1 + packages/ui-next/index.ts | 14 ++++++++++++-- packages/ui-next/package.json | 4 ++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/packages/ui-next/index.html b/packages/ui-next/index.html index 1d7f9faf7..deacd330d 100644 --- a/packages/ui-next/index.html +++ b/packages/ui-next/index.html @@ -5,6 +5,7 @@ Hydro +
diff --git a/packages/ui-next/index.ts b/packages/ui-next/index.ts index 9fc34d844..30acceb3c 100644 --- a/packages/ui-next/index.ts +++ b/packages/ui-next/index.ts @@ -2,11 +2,13 @@ import fs from 'fs'; import path from 'path'; import importMetaUrlPlugin from '@codingame/esbuild-import-meta-url-plugin'; import react from '@vitejs/plugin-react-swc'; -import c2k from 'koa2-connect'; +import c2k from 'koa2-connect/ts'; import { createServer } from 'vite'; import { } from '@hydrooj/framework'; import { Context } from 'hydrooj'; +const INJECT_MARKER = ''; + export async function apply(ctx: Context) { if (process.env.HYDRO_CLI) return; const vite = await createServer({ @@ -49,7 +51,15 @@ export async function apply(ctx: Context) { output: 'html', asFallback: false, priority: 100, - render: async (name, args, context) => await vite.transformIndexHtml(context.handler.context.req.url, html), + async render(name, args, context) { + const htmlToRender = html.replace(INJECT_MARKER, ``); + return await vite.transformIndexHtml(context.handler.context.req.url!, htmlToRender); + }, }); // eslint-disable-next-line consistent-return diff --git a/packages/ui-next/package.json b/packages/ui-next/package.json index a517bbfc8..30d7d39b8 100644 --- a/packages/ui-next/package.json +++ b/packages/ui-next/package.json @@ -8,14 +8,14 @@ "preview": "vite preview" }, "dependencies": { - "@vitejs/plugin-react": "^6.0.1", + "koa2-connect": "^1.0.2", "react": "^19.2.5", "react-dom": "^19.2.5" }, "devDependencies": { "@types/react": "^19.2.14", "@types/react-dom": "^19.2.3", - "@vitejs/plugin-react-swc": "^4.3.0", + "@vitejs/plugin-react": "^6.0.1", "vite": "^8.0.10" } }