diff --git a/next.config.ts b/next.config.ts index ae1d9e0..b24ead9 100644 --- a/next.config.ts +++ b/next.config.ts @@ -1,9 +1,19 @@ +import { execSync } from "node:child_process"; import type { NextConfig } from "next"; +// When the code this copy runs was last changed (its newest commit), for "A new version of broke is ready". +let builtFrom = ""; +try { + builtFrom = execSync("git log -1 --format=%cI", { stdio: ["ignore", "pipe", "ignore"] }).toString().trim(); +} catch { + /* no git (a download without history): the update check stays quiet */ +} + const nextConfig: NextConfig = { devIndicators: false, distDir: process.env.NEXT_DIST_DIR || ".next", // a production build can sit beside the running dev server serverExternalPackages: ["pg"], + env: { BROKE_BUILT_FROM: builtFrom }, // Keep pages you visited for 3 min, so going back or switching tabs is instant. Every edit calls router.refresh(), // which drops the cache, so changes still show at once. experimental: { staleTimes: { dynamic: 180 } }, diff --git a/scripts/start.mjs b/scripts/start.mjs index 121b217..8575710 100755 --- a/scripts/start.mjs +++ b/scripts/start.mjs @@ -2,7 +2,7 @@ // Starts broke on this computer and opens it. Before the keys are in, it runs in development mode: the setup page saves // keys and the server picks them up without a restart. After that it runs the faster production build. import { spawn, spawnSync } from "node:child_process"; -import { existsSync, readFileSync } from "node:fs"; +import { existsSync, readdirSync, readFileSync, statSync } from "node:fs"; import { dirname, join } from "node:path"; import { fileURLToPath } from "node:url"; @@ -34,7 +34,14 @@ if (await fetch(url, { redirect: "manual" }).then(() => true, () => false)) { openIt(); process.exit(0); } -if (ready && !npm("run", "build")) process.exit(1); +// The last build is reused when nothing it was built from has changed since: code, packages, settings or keys. +const newest = (p) => !existsSync(p) ? 0 : statSync(p).isDirectory() + ? Math.max(0, ...readdirSync(p, { recursive: true }).map((f) => statSync(join(p, String(f))).mtimeMs)) + : statSync(p).mtimeMs; +const built = existsSync(".next/BUILD_ID") ? statSync(".next/BUILD_ID").mtimeMs : 0; +const stale = Math.max(...["src", "public", "package-lock.json", "next.config.ts", ".env", ".env.local"].map(newest)) > built; +if (ready && !stale) console.log("Nothing changed since the last build: starting it."); +if (ready && stale && !npm("run", "build")) process.exit(1); const next = join("node_modules", ".bin", win ? "next.cmd" : "next"); // Listens on this computer only, which is what makes saving keys from the page safe (writeGate checks the rest). const args = ready ? ["start", "-H", "127.0.0.1", "-p", port] : ["dev", "--turbopack", "-H", "127.0.0.1", "-p", port]; diff --git a/src/app/(app)/accounts/page.tsx b/src/app/(app)/accounts/page.tsx index 72be2ca..dac943c 100644 --- a/src/app/(app)/accounts/page.tsx +++ b/src/app/(app)/accounts/page.tsx @@ -60,6 +60,12 @@ export default async function Accounts() { supabase.from("accounts").select("id, name, custom_name, mask, type, subtype, current_balance:balance, currency, home:home_balance, included").eq("manual", true).eq("user_id", user!.id), ]); const items = (data ?? []) as unknown as Item[]; + // How far back each bank's transactions go, so a short history doesn't read as a strange month. + const since = new Map(await Promise.all(items.map(async (i) => { + const ids = i.accounts.map((a) => a.id); + const { data: first } = ids.length ? await supabase.from("transactions").select("date").in("account_id", ids).order("date").limit(1) : { data: [] }; + return [i.id, (first?.[0]?.date as string | undefined) ?? null] as const; + }))); const manualItem = { id: "manual", institution_name: "Added by you", institution_logo: null, institution_color: null, last_synced_at: null, accounts: [] }; const all = [ ...items.flatMap((i) => i.accounts.map((a) => ({ ...a, item: i }))), @@ -164,7 +170,7 @@ export default async function Accounts() {
{item.status && item.status !== "ok" ? item.status === "ITEM_LOGIN_REQUIRED" ? "Sign in to your bank again to keep syncing." : (item.error ?? "This connection stopped syncing.") - : `${holds(item.accounts) ? `${holds(item.accounts)} · ` : ""}${plural(item.accounts.length, "account")} · synced ${item.last_synced_at ? ago(item.last_synced_at) : "never"}`} + : `${holds(item.accounts) ? `${holds(item.accounts)} · ` : ""}${plural(item.accounts.length, "account")}${since.get(item.id) ? ` · history from ${new Date(`${since.get(item.id)}T12:00:00Z`).toLocaleDateString("en-US", { month: "short", day: "numeric", year: "numeric", timeZone: "UTC" })}` : ""} · synced ${item.last_synced_at ? ago(item.last_synced_at) : "never"}`}
diff --git a/src/app/(app)/layout.tsx b/src/app/(app)/layout.tsx index 6eddb9f..08fe4e8 100644 --- a/src/app/(app)/layout.tsx +++ b/src/app/(app)/layout.tsx @@ -11,12 +11,14 @@ import { countryOf } from "@/lib/countries"; import { getUser, userTz } from "@/lib/data"; import { fmtFor, todayIn } from "@/lib/format"; import { modeOf } from "@/lib/privacy"; +import { updateReady } from "@/lib/updates"; import { createClient } from "@/utils/supabase/server"; // Accounts made before country support are treated as US (countryOf default) and get a dashboard nudge instead. const FIRST_RUN_SINCE = "2026-10-22"; export default async function AppLayout({ children }: { children: React.ReactNode }) { + const update = await updateReady(); const [{ user }, tz] = await Promise.all([getUser(), userTz()]); const profile = user?.user_metadata?.profile; // created_at isn't in the token, so only users with no country pay for the full user record. @@ -47,6 +49,7 @@ export default async function AppLayout({ children }: { children: React.ReactNod