#7237·tinacms

⚡ Epic: Prebuilt admin + runtime split — stop shipping the editor to every site

Author: wicksipediaCreated Jul 14, 2026Updated Oct 1, 2026
Labelsperf

On hold. Don't size or start Phase 1 or Phase 2 yet. v3 is in bug-fix-only support mode, and since this was written the v4 plan has dropped the build and dev commands, so the site's own Vite compiles the admin (https://github.com/tinacms/tinacms/blob/main/packages/v4/README.md). A prebuilt admin shell is planned for v4 but is not a priority. v4 is modular, so the shell first needs a way to load each site's local plugins, which is non-trivial. When this is picked up, rewrite Phase 1 and Phase 2 against v4 paths before sizing anything. Phase 0 and the mermaid lazy-load have shipped, and every scenario B item listed below has since merged or closed.


Tracklist

Phase 0 - baselines (land first)

Phase 1 - prebuild the shell → scenario C (-68.3 MB)

Browser-payload wins (independent, main-safe)

Phase 2 - the split → scenario D (-320.0 MB, v4)

Hard edges: https://github.com/tinacms/tinacms/issues/7240 → https://github.com/tinacms/tinacms/issues/7242 → https://github.com/tinacms/tinacms/issues/7243 → https://github.com/tinacms/tinacms/issues/7244; https://github.com/tinacms/tinacms/issues/7241 → https://github.com/tinacms/tinacms/issues/7243; https://github.com/tinacms/tinacms/issues/7243 + https://github.com/tinacms/tinacms/issues/7244 → https://github.com/tinacms/tinacms/issues/7248 → https://github.com/tinacms/tinacms/issues/7249. Parallel lanes: { https://github.com/tinacms/tinacms/issues/7238, https://github.com/tinacms/tinacms/issues/7239 } · { https://github.com/tinacms/tinacms/issues/7240, https://github.com/tinacms/tinacms/issues/7241 } · { https://github.com/tinacms/tinacms/issues/7245, https://github.com/tinacms/tinacms/issues/7246, https://github.com/tinacms/tinacms/issues/7247 }.


Problem

Every tinacms build compiles the entire admin app - 43k LOC of editor - with vite, per project, on the user's machine, with vite's dependency cache force-disabled every run (packages/@tinacms/cli/src/next/vite/index.ts:198-203, optimizeDeps.force: true). To make that possible, the user installs the full editor toolchain: @tinacms/app ships 15 runtime dependencies including monaco (73 MB) and typescript (23 MB), and tinacms ships 81 runtime dependencies (packages/tinacms/package.json) - mermaid, lucide, Plate, Radix, date-fns - into every site that only needs useTina and TinaMarkdown at runtime.

The spike (spike/prebuilt-admin, 87ec040ad, see SPIKE.md on that branch) proved the alternative end-to-end: prebuild the admin shell once, in our CI; per-project, compile only the user's config with esbuild. Result: the per-project build drops from a full vite compile to 608 KB / 33 ms of esbuild, and a real custom field in the real kitchen-sink saved a real change to disk through the real GraphQL backend, served under a basePath the shell never saw at build time.

The measured ladder (real npm installs of an Astro site - do not re-derive, these are the numbers)

Scenario Installed node_modules Δ
A - baseline as published today 1037.8 MB -
B - + the 5 already-open dependency-hygiene PRs 795.7 MB -242.1 MB
C - + prebuilt admin (this epic, phase 1) 727.4 MB -68.3 MB
D - + runtime split (this epic, phase 2) 407.4 MB -320.0 MB

Astro's own floor with no Tina at all: 154.4 MB. Total A→D: -630 MB (61%).

Two honesty notes, so nobody quotes the wrong number later:

  1. The often-quoted 1412 MB baseline no longer reproduces. It was real when measured: @tinacms/cli exact-pinned [email protected] while 3.10.1 had shipped, so npm nested 3 copies of tinacms/mermaid/date-fns. Versions have since coincidentally realigned. https://github.com/tinacms/tinacms/pull/7213 (publish ranges instead of exact pins) therefore measures $0 today - it is regression prevention, not a size win. It stops the next release from re-nesting 3 copies. The size-baseline harness (first child issue) exists precisely because this class of drift is invisible until someone measures.
  2. Prebuilding alone is only -68 MB. Its real value is that it is the precondition for the -320 MB split: as long as the CLI must compile the editor on the user's machine, the editor and its 81-dep closure must be installed on the user's machine. Do not sell phase 1 on its own delta.

What's already done (scenario B) - link, don't re-plan

All verified open as of 2026-07-14; no new work in this epic covers them:

What this epic adds

Phase 0 - baselines first. The spike's four traps all compiled clean and failed silently in a browser; the 1412→1037 drift went unnoticed until re-measured. Before any risky change lands: (a) a size-baseline CI harness that turns the table above into per-PR budgets, and (b) behavioural baselines - the first browser tests this repo has ever run against a production tinacms build output (today every Playwright suite boots tinacms dev), driven by a deliberately hostile fixture config.

Phase 1 - prebuild (scenarios → C). Productionize the spike per .spike-scope.md: the runtime seam in @tinacms/app, the Tailwind two-pass split, a real dist/ + manifest for @tinacms/app, the flag-gated CLI prebuilt path (with the frozen externals ABI - the one decision that can't be walked back cheaply), and a vite-free dev server. Measured value once default: -68.3 MB install, per-project admin build 33 ms instead of a full vite compile, and the CLI sheds its vite stack.

Phase 2 - the split (scenario D, v4). Extract the site runtime (useTina, TinaMarkdown, tinaField) so sites stop depending on the 81-dep editor package. -320.0 MB measured.

On the maintainer's four constraints - read this before filing more issues

  1. mermaid → optional (83 MB) and 2. posthog → optional, opt-out (42 MB) - these are the genuinely new work, and their meaning changes after the split. Once mermaid and posthog live in our prebuilt shell instead of the user's node_modules, "optional" stops being about disk (they're already off the user's disk - that's phase 2 doing its job) and becomes about what the browser downloads. So they are lazy-chunk problems in the shell / in packages/tinacms, not dependency-graph problems - and both can land on main today as browser-payload wins that carry into the shell automatically. Child issues below.
  2. lucide icons we use → bundled into the prebuilt shell and 4. Plate, Radix, dnd-kit, cmdk → bundled into the prebuilt shell - these are not extra work; they are the -320 MB. All four are editor-only dependencies of tinacms. The moment the editor ships inside the prebuilt shell and sites import the slim runtime package instead, they leave the user's node_modules automatically. No separate issues exist for them by design; they are acceptance criteria of the split issue.

What survives scenario D, so nobody files a bug about it: date-fns (38 MB) and @tinacms/mdx - both independently required by @tinacms/graphql on the server side. The typedoc → [email protected] duplicate is https://github.com/tinacms/tinacms/issues/7211, not this epic.


2. The baseline-test plan (files as child issues https://github.com/tinacms/tinacms/issues/7238 and https://github.com/tinacms/tinacms/issues/7239 - FIRST, before any risky work)

Maintainer's requirement, verbatim: "i want to have baseline tests so that i can discover regressions ahead of time." Two halves. Both land before the runtime seam does.

Ground truth about today's CI (verified 2026-07-14 against .github/workflows/):

  • No size measurement of any kind exists - no size-limit, bundlewatch, du, tarball checks. The only adjacent tool is publint --strict in lint:packages (root package.json:22), which validates export maps, not size. The 1412→1037 MB drift was invisible for exactly this reason.
  • No Playwright suite runs against a production build. All six playwright.config.ts files (playwright/tina-playwright, playwright/astro-init, four kitchen-sink examples) use dev servers as webServer.command; even playwright/tina-playwright's build script is tinacms dev -c "next build" - dev-mode Tina wrapping a Next build. The spike's four traps were all invisible to this setup by construction: they only exist in production output.
  • Runners are ubuntu + macOS (main.yml build matrix); zero Windows jobs.
  • turbo.json: test dependsOn: ["build", "types"] - package tests may assume dist/ exists. pnpm test runs per-PR (main.yml), turbo remote cache via TURBO_TOKEN.

(a) Size baselines - child issue https://github.com/tinacms/tinacms/issues/7238

What's measured (four metrics, one checked-in baseline file):

  1. Installed closure of a fixture site, via real npm. Pack every workspace package (pnpm -r exec pnpm pack - pnpm pack resolves workspace: protocols the same way publish does), publish the tarballs into a throwaway local registry (verdaccio) in the CI job, then npm install a minimal Astro fixture (tests/size-fixture/, mirroring the scenario the ladder was measured on) against that registry. Measure du -sk node_modules. npm deliberately, not pnpm - npm's nested-duplicate behaviour is the failure mode that produced 1412 MB; pnpm's store would hide it.
  2. Duplicate-copy watchlist - the sharpest check, and the one that would have caught the 1412 MB incident the day it happened: npm ls --all --json in the fixture, assert each watchlist package (tinacms, mermaid, date-fns, typescript, react, graphql, lodash) resolves to exactly one physical copy. This catches the symptom (nesting) regardless of cause; https://github.com/tinacms/tinacms/pull/7213 removes the known cause.
  3. Per-package unpacked size: npm pack --dry-run --json → unpackedSize for every publishable package (same discovery loop tests/build-verification.test.ts already uses).
  4. Admin output size: total bytes of public/admin/ after tinacms build on the kitchen-sink. Once the prebuilt path exists this splits into two budgets: shell dist/ size (in @tinacms/app) and per-project project.js size - the shell budget is also the regression guard for "something that was supposed to be external got re-bundled" (.spike-scope.md §2 Layer 3).

Where the baseline lives: tests/size-baselines.json, checked in. Numbers seeded from the measured ladder.

What fails the build: any metric exceeding baseline by >5% or >5 MB (whichever is larger - small packages need the absolute floor, big closures the percentage); any watchlist package with copy-count >1 fails unconditionally, no tolerance.

How a legitimate increase is re-baselined: pnpm size:update regenerates the JSON; the diff rides in the same PR, so the increase is reviewed as a visible number by a human, with a one-line justification in the PR description. Decreases >10% emit a warning prompting a re-baseline so wins get locked in too.

CI fit: one new job in main.yml (ubuntu only - size is platform-independent enough), triggered on PRs touching packages/** or pnpm-lock.yaml. Cost estimate: verdaccio boot + pack + npm install ≈ 2-4 min. Honest limitation: local-tarball publishing cannot reproduce registry-history interactions (the exact 1412 scenario needed an already-published stale version on npm); the duplicate-copy check covers the symptom anyway, and a scheduled (cron) variant of the same job running against the real registry covers the published state - same harness, two modes.

(b) Behavioural baselines - child issue https://github.com/tinacms/tinacms/issues/7239

Guiding fact from the spike: all four traps compiled clean and died only in a browser. (export * from CJS react → default-only namespace; CJS require() of an ESM external; uncovered tinacms subpaths; ./project.js resolving against the module instead of the document.) So: build-time contract assertions wherever a trap has a build-time signature; a real browser against production output for the rest. This carries .spike-scope.md §2 forward with one sharpening:

The sharpening - the prod-build browser suite lands FIRST, against today's vite build. .spike-scope.md slots the Playwright suite into PR4 (the prebuilt path). Instead: land playwright/prebuilt-admin/ now, with webServer = tinacms build + a static file server + the GraphQL API - running against the current production output. That gives the repo its first-ever prod-output browser coverage before a single line of prebuilt code exists, baselines today's behaviour, and then PR4 simply runs the identical suite a second time with the flag on. Every spec below is meaningful in both modes.

The nasty fixture (one hostile app in playwright/prebuilt-admin/, cloned from playwright/tina-playwright's layout - Next.js, so next/image is naturally available):

Ingredient Why it's there Source of the pattern
Custom field component colocated with the schema escape hatch, JSX through the seam examples/next/kitchen-sink tina/fields/color.tsx (spike-verified end-to-end)
A component importing next/image - a CJS dependency the killer: CJS require('react') against an ESM external (spike trap 2) SPIKE.md trap list
An arbitrary Tailwind class the shell never uses (e.g. aspect-w-9) plus bg-blue-500 proves the second Tailwind pass ran AND used Tina's theme (rgb(0,132,255), not stock) spike verification no. 3
A real media.loadCustomStore with dynamic import() documented pattern, exercises esbuild single-outfile + dynamic import packages/@tinacms/schema-tools/src/types/index.ts:~843-849 (JSDoc example)
authProvider: new UsernamePasswordAuthJSProvider() from tinacms-authjs/dist/tinacms ESM entry that drags in CJS next-auth/react - second CJS-bridge exercise .spike-scope.md §1.4
cmsCallback registering a createScreen screen plugin path; catches a second react-router-dom if the ABI misses it .spike-scope.md §1.1/§1.5
build.basePath: 'my-site' every URL bug the spike hit was basePath-shaped spike trap 4, .spike-scope.md §1.7

Specs (each names the trap it guards):

  • boot.spec - admin renders the collection list; window.__REACT_DEVTOOLS_GLOBAL_HOOK__.renderers.size === 1 (the CI-grade single-React assertion - trap 2's runtime form); zero console.error during boot (this alone would have caught traps 1-3, which all threw to console).
  • custom-field.spec - custom field renders, a save round-trips to disk (reuse examples/next/kitchen-sink/e2e/utils/admin-helpers.ts).
  • tailwind.spec - getComputedStyle on both fixture classes (trap 4's - the Tailwind trap's - runtime form).
  • basepath.spec - boot at /my-site/admin/ and at /my-site/admin without the trailing slash (the trap .spike-scope.md §1.7 found: the spike harness only ever served the trailing-slash form; next dev serves the bare form, document.baseURI becomes the parent, every relative asset 404s).
  • media.spec / auth.spec - media manager lists via the custom store; the custom auth provider's login screen appears.
  • Prebuilt-mode-only (added by child https://github.com/tinacms/tinacms/issues/7243): skew.spec - tampered manifest/env produces a readable error screen, not a white screen; under network throttling the 2 s asset watchdog (packages/@tinacms/app/index.html) doesn't false-fire on the now-async project fetch.

Build-time contract layers (land with the code they constrain, but specified here so they're one coherent plan):

  • Layer 0 - shell contract (vitest in @tinacms/app, runs post-build via turbo's test → build dependency): for every emitted vendor-* chunk, import() it in node and assert Object.keys(ns) ⊇ Object.keys(require(sourcePkg)) - export-name parity. Future-proof by design: React adding an export fails the test until the vendor list is updated, which is the desired behaviour. Plus: every subpath of packages/tinacms/package.json exports is either a vendor entry or on a snapshot-tested exclusion list (ABI completeness, .spike-scope.md §1.1); dist/manifest.json exists and its exposedModules matches the vendor entry set. Ships with child https://github.com/tinacms/tinacms/issues/7242.
  • Layer 1 - CLI build assertions (jest; precedent for running real esbuild in jest: packages/@tinacms/cli/src/next/config-build-error.test.ts): run the real project-chunk build with metafile: true and assert no node_modules/react/, node_modules/react-dom/, node_modules/tinacms/ path appears in metafile.inputs - "externals actually externalized" as a deterministic, browserless CI check. CJS-bridge tests including the namespace-interop case .spike-scope.md §1.4 caught (require('tinacms').AbstractAuthProvider must resolve - the spike's m.default ?? m heuristic returns undefined for it, because tinacms's default export is TinaCMSProvider2, packages/tinacms/src/index.ts:22). Tailwind two-pass assertions. Stage-D index.html string assertions (absolut