spliit icon indicating copy to clipboard operation
spliit copied to clipboard

Tracking: coordination of merging forks

Open BastiOfBerlin opened this issue 3 months ago • 0 comments

I've been running a fork of Spliit for a while and, now that I have maintainer access here, I'd like to contribute the work back. It's a lot — ~90 commits across ~125 files — so rather than one unreviewable PR, this issue tracks a sequenced series of small ones.

Nothing below lands without normal review. If any individual item isn't wanted upstream, it just stays in the fork; the series is designed so each PR can be dropped without blocking the others.


✅ The urgent one is closed

Expense.originalAmount was holding two different units on main — #425 converted the expense form to write minor units without a data migration, so rows written before each instance deployed it were still in major units and displayed 100× too small. #550 merged the backfill, so this is done.

My fork had a version of this migration too. #550's is better and mine isn't going anywhere near upstream.

Mine does a blanket originalAmount * 100, which assumes every row predates the cutover — so it would double-convert every row written after #425 shipped. It also hardcodes ×100 rather than 10^decimals, making it wrong for BHD, KWD, JOD, OMR and TND regardless. #550 classifies each row by its own values instead, which is the only thing that works when the cutover happens at each self-hoster's deploy time.


✅ Phase 1 — merging existing community PRs — done

Several open PRs here were already carried in my fork and had been running in production for months. These were merged as the originals so the authors keep their attribution, before layering anything of mine on top. All eight are in.

  • [x] #515 — frankfurter.app → frankfurter.dev/v1 (currency conversion was broken on main)
  • [x] #516 — currency data
  • [x] #505 — Docker Compose documentation
  • [x] #491 — restore keyboard navigation in the category and currency selectors
  • [x] #500 — QR code in the share popover, and a camera scanner for joining (landed as #558)
  • [x] #486, #507, #521 — add COP, MKD, MYR
  • [x] #503 — enable Next 16's reactCompiler
  • [x] #219 — build-image.sh: POSIX parsing instead of node -p, so the image builds on hosts without Node

#500 needed a rebase, which went in as #558. @theo-engels' commit was cherry-picked byte-identical; what conflicted was only the lockfile, whose diff was cut from d3b151e back in January, so I regenerated it against main instead of replaying it — after #556 that seemed the safer habit.

Two things from #558 are still open, both flagged in its body:

  • html5-qrcode is 375 kB minified and statically imported by qr-code-scanner.tsx, so it lands in the groups-route chunk whether or not anyone ever scans. A next/dynamic import behind the scan-mode toggle would defer it until someone taps "Scan QR" — happy to send that as a follow-up.
  • The camera path and the PNG download (canvas.toDataURL on an SVG-sourced image, historically fiddly in Safari) still want a check on real hardware.

#219 got a small follow-up from me, merged as #563. The parser it landed with was grep name | awk '{print $2}', which worked only because name and version each happened to appear on exactly one line of package.json. grep is unanchored and prints every match, so adding a dependency like standard-version turned SPLIIT_APP_NAME into two lines and malformed the docker build -t — I reproduced that rather than assuming it, and confirmed it was latent rather than already broken. #563 anchors on "key": with a grep -m1 plus one sed -E, keeping the no-Node-required property that made #219 worth merging.

A note on all of these: in every case the merged version differed from what my fork had, and it went a different way each time. #491's was better than mine (upstream nests <CommandEmpty> inside <CommandList> — cmdk's documented structure — while mine left it a sibling, so my empty state never rendered). #219's was less sturdy. #503 was a wash, except for the comment pointing at vercel/next.js#58019 that I'd dropped and have now restored. And #500 turns out not to be the same feature as mine at all — see below. Worth a diff every time.

On #500 specifically: two different features, one shared component

I'd assumed my fork had cherry-picked #500. It hadn't — I arrived at a QR code independently, and the two implementations differ:

#500 my fork
Where the QR lives its own dialog behind a QrCode button inline in the share popover, always visible
Download as PNG yes no
Logo embedded in the QR yes no
Camera scanner (scan to join) yes, via html5-qrcode no
Deps added qrcode.react, html5-qrcode qrcode.react

The scanner half is the strongest part of #500 and nothing of mine competed with it. On the display half I went with #500's dialog, and my fork's inline QR came back out — one design, not two. What survives from my side is the hardening, which shipped with #558:

  • URL parsing. new RegExp(${window.location.origin}/...) interpolates the origin unescaped. Replaced with new URL(input, window.location.origin) plus an origin check. This also tightens #500 rather than just tidying it: its relative-URL fallback, match(/\/groups\/([^/?]+)/), matched any host, so https://evil.example/groups/x would have been accepted. Resolving relative input against the current origin keeps the scanned-QR case working while absolute links keep their own origin and still fail the check.
  • The scanner couldn't be retried after a denial. The start button rendered only while hasPermission === null, so one dismissed browser prompt left the error message as the only UI until the popover was closed and reopened.
  • marginSize instead of includeMargin, deprecated in qrcode.react 4, plus explicit colours and a title — the QR is rendered over a themed background, so it shouldn't inherit one.
  • Tooltips on the copy and share buttons, which had none. en-US only, so Weblate picks the keys up normally.

Phase 2 — the fork's own work

Grouped so that follow-up fixes are folded into what they fix, and ordered so the risky pieces come after the cheap ones.

✅ Fixes and hardening — all merged

  • [x] fix: honour locale week start when grouping expenses and activity — #559
  • [x] security: harden AI extraction, CSV export, and workflows — #560
  • [x] fix: split every expense the same way everywhere — #562

main now has one apportionment behind the balances tab, the totals and the CSV export, and 101 tests across 7 suites where it had 27 across 2 — and as of #564, CI actually runs them. Everything below now lands against a real gate, which was the point of taking that one early.

#564 also raised the TypeScript target off es5, so the TS2802 workarounds I wrote around in #562 are no longer needed in anything built from here. I've left the existing Array.from / Map.forEach code alone rather than churning it.

The #219 follow-up described above also landed, as #563.

Features

  • [x] feat: global balance summary across all groups — implements #509, #583
  • [x] feat: PWA service worker with offline assets and update prompt — #587
  • [x] feat: expand group stats — spending by participant / category / recurring / over time, #584
  • [x] feat: stats date range and expense drill-downs — #586
  • [x] feat: settle up in a currency other than the group's — #588

Wave 2 is complete — all five features are merged.

Toolchain and dependencies

  • [x] chore: CI and lint baseline — #564
  • [x] deps: routine updates — #576, and far smaller than I implied here. See the correction below.
  • [x] deps: major framework upgrades — #589. Tailwind 4, zod 4, TypeScript 6, jest 30, lucide-react 1, openai 6, React 19 types, Prisma 7 with the pg driver adapter, plus the compilerOptions.types change and the generate-currency-data fix. 41/41 on your E2E suite.

Wave 3 is complete. With #589 merged, package.json is byte-identical between my fork and main for the first time since the fork point — the remaining delta is now entirely self-hosting and delivery, below.

A third correction, and this one changed the PR. I had openai queued for the self-hosting PR, on the grounds that bumping an SDK with no test coverage buys nothing. It turns out not to be optional: openai 4 declares peerOptional zod@"^3.23.8", so zod 4 and openai 4 cannot resolve together and npm install fails outright. I only caught it because I dry-ran each commit in isolation — my first zod commit carried a lockfile npm had produced by skipping re-resolution against a warm node_modules, and it would have failed for anyone installing clean. Worth knowing generally: a successful npm install in an existing tree does not prove the lockfile resolves.

Two things the major-upgrades PR needed that weren't on my list: TypeScript 6 breaks npm run generate-currency-data via the new TS5011 diagnostic (fixed with an explicit rootDir; regenerating returns currency-data.json byte-identical, which re-verifies #557 for free), and Prisma 7 makes src/lib/api.ts exporting randomId a build failure, because two client components import it and it now drags pg into the browser bundle.

Two corrections to earlier versions of this list.

I had npm run generate-currency-data down as broken on main. It isn't — src/scripts/generateCurrencyData.ts is byte-identical between my fork and main, and the TS5011 I was seeing comes from my fork's TypeScript 6. It moves to the major-upgrades PR, where it belongs.

I also described deps: routine updates as folding nine Dependabot PRs from my fork. It doesn't, because there was almost nothing to fold. npm ci installs what the lockfile pins, carets float, and main's lockfile is already current — @trpc/server is on 11.18.0 stable despite the manifest naming an rc, next is on 16.3.1 despite ^16.0.7, @tanstack/react-query on 5.101.4 despite ^5.59.15. Several of my fork's declared ranges were behind what you already ship. What's left is the six a caret range was genuinely blocking, plus dropping uuid, which nothing imports.

This shrinks the major-upgrades PR too: Next 16.3 is already installed here, so it's documentation rather than an upgrade. Tailwind 4, zod 4, TypeScript 6, jest 30, lucide-react 1 and Prisma 7 are the ones that are actually real — I checked each against the lockfile rather than the manifest.

Self-hosting and delivery

  • [x] feat: configurable OpenAI endpoint, models, and structured outputs — #590. Structured outputs on both AI paths, configurable model names, and a CRLF fix that was a live bug here. 18 new tests, since neither path had any. See the correction below.
  • [x] feat: runtime-configurable feature flags and BASE_URL for prebuilt images — #591. The same argument #548 makes for the analytics vars ("read on the server so a single image stays configurable at container start"), applied to the ENABLE_* flags, BASE_URL and DEFAULT_CURRENCY_CODE, which are still NEXT_PUBLIC_ and bake at build time. Additive: the old spellings keep working, and the runtime ones win when both are set.

On that one, the verification is the part worth reading. "One build, configured at start" is not something type-checking can confirm, so I built once with every flag off and started that same build twice: with no runtime variables the sitemap points at localhost, the new-group currency is USD and the receipt button is absent; with them set it is spliit.example.com, EUR, and the button is there. Then a second build using only the old NEXT_PUBLIC_* spelling, to test the compatibility claim rather than assert it — that deployment behaves exactly as it does today, and adding runtime variables on top overrides it as documented.

That found a bug in my own first attempt, and one my fork has been shipping for months: BASE_URL had no effect on robots.txt or sitemap.xml. They are the only two statically prerendered routes in the app, so they capture the build-time URL no matter what the container is started with. Both now render per request. Every other route was already server-rendered on demand, which I checked against the build's route table rather than guessing.

A fourth correction, and it changed this PR's headline. I had this down as "adds OPENAI_BASE_URL so self-hosters can point at a local provider". That was wrong: the OpenAI SDK already falls back to process.env.OPENAI_BASE_URL when no baseURL is passed, so redirecting the endpoint works on main today — I confirmed it by pointing unmodified main at a stub endpoint and watching the request arrive. What actually blocks an alternative provider is the hardcoded model name: the redirected request asks it for gpt-3.5-turbo. So the PR adds the two model variables and merely declares OPENAI_BASE_URL in the env schema, so existing behaviour gets documented and validated. Worth checking whether a library already does the thing before claiming to add it.

Relatedly, I had max_tokens down as "rejected by newer models" — true, but it sits on the category call, which is pinned to gpt-3.5-turbo where it's accepted. Nothing is broken today; it breaks the moment the model becomes configurable. The category model does have to move, though, because json_schema is unsupported before gpt-4o-2024-08-06. I defaulted it to gpt-5-nano, the model your receipt path already uses, rather than picking something this repo has never run — but that default is yours to overrule.

One live bug did come out of it. An .env saved with Windows line endings gives every value a trailing \r, so ENABLE_...=true parses as "true\r" and the feature is silently off with no error anywhere — and an OPENAI_API_KEY ending in \r fails auth with a 401 that points at the key rather than at the file. Reproduced both ways; it's the first commit.

  • [x] build: standalone runtime image — #592 . output: 'standalone' for a smaller runtime image. #549 already landed the multi-arch half, which my fork had arrived at independently, so that part is dropped.

I finally have a Docker daemon, so this one is measured rather than argued — and it retires the "not verified: docker build" caveat that every previous PR in this series carried. Same commit, same base image, no cache: 1.6 GB → 670 MB uncompressed, 316 MB → 143 MB compressed. It is almost entirely one layer: the production node_modules is 1.05 GB, and the traced server that replaces it is 74.8 MB.

More usefully, it is verified by running the artefact: migrate deploy against an empty PostgreSQL 16 applies the whole history, readiness returns 200, and the E2E suite passes 41/41 against the container instead of against npm run start. Restarting that same image with BASE_URL and DEFAULT_CURRENCY_CODE set changes robots.txt, the sitemap and the new-group currency, so #591's runtime configuration survives the standalone build.

One regression came out of that, which I would not have found by reading the diff: Next.js copies .env into .next/standalone. The build stage does COPY scripts/build.env .env, so my first image shipped the mocked build values — a Postgres URL pointing at db, placeholder S3 and OpenAI credentials — inside the published image, which today's image does not do. Container config still wins, so the risk isn't a broken deployment; it's the quiet one, where a variable an operator forgot to set resolves to a build placeholder instead of failing. Deleted in the build, folded into the commit that caused it.

One thing I deliberately did not fix: the Prisma CLI stage is now the biggest layer at 264 MB, and roughly 140 MB of that is Prisma Studio and prisma dev — @prisma/studio-core, effect, @electric-sql, elkjs, react-dom — pulled in through prisma's regular dependencies, so --omit=optional doesn't drop them. migrate deploy only needs @prisma/engines and @prisma/config. Pruning it would mean hand-listing package directories to delete, which breaks silently on the next Prisma upgrade, so I've left it as a flagged follow-up rather than smuggling it in here.


On translations

My fork carries machine translations for ~20 locales alongside its new UI strings. Given #457 and the Weblate round-trip, I'll strip those and ship en-US only, so translators pick the new keys up normally. src/i18n/request.ts deep-merges every locale over en-US, so nothing breaks in the meantime.

One thing that needs a second opinion

Prisma 7. It moves connection URLs out of schema.prisma into a prisma.config.ts and requires an explicit driver adapter, which changes how every deployment connects to Postgres. It's the last commit in the major-upgrades PR and nothing depends on it, so splitting it out is one rebase.

To be clear about what I can and can't stand behind there: prisma migrate deploy applies the full migration history to an empty database under Prisma 7, and it also works from a production-only install — the exact tree the runtime stage has. The same two environment variables are read in the same order, so no self-hoster changes any configuration. What I have not run is docker build itself, because there's no Docker daemon where I work. The Dockerfile changes are three targeted edits and each is reasoned from a behaviour I tested outside the image, but that build is the one check the PR needs from someone else.

The E2E suite changes how the rest of this series gets verified

#577/#578/#580 are the most useful thing to happen to this plan since the Weblate switch. Everything from here on gets run in a browser before I send it, not just type-checked.

I can't use scripts/e2e.sh where I work — no Docker daemon — but playwright.config.ts honours E2E_BASE_URL, so pointing the suite at a locally built app and a real Postgres 16 runs the same specs against the same app. Two things came out of that:

My fork's main passed all 26 of your tests when I measured it at the time of #580 (the suite has since grown, partly from this series). That mattered most for the major-upgrades PR — and that PR has now been measured directly rather than by proxy: 41/41 on the branch itself, with Prisma 7 and the pg driver adapter, Tailwind 4, zod 4 and TypeScript 6, against a real Postgres 16 with the migrations applied from empty. The question that PR really has to answer is "does this break how deployments reach Postgres", and it's answered with a run rather than an argument.

One thing you may or may not have intended: e2e.yml triggers on workflow_dispatch and push: tags: ['*'], so the suite doesn't run on pull requests. A PR that breaks it goes green and surfaces when you cut a tag. Adding pull_request would close that, at the cost of an image build plus a browser run per PR — a real CI-minutes trade, so I've left it alone rather than slipping it into an unrelated PR. Happy to send it as a one-liner if you want it.

Already done

  • [x] Synced my fork with main nineteen times, through 7824fb4. One finding worth passing on: [email protected] declares sharp: ^0.35.3 in optionalDependencies, so anyone pinned below that gets a second full copy of sharp and all its platform binaries nested under node_modules/next. #543's bump fixed that here.
  • [x] Cross-checked currency-data.json after #557. My fork had regenerated it independently from currency-list; comparing the two across all 24 locales × 34 codes gives zero value differences, so #557's repair is correct and complete. (The only delta was key ordering — appended vs alphabetical.) The JSON.stringify(..., null, 2) change in #557 is what made that diff readable at all; thanks for that.

BastiOfBerlin avatar Aug 13 '26 11:08 BastiOfBerlin