Skip to content

feat(vite): bundle meta.gen stub + drop crashing chunk splits + add .deco.studio - #108

Merged
vibe-dex merged 1 commit into
mainfrom
feat/vite-plugin-stub-meta-and-fix-chunks
May 1, 2026
Merged

vibe-dex merged 1 commit into
mainfrom
feat/vite-plugin-stub-meta-and-fix-chunks

Conversation

@vibe-dex

@vibe-dex vibe-dex commented May 1, 2026

Copy link
Copy Markdown
Contributor

Summary

Three small extensions to `decoVitePlugin()` that absorb boilerplate both real-world Deco sites (casaevideo-storefront, baggagio-tanstack) were keeping in their own `vite.config.ts`.

# Change Replaces site-side
1 Stub `meta.gen.{json,ts}` to `export default {}` on client `deco-stub-meta-gen` inline plugin (~14 lines × 2 sites)
2 Drop `vendor-deco` and `vendor-commerce` chunk splits `site-manual-chunks` inline plugin (~25 lines × 2 sites)
3 Add `.deco.studio` to `allowedHosts` (when `DECO_SITE_NAME` set) `.deco.studio` entry in site `allowedHosts` lists

Detail

1. `meta.gen` client stub

`server/admin/meta.gen.json` is the admin schema bundle. It's server-only (the client receives pre-resolved blocks via the SSR payload), but Vite's dependency graph would still pull it into the browser bundle by default, adding 0.5-5 MB of dead weight.

Match is end-of-id (`endsWith`), scoped to non-entry imports (requires `importer`), so it can't accidentally stub a build target that points at meta.gen directly.

Casaevideo's inline plugin even has a comment:

`// TODO: move into decoVitePlugin in next @decocms/start release.`

This is that release.

2. Drop `@decocms/start` / `@decocms/apps` chunk splits

Rollup's `manualChunks` had `vendor-deco` and `vendor-commerce` rules that pushed framework + apps packages into separate chunks. They have circular re-exports (`apps` imports `start/sdk/cachedLoader`; `start/admin` imports from `apps`), and splitting them produces a chunk-load order that crashes at runtime ("undefined is not a function").

Both sites worked around this by overriding `manualChunks` in their own configs (with explicit comments calling out the circular-dep crash). Removing the broken rules from the framework default lets Rollup bundle them with the importing chunk (or a default vendor catch-all), matching what every site already runs in production.

3. Add `.deco.studio` to `allowedHosts`

The new admin frontend domain. Both sites duplicated the existing `[".deco.host", ".decocdn.com"]` list to add this third entry. Bundling here removes that duplication; sites can drop their own copy.

Risk analysis

  • (1) is additive: stubs an import that was previously not stubbed. If a site ever did intentionally import `meta.gen.json` on the client (which would be a bug — it's server-only), they would see an empty object instead. The probability is near zero based on the two reference sites.
  • (2) removes broken behavior: the rules being deleted were the cause of the runtime crashes that drove every site to override them. Removing them is strictly an improvement.
  • (3) is additive: just adds a third entry to an existing list, only when `DECO_SITE_NAME` is set (i.e. tunnel mode).

Verification

  • `node --check src/vite/plugin.js`: syntax OK
  • vitest: 104/104 pass
  • No new exports; pure plugin-internal change

Site cleanup that becomes possible after this lands + releases

```diff

  • {
  • name: "site-manual-chunks",
  • config(_cfg, { command }) { ... ~25 lines ... },
  • },
  • {
  • name: "deco-stub-meta-gen",
  • enforce: "pre" as const,
  • resolveId(id, importer, options) { ... },
  • load(id) { ... },
  • },
    ```

Plus the `.deco.studio` entry in each site's `allowedHosts`. Approximately 50 LOC of boilerplate per site.

Test plan

  • CI passes
  • Run `vite build` on baggagio-tanstack with the override removed; verify bundle still works (no chunk-load crash)
  • Smoke a baggagio dev session against `*.deco.studio` to confirm tunnel host check passes
  • Verify `meta.gen.json` no longer appears in production client bundle (check `vite build --mode production` chunk listing)

Made with Cursor

…deco.studio

Three small extensions to decoVitePlugin() that absorb boilerplate
both real-world Deco sites (casaevideo-storefront, baggagio-tanstack)
were keeping in their own vite.config.ts.

1. **meta.gen client stub** — `server/admin/meta.gen.json` is the admin
   schema bundle. It's server-only (the client receives pre-resolved
   blocks via the SSR payload) but Vite's dependency graph would still
   pull it into the browser bundle by default, adding 0.5-5 MB of dead
   weight. The framework now stubs `meta.gen.json` / `meta.gen.ts` to
   `export default {};` on the client.

   Match is end-of-id, scoped to non-entry imports (requires `importer`),
   so it can't accidentally stub a build target that points at meta.gen
   directly. Both site implementations had this exact plugin inline,
   with casaevideo's even commenting "TODO: move into decoVitePlugin in
   next @decocms/start release."

