Skip to content

原型:Vite SPA 壳切片(去 Next 化成本验证) #94

Closed

Description

@JonasGao

Part of #88

Question

web/ 下 Vite + React + React Router v7 库模式壳,迁移 login + timeline 两个页面与 AuthGate/apiFetch 直连现有 Next API:去 Next 化的真实成本多大?next/font/Geist 与 build-info 的替代方案是什么?回答:SPA 化是不是机械替换。

Activity

  1. self-assigned this
    on Nov 5, 2026
  2. JonasGao commented on Nov 5, 2026

    @JonasGao
    CollaboratorAuthor

    结论(已验证,用户已采信)

    SPA 化是机械替换。 在「alias @ → 仓根 src/ + 95 行 next-compat shim」策略下,仓根 src/ 一行未改,login + timeline 两页连同 AppShell/AuthGate/SyncAllSources/ThemeProvider 全功能跑通:真实数据渲染、认证开/关双模式、trace 端到端、Geist 字体、暗色主题、SPA 客户端路由。壳的全部成本 ≈ 14 个新增文件 ~200 行。vite build 474ms 全绿(2445 模块零改动编译);认证关模式 0 console errors;认证开模式错误密码 inline error 带 trace 后缀,与 Next 版行为一致。

    产物:分支 prototype/vite-spa-shell(未推送)——web/ 全部代码 + docs/prototype/vite-spa-shell.md(成本表、12 条实证发现、验证矩阵、截图)。

    票面两个子问题的答案

    • next/font/Geist 替代:@fontsource-variable/geist + @fontsource-variable/geist-mono 自托管可变字重(woff2 每子集 12–29KB 打进 dist),:root 挂同名 --font-geist-* 变量即可,globals.css 与 DESIGN.md 设计系统零改动,实测 h1 计算字体栈 = --font-ui 定义原样生效。
    • build-info:构建期 git rev-parse 生成常量文件的模式在 Vite 下原样存活(web/scripts/gen-build-info.mjs 照搬根脚本,alias @/lib/build-info 接管;AppShell 实测显示 v0.1.0 · d6f07a2)。Go 侧对应物 = ldflags 注入。

    实证坑(详证见 findings 文档)

    ① 仓根 pnpm-workspace.yaml 只有 allowBuilds 没有 packages:——web/ 安装会被静默吸到根(原型用 --ignore-workspace 绕过);② Vite 必须 resolve.dedupe: ['react','react-dom'](pnpm 布局 + 预打包依赖的双 React 实例 → Invalid hook call);③ Tailwind v4 在 web/ 下必须显式 @source 指回仓根 src(否则类名静默丢失);④ react-router npm latest 已是 v8.5.1;⑤ Next 16 同目录单 dev-server 锁(第二个 next dev 拒启)。另:AuthGate 的 authEnabled 不能先渲染后探测——bootstrap 阶段无头 GET /api/auth/verify(200=认证关、401=认证开)零新增 API,Go server 侧语义同样成立。

    用户拍板(answer-board round 3)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions