Просмотр исходного кода

feat(ui): visible build stamp in the sidebar (#1250)

Sidebar shows the build's short git hash. #1214
Nacho 2 месяцев назад
Родитель
Сommit
2addf4eda0
3 измененных файлов с 21 добавлено и 0 удалено
  1. 2 0
      app/src/build.d.ts
  2. 6 0
      app/src/components/Layout.tsx
  3. 13 0
      app/vite.config.ts

+ 2 - 0
app/src/build.d.ts

@@ -0,0 +1,2 @@
+/** Hash corto del commit con el que se construyó el bundle (vite define). */
+declare const __NP_BUILD__: string

+ 6 - 0
app/src/components/Layout.tsx

@@ -315,6 +315,12 @@ function Sidebar({ collapsed, onToggleCollapse }: { collapsed: boolean; onToggle
       </nav>
       {/* Pie del sidebar (#981): indicador "En vivo" + boton de plegar en la
           misma fila (sustituye a la antigua tarjeta de estado del gateway). */}
+      {/* Sello de build (#1214): identifica el commit exacto que ejecuta el
+          navegador. Imprescindible para diagnosticar cachés y service
+          workers: una captura del usuario dice qué build ve de verdad. */}
+      <div className="px-3 pb-1.5 pt-0.5 text-[10px] font-medium tabular-nums tracking-wide text-text-secondary/50">
+        build {__NP_BUILD__}
+      </div>
       <div className="flex items-center gap-2 border-t border-border p-3">
         <LivePill />
         <button

+ 13 - 0
app/vite.config.ts

@@ -1,5 +1,17 @@
 import path from "path"
+import { execSync } from "node:child_process"
 import react from "@vitejs/plugin-react"
+
+// Sello de build visible en el sidebar: diagnostica al instante qué
+// código está ejecutando el navegador de cada usuario (#1214: "no veo
+// los cambios" era el service worker sirviendo el app shell viejo; con
+// el sello, una captura del usuario dice exactamente qué build ve).
+let npBuild = "dev"
+try {
+  npBuild = execSync("git rev-parse --short=8 HEAD", { encoding: "utf8" }).trim()
+} catch {
+  /* fuera de repo: deja "dev" */
+}
 import { defineConfig, type Plugin } from "vite"
 import { VitePWA } from "vite-plugin-pwa"
 
@@ -25,6 +37,7 @@ function goatcounterPlugin(): Plugin {
 
 // https://vite.dev/config/
 export default defineConfig({
+  define: { __NP_BUILD__: JSON.stringify(npBuild) },
   // Servido desde el backend Hono en la raíz del dominio → rutas absolutas.
   // (Con './' las rutas anidadas tipo /routers/:id rompen los assets al recargar.)
   base: '/',