Repository navigation
fix(migrate): add VTEX/Shopify/commerce import rewrite rules - #65
Merged
Merged
Conversation
The catch-all apps/* → null rule was silently removing valid imports from apps/vtex/hooks/*, apps/vtex/utils/*, apps/shopify/*, and apps/commerce/sdk/*. Add specific rules that rewrite these to their @decocms/apps equivalents before the catch-all fires. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Instead of static islands/ → sections/ rewrite, scan the filesystem after transform to find where each island actually ended up (may be components/ or sections/) and rewrite imports to the correct path. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Instead of removing the import (leaving signal() undefined at runtime), redirect to the drop-in replacement that uses @tanstack/store. Co-Authored-By: Claude Opus 4.6 <[email protected]>
The import transform only handled static `from "..."` patterns but
missed `import("$store/...")` used in React.lazy() calls, causing
Vite "Failed to resolve import" errors at runtime.
Co-Authored-By: Claude Opus 4.6 <[email protected]>
…rite
The removeExportConstBlock function matched destructuring braces in
arrow function parameters (e.g. `({ groups }: Props) => {`) instead
of the function body brace. Now skips past `=>` before counting braces.
Co-Authored-By: Claude Opus 4.6 <[email protected]>
…r clx - signal.ts: add useSignal, computed, effect as drop-in replacements for @preact/signals APIs used by migrated sites - clx.ts: add default export so `import clx from "..."` works (sites commonly use default import pattern) Co-Authored-By: Claude Opus 4.6 <[email protected]>
- Revert useSignal/effect/computed from framework signal.ts — sites should NOT depend on framework for these; each site gets its own shim - Add generateSignalShim() to phase-scaffold.ts — migration now generates src/sdk/signal.ts with full @preact/signals compat shim (useSignal, useComputed, computed, effect, batch, useSignalEffect) - Redirect @preact/signals imports to ~/sdk/signal (local) instead of @decocms/start/sdk/signal (framework) Co-Authored-By: Claude Opus 4.6 <[email protected]>
- Add generateClxShim() to scaffold src/sdk/clx.ts in migrated sites with both default export and clsx alias for compat - Redirect clx imports to ~/sdk/clx (local) instead of @decocms/start/sdk/clx (framework) — avoids dependency on unpublished framework changes - Add run-migration skill for testing migration on real sites Co-Authored-By: Claude Opus 4.6 <[email protected]>
- Replace <Head>...</Head> with <>...</> in fresh-apis transform — React 19 auto-hoists title/meta/link tags to document head - Add std/async/debounce → ~/sdk/debounce import redirect - Scaffold src/sdk/debounce.ts with Deno-compatible API - Fixes "Head is not defined" and "debounce is not defined" runtime errors Co-Authored-By: Claude Opus 4.6 <[email protected]>
When dead-code removal strips `export const loader` from component
files, section wrappers like `export { default, loader } from "..."`
break at runtime. Now also clean up the re-export lines.
Co-Authored-By: Claude Opus 4.6 <[email protected]>
Section loaders (export const loader) are NOT dead code — they run server-side to modify props before rendering. Reverted their removal from dead-code transform and verify phase. Co-Authored-By: Claude Opus 4.6 <[email protected]>
There was a problem hiding this comment.
5 issues found across 9 files (changes from recent commits).
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="scripts/migrate/transforms/imports.ts">
<violation number="1" location="scripts/migrate/transforms/imports.ts:240">
P2: Dynamic import rewrites bypass the existing sdk-specific rules (e.g., `site/sdk/useId` → `react`), so `import("site/sdk/useId")` will incorrectly become `~/sdk/useId`. Route these through `rewriteSpecifier` so dynamic imports follow the same rules as static imports.</violation>
</file>
<file name="scripts/migrate/phase-transform.ts">
<violation number="1" location="scripts/migrate/phase-transform.ts:148">
P2: Normalize path separators when computing `relPath`; Windows backslashes will otherwise break the `components/`/`sections/` prefix checks and produce invalid import specifiers like `~/components\Foo`.</violation>
</file>
<file name="scripts/migrate/transforms/fresh-apis.ts">
<violation number="1" location="scripts/migrate/transforms/fresh-apis.ts:150">
P2: Handle self-closing `<Head />` tags before the generic `<Head ...>` replacement; otherwise `<Head />` becomes `<>` without a closing fragment and the transformed JSX is invalid.</violation>
</file>
<file name="scripts/migrate/phase-scaffold.ts">
<violation number="1" location="scripts/migrate/phase-scaffold.ts:317">
P2: `useComputed` memoizes the computed value only once, so changes in props/state won’t recompute the signal and the value stays stale after the first render. Include `fn` in the memo dependencies (or otherwise refresh the signal) so it updates when the compute function changes.</violation>
<violation number="2" location="scripts/migrate/phase-scaffold.ts:331">
P2: `useSignalEffect` runs its callback during render. In React this should be scheduled with `useEffect`; otherwise side effects run during render (and twice in StrictMode).</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
- imports: route dynamic imports through rewriteSpecifier so sdk-specific rules (e.g. site/sdk/useId → react) apply to dynamic imports too - phase-transform: normalize path separators with .replace(/\\/g, "/") when computing relPath to avoid Windows backslash breaking prefix checks - fresh-apis: handle self-closing <Head /> before generic <Head ...> replacement so it becomes <></> instead of a broken <> - phase-scaffold: include fn in useComputed memo deps so it recomputes when the function changes - phase-scaffold: fix useSignalEffect to wrap callback in useEffect instead of calling it directly during render Co-Authored-By: Claude Opus 4.6 <[email protected]>
There was a problem hiding this comment.
1 issue found across 4 files (changes from recent commits).
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="scripts/migrate/transforms/fresh-apis.ts">
<violation number="1" location="scripts/migrate/transforms/fresh-apis.ts:150">
P2: Self-closing `<Head ... />` with attributes is rewritten to `<>` (missing `</>`), which produces invalid JSX.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
`<Head lang="pt" />` was matched by the generic `<Head ...>` rule and replaced with `<>` (missing `</>`), producing invalid JSX. Now the self-closing pattern with attributes is matched first. Co-Authored-By: Claude Opus 4.6 <[email protected]>
|
🎉 This PR is included in version 0.42.3 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
Merged
3 tasks done
hugo-ccabral
pushed a commit
that referenced
this pull request
Aug 14, 2026
- #52: ctx is no longer always undefined (framework fixed via issue #305, landed before this PR); reframe Fix as ctx-free alternative, not mandatory - #61: discovery rg command had unbalanced parens and didn't compile; split into two valid rg calls - #63: filter checked "@type" (always "UnitPriceSpecification") instead of priceComponentType, so the trim silently matched nothing; fixed the field - #65: discovery step was prose, not a runnable command; added grep+jq pair - #66: v5-only gotcha wasn't flagged as such in an otherwise v4 file; added an applicability note - #72: fix had no code example unlike every other BLOCKER/HIGH gotcha; added one, correcting the import path typo present in the source JSDoc itself (@decocms/apps/vtex/... -> @decocms/apps-vtex/...) Co-Authored-By: Claude Sonnet 5 <[email protected]>
hugo-ccabral
added a commit
that referenced
this pull request
Aug 18, 2026
…rnings-staging convention (#457) ## Summary Consolidates the farmrio-storefront Fresh→TanStack migration's staged learnings (`migration/learnings/`, ~69 completed targets, coverage-verified against the live ledger) into this skill's reference docs, per the epic's own consolidation target (`T40`). 22 new numbered gotchas (**#52–#73**), each carrying Severity, Symptom, Root cause, Fix (with code), a discovery `rg`/`grep` command, and empirical farmrio evidence (file counts, byte deltas, before/after numbers, cross-refs). Distributed into the existing topic files rather than one new dump file, matching this repo's own index-per-topic convention: | File | New gotchas | Headline finding | |---|---|---| | `async-rendering.md` | #52–54, #73 | Dead 3-arg `ctx` section loaders — 28-file sweep, one was a site-wide dead cookie-consent banner | | `hydration-fixes.md` | #55–58 | `DeferredSectionWrapper` skeleton remount/CLS (cross-ref #448) + a content-refresh-safe `Lazy.tsx` unwrap pattern | | `vtex-commerce.md` | #59–64 | CMS multivariate-flag resolver only recognizes 2 of 7 real resolveTypes — silently drops content (blocker) | | `css-styling.md` | #65–67 | Theme-conversion DaisyUI slot mismapping + v5's silent dark-theme bundling | | `worker-cloudflare.md` | #68–71 | Device-segmented edge-cache poisoning via SWR revalidation (novel); server-only secrets reachable from client bundle via the invoke dispatch table (security) | | `storefront-patterns.md` | #72 | `sitemap.xml` not auto-wired | `references/migration-learnings-staging.md` (new file) proposes the index-per-target-file learnings convention as the **starting** pattern for the next migration's own staging area — citing this epic's own flat `LEARNINGS.md` (282,249 bytes / 3,875 lines / 103 entries, costing target sessions 60k+ tokens just to search before it was restructured mid-epic on 2026-07-30) as the empirical case for adopting it from day one instead. Linked from `SKILL.md`'s reference index. Two gotchas (#55, #59) reference upstream PRs/issues already filed from this same migration: **[#448](#448 (`DeferredSectionWrapper` fix, open) and **[#391](#391 (URL param coercion, referenced by #61). ## Codemod / audit-rule proposals for `packages/blocks-cli` Proposal only (per this migration's own DoD, implementation is a bonus, not required) — each was hit ≥3 times independently across the farmrio migration: 1. **Dead-arity section-loader detector** — AST walk for 3-arg `(props, req, ctx)` loader exports, cross-referenced against `registerSectionLoaders` calls and each file's real `__resolveType` (not its file path) in `blocks.gen.json`. Would have caught all 28 candidate files in gotcha #52 at migration time. 2. **`typeof X === "function"` guard sweep** — flag this pattern on any value that originates from CMS section resolution (gotcha #54); recurred independently in 6+ files across the epic. 3. **Controlled-input-missing-`onChange` sweep** — `checked={...}` JSX prop with no sibling `onChange` (gotcha #58); found and fixed independently 3 separate times. 4. **`LoadingFallback` wrapper-function → literal-alias codemod** — rewrite `export function LoadingFallback(props) { return <X {...props}/>; }` to `export const LoadingFallback = X;` (gotcha #56). 5. **Redirect self-loop lint rule** — flag any `blocks.gen.json` redirect block where `normalize(from) === normalize(to)` after case-folding (gotcha #60); found 3 live instances across 2 targets once the check existed as an ad-hoc script. 6. **Image-dimension backfill from source headers** — generic migration-time step parsing real JPEG/PNG dimensions from each unique image URL's own file header and writing `width`/`height` back into CMS content, instead of leaving every un-dimensioned image to hit the CLS-safety-net fallback one page at a time (gotcha #67). 7. **`deco-post-cleanup --strict` comment/string-literal awareness** — several existing audit rules (`deco-cx-runtime-api`, `style-string-props`, `htmx-residue`) are literal-substring scans with no AST/JSX awareness, so they false-positive on matches inside comments or inside a `dangerouslySetInnerHTML` HTML string. Farmrio counts: 7 comment-only false positives on one rule, 4 on another, 4-of-6 on a third. ## Parity-destined findings Filed separately against `decocms/parity` (issue, cross-linked from `migration/learnings/INDEX.md` in farmrio-storefront) rather than bundled into this PR — covers `--fail-on` requiring `--ci`, `--pages` not scoping `flows`, a `banner-aspect-ratio` check double-counting infinite-carousel clones, a `lazy-section-presence` heuristic incompatible with TanStack's transport, and LLM visual-diff hallucination on downscaled full-page screenshots. ## Test plan - [x] Docs-only change — no code paths affected, nothing to typecheck or build - [x] Every new gotcha cross-checked against the current `gotchas.md` numbering (#51 was the prior max, confirmed via `grep -rn "^## #\?[0-9]" *.md`) - [x] Every code snippet reproduced from the source learnings files, not invented — cross-checked against the cited `migration/learnings/T<ID>.md` file in `deco-sites/farmrio-storefront` 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Consolidates Farm Rio Fresh→TanStack migration learnings into this skill and adds 22 numbered gotchas (#52–#73). Also documents an index-per-target-file staging convention to keep future migrations fast and cheap. - Adds gotchas across async/rendering, hydration, VTEX commerce, CSS/DaisyUI, Worker/Cloudflare, and storefront patterns, covering issues like pre-`#305` 3‑arg loader pitfalls, `DeferredSectionWrapper` CLS, multivariate resolver gaps, sitemap wiring, cache behavior, and a client-bundle secret leak. Cross‑refs: `#448` and `#391`. - Introduces `references/migration-learnings-staging.md` and links it from `SKILL.md` to replace flat learnings with an index-per-target approach. **Doc updates since review** - #52: Clarifies that `@decocms/blocks` now supports an optional 3rd `ctx` arg when registered; positions the fix as a ctx‑free alternative for pre‑`#305` or unregistered loaders. - #61: Splits discovery into two valid `rg` commands. - #63: Corrects variant‑trim filter to use `priceComponentType` (not `@type`), ensuring installment entries are removed. - #65: Adds runnable discovery steps (`grep` + `jq`) for DaisyUI slot mapping. - #66: Flags the dark‑theme auto‑bundling gotcha as DaisyUI v5‑only. - #72: Adds a `worker-entry.ts` wiring example for `/sitemap.xml` and fixes the import path to `@decocms/apps-vtex`. <sup>Written for commit 919eb12. Summary will update on new commits.</sup> <a href="https://cubic.dev/pr/decocms/blocks/pull/457?utm_source=github" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img alt="Review in cubic" src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a> <!-- End of auto-generated description by cubic. --> --------- Co-authored-by: hugo-ccabral <[email protected]> Co-authored-by: Claude Sonnet 5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
apps/vtex/hooks/*,apps/vtex/utils/*,apps/vtex/actions/*,apps/vtex/loaders/*,apps/shopify/*, andapps/commerce/sdk/*apps/* → nullrule, preventing valid imports from being silently removedWhy
The catch-all
apps/* → nullrule was removing imports likeapps/vtex/hooks/useCartandapps/vtex/utils/vtexIdthat have direct equivalents in@decocms/apps. This caused runtime errors in migrated sites (e.g. miess-01).Test plan
deco-migrateon a VTEX site — imports fromapps/vtex/hooks/*should become@decocms/apps/vtex/hooks/*deco-migrateon a Shopify site — same pattern for shopify importsapps/website/mod.tsand other non-commerce imports still get removed by catch-all🤖 Generated with Claude Code
Summary by cubic
Add targeted import rewrites for VTEX/Shopify/commerce and fix islands, signals, dynamic imports, and Head handling to stop migration runtime errors.
apps/vtex/{hooks,utils,actions,loaders,types},apps/shopify/{hooks,utils,actions,loaders}, andapps/commerce/{sdk,utils}to@decocms/apps/*before the catch‑all; redirect@preact/signals/@preact/signals-coreto~/sdk/signal; rewrite dynamic imports so$store//site/and SDK aliases resolve (e.g.site/sdk/useId→react).~/islands/*imports to actual files undercomponents/orsections/(preferscomponents/), and normalize path separators to avoid Windows issues.~/sdk/signal(drop‑in API withuseSignal,useComputed,useSignalEffect, etc.),~/sdk/clx(default +clsx), and~/sdk/debounce; mapstd/async/debounceto the shim; replace<Head>and self‑closing<Head ... />with fragments (React 19 hoists head tags).loaderexports and harden dead‑code removal with brace‑counting.Written for commit 6baa9e7. Summary will update on new commits.