Skip to content

Make the read/render path tree-shakeable to a tiny edge bundle (no server engine) #63

Backlog

Description

@jherr

Motivation

Deploying the blog to an edge runtime (Kody/workerd) forced us to bypass the CMS entirely on the read path — hand-rolled SELECT … FROM cms_documents + a hand-written renderer — because importing anything from @tanstack/cms-core/server dragged in the whole engine (~1 MB) and wouldn't instantiate reliably. A read-only page (/, /post/:id) should be serveable with the CMS's own abstractions in a tiny bundle.

Why it's heavy today

  • @tanstack/cms-core/server is a barrel — importing getStorage/queryDocuments pulls dispatcher, auth, media, interfaces, scheduling, etc.
  • The embedded PGlite default is referenced via a literal import('@tanstack/cms-store-postgres/pglite') in storage.ts, so the WASM runtime (with eval) lands in the graph even when a different store is configured.
  • nodeImport / runtimeImport use non-literal import(specifier), which defeats edge bundlers' static analysis and is outright rejected by strict server sandboxes (workerd).
  • store-postgres statically pulls node:fs / node:path (legacy-store + export paths) that a reader never exercises.
  • Module-scope zod/config construction adds instantiation cost.

Proposal

  • A dedicated lightweight read entry (e.g. @tanstack/cms-core/read) exposing published-document queries + the block/field renderers, with no engine side-effects, no embedded-store reference, no node:*, no non-literal import(), no WASM.
  • Make the embedded PGlite default fully opt-in (no static/literal reference unless configured).
  • Replace the dynamic-import helpers with literal, tree-shakeable imports.
  • Ship an "edge read" recipe in docs.

Acceptance

  • A worker importing only the read entry + renderers bundles to < ~50 KB, with zero node:*, WASM, eval, or non-literal import() — verified by a bundle-audit test.
  • The render path produces the same HTML a hand-rolled renderer does for the standard block types.

Context

Came out of deploying a TanStack CMS blog to Kody: the read path is great on the edge, but only after dropping the engine. This issue is the "make reads first-class on the edge" half. The companion platform-side blocker (running the write/admin engine on Kody) is tracked separately.

Activity

  1. added
    enhancement
    state:needs-triage
    risk:contract
    on Dec 2, 2026
  2. jherr commented on Dec 2, 2026

    @jherr
    ContributorAuthor

    Companion platform-side blocker (running the write/admin engine on Kody): #64. This issue is the edge-reads half.

  3. cms-triager commented on Dec 2, 2026

    @cms-triager
    handoff:
      from: triager
      to: human
      issue: 63
      pr: null
      attempt: 1
      risk: contract
      risk_reasons: [author-not-verified-maintainer]
      summary: Not triaged; author association is CONTRIBUTOR and the maintainer who applied state:needs-triage could not be verified
      acceptance:
        - "blocked: a maintainer (OWNER/MEMBER/COLLABORATOR) must confirm this issue should be triaged"
      out_of_scope: []
      notes_for_next: >
        Labels left untouched. To proceed, a maintainer should re-apply state:needs-triage
        (or comment confirming). Preliminary read for whoever triages it: this is a big feature
        and will likely be split into child issues: (1) a new side-effect-free `@tanstack/cms-core/read`
        entry plus a bundle-audit test, (2) making the PGlite default opt-in, i.e. removing the literal
        import('@tanstack/cms-store-postgres/pglite') from storage, (3) replacing the non-literal
        nodeImport/runtimeImport helpers, (4) dropping static node:fs/node:path imports from store-postgres reads,
        (5) an edge-read docs recipe. Parts 2 and 4 touch store-postgres/src/** and storage code, so they are one-way
        (persisted-shape/storage paths). The new export path is contract. The existing risk:contract label is a floor, not a ceiling.

    I didn't triage this issue. GitHub shows the author jherr with association CONTRIBUTOR, and I couldn't confirm that a repository maintainer applied state:needs-triage. Under the station rules, a maintainer needs to authorise triage before I proceed. If you are a maintainer with private org membership, set your membership to public or have a collaborator re-apply state:needs-triage, and this will be picked up again.

  4. jherr commented on Dec 2, 2026

    @jherr
    ContributorAuthor

    Investigation: why the read path is 1.7 MB

    Bundled just queryReadableDocuments / getStorage from @tanstack/cms-core/server (esbuild, workerd conditions, node:*/react external):

    • 1.7 MB, 618 input files. Importing the symbol directly from its module (bypassing the server.ts barrel) is still 816 KB / 337 files — so it's module layering, not the barrel.
    • Transitively pulls, for a read: PGlite (~475 KB, WASM+eval), QuickJS @jitl/quickjs-wasmfile (~290 KB, the AI code-mode isolate), @tanstack/ai (~240 KB), MCP SDK+core (~240 KB), zod v3+v4 (~380 KB), sucrase (~90 KB, a TS compiler).
    • Offenders in the output: eval ×4, non-literal import() ×2, node:async_hooks|crypto|fs|path.

    First-party bridge edges (the cut points)

    • core/src/server/storage.ts → @tanstack/cms-store-postgres/pglite (embedded default store → WASM/eval). Literal import(), so bundlers include it.
    • core/src/ops.ts → core/src/lib/webmcp.ts → @modelcontextprotocol/sdk; and the AI/agent/code-mode chain → @tanstack/ai → QuickJS + sucrase.
    • access-context.ts (the read fn) → ../config / ./access, whose transitive value-graph reaches the above. config.ts is the hub nearly everything imports.

    Plan

    1. Layer a pure read/query core that depends only on schema/types + the storage interface — no ops.ts, no lib/webmcp, no AI/agent/code-mode, no embedded store.
    2. Embedded PGlite default = provider-injected, not a static/literal import in storage.ts (so WASM/eval never enter a graph that didn't configure it).
    3. AI / MCP / code-mode behind lazy boundaries — only loaded when those features actually run, never on the read path.
    4. New @tanstack/cms-core/read entry exporting the slim query + renderers.
    5. Bundle-audit test (CI): a worker importing only /read bundles < ~50 KB with zero node:*, WASM, eval, or non-literal import().

    Branch: feat/edge-read-entry. This is a careful module-layering change to central modules (config.ts/access-context.ts/storage.ts) — public-contract (new entry) + needs a changeset — so it lands incrementally with the bundle-audit test as the guardrail.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementrisk:contractstate:needs-triage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions