Skip to content

fix(migrate): stop regressing valid @decocms/apps/vtex imports to dead shims - #107

Merged
vibe-dex merged 1 commit into
mainfrom
fix/migrate-stop-regressing-vtex-imports
May 1, 2026
Merged

vibe-dex merged 1 commit into
mainfrom
fix/migrate-stop-regressing-vtex-imports

Conversation

@vibe-dex

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

Copy link
Copy Markdown
Contributor

Summary

The `phase-cleanup` pass had four import rewrites that took perfectly valid direct imports and pointed them at NO-OP local shims:

```
from "@decocms/apps/vtex/utils/transform" → "/lib/vtex-transform"
from "@decocms/apps/vtex/utils/intelligentSearch" → "
/lib/vtex-intelligent-search"
from "@decocms/apps/vtex/utils/segment" → "/lib/vtex-segment"
from "@decocms/apps/vtex/client" → "
/lib/vtex-client"
```

These rewrites made sense when `@decocms/apps` did not export those modules. PR #93 (and the `apps-start` `package.json` exports map for `./vtex/utils/*` and `./vtex/client`) now provide them directly, so the cleanup pass was actively regressing migrated sites.

Concrete impact

Sites ended up with:

Shim Implementation Real apps-start
`~/lib/vtex-transform.ts` `toProduct(p) => p as Product` (no-op cast) Real product transform
`~/lib/vtex-segment.ts` `getSegmentFromBag() => null` Cookie-backed segment auth
`~/lib/vtex-segment.ts` `withSegmentCookie() => return arg` Adds segment cookie to headers
`~/lib/vtex-intelligent-search.ts` `getISCookiesFromBag() => {}` Real IS cookie generation

Silent runtime regressions on every migrated site — anything depending on segment auth or IS cookies just stops working at runtime.

Fix

Empty the `importRewrites` array in `rewriteVtexUtilImports`. The first-pass `transforms/imports.ts:50-52` already produces the correct direct form via:

```
/^"apps\/vtex\/utils\/([^"]+?)(?:\.ts)?"$/ → "@decocms/apps/vtex/utils/$1"
/^"apps\/vtex\/utils\/client(?:\.ts)?"$/ → "@decocms/apps/vtex/client"
```

Kept all other transforms in the function (LabelledFuzzy inline, generic-type strip on `createHttpClient`, `fetcher: fetchSafe` param strip, inline-stub hoisting) — those still address real path/signature mismatches.

Discovery context

Surfaced while triaging dead code in baggagio-tanstack#7 (11 unused `src/lib/*` files, 235 LOC of NO-OP stubs). Once #7 lands, every migrated site will need that same cleanup unless this PR ships first.

Verification

  • vitest: 104/104 pass
  • The diff is purely doc + array-emptying; no behavior added, only one removed
  • The kept transforms (createHttpClient generics, fetcher strip, inline-stub hoisting) are unaffected

Follow-ups (not in this PR)

  • Drop the 6 VTEX shim templates from `lib-utils.ts` (they're now only reachable via the rare inline-stub-hoisting path; future PR can route those directly to `@decocms/apps/vtex/...` instead)
  • Add a vitest config for `scripts/` so we can write regression tests for migration transforms without fs mocking gymnastics

Test plan

  • CI passes
  • Run migration on a copy of `casaevideo` (or any deco-cx site) and confirm `@decocms/apps/vtex/utils/transform` imports stay direct (verify with `grep -rn '~/lib/vtex-' src/` → 0 hits if no inline-stub hoisting fired)
  • Smoke a re-migrated site's PDP to confirm segment cookies and IS cookies populate correctly at runtime

Made with Cursor

…d shims

The `phase-cleanup` pass had four import rewrites that took perfectly
valid direct imports and pointed them at NO-OP local shims:

    from "@decocms/apps/vtex/utils/transform"          →  "~/lib/vtex-transform"
    from "@decocms/apps/vtex/utils/intelligentSearch"  →  "~/lib/vtex-intelligent-search"
    from "@decocms/apps/vtex/utils/segment"            →  "~/lib/vtex-segment"
    from "@decocms/apps/vtex/client"                   →  "~/lib/vtex-client"

These rewrites made sense when `@decocms/apps` did not export those
modules. PR #93 (and the apps-start `package.json` exports map for
`./vtex/utils/*` + `./vtex/client`) now provide them directly, so the
cleanup pass was actively regressing migrated sites. Concretely, sites
ended up with:

  - `~/lib/vtex-transform.ts`: `toProduct(p) => p as Product` (no-op cast)
  - `~/lib/vtex-segment.ts`: `getSegmentFromBag() => null`,
    `withSegmentCookie() => return arg as-is`
  - `~/lib/vtex-intelligent-search.ts`: `getISCookiesFromBag() => {}`

…instead of the real implementations that handle cookies, segment
auth, transformations, etc. Silent runtime regressions on every migrated
site.

Fix: empty the `importRewrites` array in `rewriteVtexUtilImports`.
The first-pass `transforms/imports.ts:50-52` already produces the
correct direct form via:

    /^"apps\/vtex\/utils\/([^"]+?)(?:\.ts)?"$/  →  "@decocms/apps/vtex/utils/$1"
    /^"apps\/vtex\/utils\/client(?:\.ts)?"$/    →  "@decocms/apps/vtex/client"

Kept all other transforms in the function (LabelledFuzzy inline,
generic-type strip on createHttpClient, `fetcher: fetchSafe` param
strip, inline-stub hoisting) — those still address real path/signature
mismatches.

Discovery context:
This bug surfaced while triaging dead code in baggagio-tanstack#7
(11 unused `src/lib/*` files, 235 LOC of NO-OP stubs). Tracked in
MIGRATION_TOOLING_PLAN.md.

Follow-ups (not in this PR):
- Drop the 6 VTEX shim templates from `lib-utils.ts` (they're now only
  reachable via the rare inline-stub-hoisting path; future PR can route
  those directly to `@decocms/apps/vtex/...` instead).
- Add a vitest config for `scripts/` so we can write regression tests
  for migration transforms without fs mocking gymnastics.

Made-with: Cursor
@vibe-dex
vibe-dex merged commit 111c5db 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