2. **Drop @decocms/start / @decocms/apps chunk splits** — Rollup's
   `manualChunks` had `vendor-deco` and `vendor-commerce` rules that
   pushed framework + apps packages into separate chunks. They have
   circular re-exports (apps imports start/sdk/cachedLoader; start
   admin imports from apps), and splitting them produces a chunk-load
   order that crashes at runtime ("undefined is not a function").

   Both sites worked around this by overriding `manualChunks` in their
   own configs. Removing the broken rules from the framework default
   lets Rollup bundle them with the importing chunk (or a default
   vendor catch-all), matching what every site already runs in production.

3. **Add .deco.studio to allowedHosts** — The new admin frontend domain.
   Both sites duplicated the list to include it; bundling here removes
   that duplication.

Verification:
- `node --check src/vite/plugin.js`: syntax OK
- vitest: 104/104 pass
- No new exports; pure plugin-internal change

Sites can drop after this lands + releases:
- `deco-stub-meta-gen` inline plugin (entire block)
- `site-manual-chunks` inline plugin (entire block)
- `.deco.studio` from their own allowedHosts list (additive change makes
  it framework-managed; site can remove its copy if they want)

Together that removes ~50 LOC of boilerplate per site.

Made-with: Cursor
@vibe-dex
vibe-dex merged commit 3a1a60a into main May 1, 2026
1 check passed
vibe-dex added a commit that referenced this pull request May 1, 2026
…checklist (#109)

Two stale areas in the deco-to-tanstack-migration skill, plus one
brand-new reference distilling battle-tested cleanup patterns.

## Changes

### `templates/vite-config.md` — drop ~80 lines of stub duplication

The old template inlined the entire `deco-server-only-stubs` plugin
(react-dom/server, node:async_hooks, node:stream, node:stream/web,
tanstack-head-scripts) — ~60 lines that exactly mirror what
`@decocms/start/vite`'s `decoVitePlugin()` already does.

The new template uses `decoVitePlugin()` and adds the production-grade
boilerplate that real sites actually need (and that the old version
omitted): VTEX dev proxy, CSP frame-ancestors header, build sourcemap,
PLUGIN_WARNING filter, react-compiler config, `pure: ["console.log"]`,
and the full `dedupe` list including `@decocms/start` + `@decocms/apps`.

### `references/vite-config/README.md` — fix "minimal" config that was broken

The "post-migration minimal config" was missing `decoVitePlugin()`
entirely. Without it, the client bundle crashes on transitively imported
server modules. Added the plugin + the minimum dedupe list, and
cross-referenced the full template.

### `references/post-migration-cleanup.md` — NEW

Dedicated reference distilling the cleanup work that surfaces on every
real migration:

1. Detect + delete unused `src/lib/*` shims (with a copy-paste detection
   script). Real-world data: baggagio-tanstack had 11 generated shims
   and 0 actual users; casaevideo had 11 generated and 1 used.
2. Drop the `site-manual-chunks` and `deco-stub-meta-gen` inline plugins
   that are now framework-provided in `@decocms/start >= 2.5.0`.
3. Drop the `runtime.ts` `invoke` shim — `@decocms/start/sdk` exports
   both `invoke` (singleton) and `createAppInvoke` (typed factory).
4. Drop site-local `withSiteGlobals` workaround — framework helper is
   now opt-in and tested.
5. Verify VTEX util imports point direct at `@decocms/apps/vtex/...`,
   not at dead `~/lib/vtex-*` shims (the migration script's stale
   `phase-cleanup.rewriteVtexUtilImports` was silently regressing
   them).
6. Search for orphan `TODO: move into framework` comments and either
   migrate, file an issue, or delete.

Plus a verification checklist.

## Why now

Validated in this session against three reference sites
(casaevideo-storefront, baggagio-tanstack, casaevideo). Each cleanup
step has a corresponding shipped or in-flight PR (#103/#106/#107/#108
on framework, #5/#6/#7 on baggagio-tanstack), so the checklist isn't
speculative.

## Scope discipline

This PR only edits skill content; no source/runtime changes. Both
`.agents/skills/` and `.cursor/skills/` copies stay in sync.

Made-with: Cursor
@github-actions

github-actions Bot commented May 1, 2026

Copy link
Copy Markdown

🎉 This PR is included in version 2.5.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant