Skip to content

fix: keep server-only AI/code-mode out of app client bundles (fixes base e2e) - #70

Merged
jherr merged 1 commit into
mainfrom
fix/config-client-bundle-leak
Dec 3, 2026
Merged

jherr merged 1 commit into
mainfrom
fix/config-client-bundle-leak

Conversation

@jherr

@jherr jherr commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

Fixes a regression from the capability-seams change (#68) and the base e2e flake it caused.

Root cause (not a flake — a deterministic crash)

#68 injected ai.runtime / interfaces.runtime as static top-level imports in app/base and app/prm's cms.config.ts. That config is isomorphic — router.tsx does import './cms.config', so it's in the client bundle. The static import … from '@tanstack/cms-core/interfaces-quickjs' (and /ai) pulled @tanstack/ai into the client, whose transitive partial-json@0.1.7 has a bad named export → the /setup page's JS threw SyntaxError at module eval → React never rendered the owner-setup form → locator.fill timed out at 90s. Vite's dep-optimizer cache made it look intermittent.

Fix

  • core: ai.runtime and interfaces.runtime now accept a server-only provider (() => Runtime | Promise<Runtime>) in addition to a value. cmsTools and interfaceRuntime() resolve it. New CmsAiRuntimeInput / InterfaceRuntimeInput.
  • base/prm: provide the runtimes via createServerOnlyFn / a dynamic import, so the opt-in entries (and their @tanstack/ai / QuickJS deps) load only on the server.
  • base e2e: health-gated globalSetup warms the SSR routes + retries: 2 on CI — defense-in-depth against genuine cold-compile.

Verification

base e2e 12/12 (was timing out) · core 661 · prm 10 · interface tests 17+4 · oxlint clean · core/api/base/prm typecheck.

Known follow-up (not in this PR)

storage: createPgliteStorage is still a static import in the isomorphic configs, so PGlite is bundled client-side. It imports cleanly (no crash, so CI is green), but it's bloat. A server-only storage injection path is more involved (resolveStorageAdapter is sync); worth a dedicated change — likely wiring setDefaultStorageFactory(createPgliteStorage) in each app's server entry instead of the isomorphic config.

🤖 Generated with Claude Code

…gression)

The capability-seams change injected `ai.runtime`/`interfaces.runtime` as
static top-level imports in base/prm's isomorphic `cms.config` (pulled into the
client via `import './cms.config'` in router.tsx). That dragged `@tanstack/ai`
into the client, whose transitive `partial-json` has a bad named export —
crashing the /setup page's JS so the owner-setup form never rendered (the
"flaky" base e2e was actually this deterministic crash).

- core: `ai.runtime` and `interfaces.runtime` now accept a server-only provider
  (`() => Runtime | Promise<Runtime>`); cmsTools / interfaceRuntime resolve it.
  New CmsAiRuntimeInput / InterfaceRuntimeInput types.
- base/prm configs: provide the runtimes via `createServerOnlyFn` / a dynamic
  import so the opt-in entries load only on the server.
- base e2e: health-gated globalSetup warms SSR routes + retries:2 on CI, as
  defense-in-depth against cold-compile.

base e2e 12/12 green; core 661; prm 10; interface tests 17+4. oxlint clean.

Known follow-up: the `storage: createPgliteStorage` static import still bloats
client bundles with PGlite (imports cleanly, doesn't crash) — needs a
server-only storage injection path (sync resolveStorageAdapter complicates it).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@changeset-bot

changeset-bot Bot commented Dec 3, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: b427cae

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@jherr
jherr merged commit ff095c5 into main Dec 3, 2026
7 of 10 checks passed
@coderabbitai

coderabbitai Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Explain Change →

Caution

Review failed

The pull request is closed.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@jherr
jherr deleted the fix/config-client-bundle-leak branch December 3, 2026 20:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant