@decocms/start 0.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (185) hide show
  1. package/.cursor/skills/deco-api-call-dedup/SKILL.md +443 -0
  2. package/.cursor/skills/deco-apps-architecture/SKILL.md +255 -0
  3. package/.cursor/skills/deco-apps-architecture/app-pattern.md +288 -0
  4. package/.cursor/skills/deco-apps-architecture/commerce-types.md +239 -0
  5. package/.cursor/skills/deco-apps-architecture/new-app-guide.md +268 -0
  6. package/.cursor/skills/deco-apps-architecture/scripts-codegen.md +148 -0
  7. package/.cursor/skills/deco-apps-architecture/shared-utils.md +181 -0
  8. package/.cursor/skills/deco-apps-architecture/vtex-deep-structure.md +253 -0
  9. package/.cursor/skills/deco-apps-architecture/website-app.md +169 -0
  10. package/.cursor/skills/deco-apps-vtex-porting/SKILL.md +189 -0
  11. package/.cursor/skills/deco-apps-vtex-porting/adaptation-patterns.md +335 -0
  12. package/.cursor/skills/deco-apps-vtex-porting/commerce-porting.md +155 -0
  13. package/.cursor/skills/deco-apps-vtex-porting/cookie-auth-patterns.md +148 -0
  14. package/.cursor/skills/deco-apps-vtex-porting/structure-map.md +234 -0
  15. package/.cursor/skills/deco-apps-vtex-porting/transform-mapping.md +99 -0
  16. package/.cursor/skills/deco-apps-vtex-porting/website-porting.md +194 -0
  17. package/.cursor/skills/deco-apps-vtex-review/SKILL.md +234 -0
  18. package/.cursor/skills/deco-async-rendering-architecture/SKILL.md +270 -0
  19. package/.cursor/skills/deco-async-rendering-site-guide/SKILL.md +417 -0
  20. package/.cursor/skills/deco-cms-layout-caching/SKILL.md +293 -0
  21. package/.cursor/skills/deco-cms-route-config/SKILL.md +388 -0
  22. package/.cursor/skills/deco-core-architecture/SKILL.md +185 -0
  23. package/.cursor/skills/deco-core-architecture/blocks.md +196 -0
  24. package/.cursor/skills/deco-core-architecture/deco-vs-deco-start.md +191 -0
  25. package/.cursor/skills/deco-core-architecture/engine.md +220 -0
  26. package/.cursor/skills/deco-core-architecture/hooks-components.md +157 -0
  27. package/.cursor/skills/deco-core-architecture/plugins-clients.md +136 -0
  28. package/.cursor/skills/deco-core-architecture/runtime.md +116 -0
  29. package/.cursor/skills/deco-core-architecture/site-usage.md +165 -0
  30. package/.cursor/skills/deco-e2e-testing/SKILL.md +372 -0
  31. package/.cursor/skills/deco-e2e-testing/discovery.md +337 -0
  32. package/.cursor/skills/deco-e2e-testing/scripts/scaffold.sh +81 -0
  33. package/.cursor/skills/deco-e2e-testing/selectors.md +175 -0
  34. package/.cursor/skills/deco-e2e-testing/templates/package.json +18 -0
  35. package/.cursor/skills/deco-e2e-testing/templates/playwright.config.ts +65 -0
  36. package/.cursor/skills/deco-e2e-testing/templates/scripts/baseline.ts +279 -0
  37. package/.cursor/skills/deco-e2e-testing/templates/scripts/run-e2e.ts +194 -0
  38. package/.cursor/skills/deco-e2e-testing/templates/specs/ecommerce-flow.spec.ts +612 -0
  39. package/.cursor/skills/deco-e2e-testing/templates/tsconfig.json +12 -0
  40. package/.cursor/skills/deco-e2e-testing/templates/utils/metrics-collector.ts +918 -0
  41. package/.cursor/skills/deco-e2e-testing/troubleshooting.md +602 -0
  42. package/.cursor/skills/deco-edge-caching/SKILL.md +316 -0
  43. package/.cursor/skills/deco-full-analysis/SKILL.md +898 -0
  44. package/.cursor/skills/deco-full-analysis/checklists/asset-optimization.md +251 -0
  45. package/.cursor/skills/deco-full-analysis/checklists/bug-fix.md +189 -0
  46. package/.cursor/skills/deco-full-analysis/checklists/cache-strategy.md +144 -0
  47. package/.cursor/skills/deco-full-analysis/checklists/dependency-update.md +150 -0
  48. package/.cursor/skills/deco-full-analysis/checklists/hydration-fix.md +191 -0
  49. package/.cursor/skills/deco-full-analysis/checklists/image-optimization.md +180 -0
  50. package/.cursor/skills/deco-full-analysis/checklists/loader-optimization.md +165 -0
  51. package/.cursor/skills/deco-full-analysis/checklists/seo-fix.md +183 -0
  52. package/.cursor/skills/deco-full-analysis/checklists/site-cleanup.md +281 -0
  53. package/.cursor/skills/deco-full-analysis/discovery.md +548 -0
  54. package/.cursor/skills/deco-incident-debugging/SKILL.md +378 -0
  55. package/.cursor/skills/deco-incident-debugging/headless-mode.md +510 -0
  56. package/.cursor/skills/deco-incident-debugging/learnings-index.md +227 -0
  57. package/.cursor/skills/deco-incident-debugging/triage-workflow.md +312 -0
  58. package/.cursor/skills/deco-islands-migration/SKILL.md +251 -0
  59. package/.cursor/skills/deco-loader-n-plus-1-detector/SKILL.md +275 -0
  60. package/.cursor/skills/deco-performance-audit/SKILL.md +530 -0
  61. package/.cursor/skills/deco-performance-audit/tools-reference.md +428 -0
  62. package/.cursor/skills/deco-performance-audit/workflow.md +457 -0
  63. package/.cursor/skills/deco-server-functions-invoke/SKILL.md +92 -0
  64. package/.cursor/skills/deco-server-functions-invoke/architecture.md +166 -0
  65. package/.cursor/skills/deco-server-functions-invoke/generator.md +122 -0
  66. package/.cursor/skills/deco-server-functions-invoke/problem.md +98 -0
  67. package/.cursor/skills/deco-server-functions-invoke/troubleshooting.md +110 -0
  68. package/.cursor/skills/deco-site-deployment/SKILL.md +396 -0
  69. package/.cursor/skills/deco-site-memory-debugging/SKILL.md +121 -0
  70. package/.cursor/skills/deco-site-memory-debugging/cdp-connection.md +222 -0
  71. package/.cursor/skills/deco-site-memory-debugging/memory-analysis.md +362 -0
  72. package/.cursor/skills/deco-site-patterns/SKILL.md +124 -0
  73. package/.cursor/skills/deco-site-patterns/app-composition.md +337 -0
  74. package/.cursor/skills/deco-site-patterns/client-patterns.md +341 -0
  75. package/.cursor/skills/deco-site-patterns/cms-wiring.md +230 -0
  76. package/.cursor/skills/deco-site-patterns/section-patterns.md +340 -0
  77. package/.cursor/skills/deco-site-scaling-tuning/SKILL.md +240 -0
  78. package/.cursor/skills/deco-site-scaling-tuning/analysis-scripts.md +267 -0
  79. package/.cursor/skills/deco-start-architecture/SKILL.md +218 -0
  80. package/.cursor/skills/deco-start-architecture/admin-protocol.md +156 -0
  81. package/.cursor/skills/deco-start-architecture/cms-resolution.md +201 -0
  82. package/.cursor/skills/deco-start-architecture/code-quality.md +158 -0
  83. package/.cursor/skills/deco-start-architecture/gap-analysis.md +129 -0
  84. package/.cursor/skills/deco-start-architecture/sdk-utilities.md +197 -0
  85. package/.cursor/skills/deco-start-architecture/worker-entry-caching.md +154 -0
  86. package/.cursor/skills/deco-startup-analysis/SKILL.md +248 -0
  87. package/.cursor/skills/deco-storefront-test-checklist/SKILL.md +369 -0
  88. package/.cursor/skills/deco-tanstack-hydration-fixes/SKILL.md +468 -0
  89. package/.cursor/skills/deco-tanstack-navigation/SKILL.md +681 -0
  90. package/.cursor/skills/deco-tanstack-search/SKILL.md +411 -0
  91. package/.cursor/skills/deco-tanstack-storefront-patterns/SKILL.md +1013 -0
  92. package/.cursor/skills/deco-to-tanstack-migration/SKILL.md +518 -0
  93. package/.cursor/skills/deco-to-tanstack-migration/references/codemod-commands.md +174 -0
  94. package/.cursor/skills/deco-to-tanstack-migration/references/commerce/README.md +78 -0
  95. package/.cursor/skills/deco-to-tanstack-migration/references/deco-framework/README.md +128 -0
  96. package/.cursor/skills/deco-to-tanstack-migration/references/gotchas.md +719 -0
  97. package/.cursor/skills/deco-to-tanstack-migration/references/imports/README.md +70 -0
  98. package/.cursor/skills/deco-to-tanstack-migration/references/platform-hooks/README.md +154 -0
  99. package/.cursor/skills/deco-to-tanstack-migration/references/signals/README.md +220 -0
  100. package/.cursor/skills/deco-to-tanstack-migration/references/vite-config/README.md +78 -0
  101. package/.cursor/skills/deco-to-tanstack-migration/templates/package-json.md +55 -0
  102. package/.cursor/skills/deco-to-tanstack-migration/templates/root-route.md +110 -0
  103. package/.cursor/skills/deco-to-tanstack-migration/templates/router.md +96 -0
  104. package/.cursor/skills/deco-to-tanstack-migration/templates/setup-ts.md +167 -0
  105. package/.cursor/skills/deco-to-tanstack-migration/templates/vite-config.md +122 -0
  106. package/.cursor/skills/deco-to-tanstack-migration/templates/worker-entry.md +67 -0
  107. package/.cursor/skills/deco-typescript-fixes/SKILL.md +178 -0
  108. package/.cursor/skills/deco-typescript-fixes/common-fixes.md +330 -0
  109. package/.cursor/skills/deco-typescript-fixes/strategy.md +148 -0
  110. package/.cursor/skills/deco-variant-selection-perf/SKILL.md +272 -0
  111. package/.cursor/skills/deco-vtex-fetch-cache/SKILL.md +225 -0
  112. package/.cursor/skills/find-skills/SKILL.md +133 -0
  113. package/.cursor/skills/incident-report/SKILL.md +179 -0
  114. package/.cursor/skills/incident-report/references/5-whys.md +75 -0
  115. package/.cursor/skills/incident-report/templates/client-report.md +187 -0
  116. package/.cursor/skills/incident-report/templates/internal-report.md +206 -0
  117. package/.cursor/skills/template-skill/SKILL.md +38 -0
  118. package/.github/workflows/release.yml +32 -0
  119. package/.releaserc.json +25 -0
  120. package/CLAUDE.md +135 -0
  121. package/GAP_ANALYSIS.md +224 -0
  122. package/GAP_ANALYSIS_V2.md +1013 -0
  123. package/biome.json +39 -0
  124. package/knip.json +5 -0
  125. package/package.json +87 -0
  126. package/scripts/generate-blocks.ts +69 -0
  127. package/scripts/generate-invoke.ts +378 -0
  128. package/scripts/generate-schema.ts +657 -0
  129. package/src/admin/cors.ts +29 -0
  130. package/src/admin/decofile.ts +72 -0
  131. package/src/admin/index.ts +24 -0
  132. package/src/admin/invoke.ts +163 -0
  133. package/src/admin/liveControls.ts +29 -0
  134. package/src/admin/meta.ts +70 -0
  135. package/src/admin/render.ts +205 -0
  136. package/src/admin/schema.ts +686 -0
  137. package/src/admin/setup.ts +44 -0
  138. package/src/cms/index.ts +59 -0
  139. package/src/cms/loader.ts +180 -0
  140. package/src/cms/registry.ts +162 -0
  141. package/src/cms/resolve.ts +1005 -0
  142. package/src/cms/sectionLoaders.ts +294 -0
  143. package/src/hooks/DecoPageRenderer.tsx +444 -0
  144. package/src/hooks/LazySection.tsx +109 -0
  145. package/src/hooks/LiveControls.tsx +108 -0
  146. package/src/hooks/SectionErrorFallback.tsx +85 -0
  147. package/src/hooks/index.ts +8 -0
  148. package/src/index.ts +5 -0
  149. package/src/matchers/builtins.ts +184 -0
  150. package/src/matchers/posthog.ts +154 -0
  151. package/src/middleware/decoState.ts +55 -0
  152. package/src/middleware/healthMetrics.ts +131 -0
  153. package/src/middleware/index.ts +80 -0
  154. package/src/middleware/liveness.ts +21 -0
  155. package/src/middleware/observability.ts +205 -0
  156. package/src/routes/adminRoutes.ts +83 -0
  157. package/src/routes/cmsRoute.ts +302 -0
  158. package/src/routes/components.tsx +34 -0
  159. package/src/routes/index.ts +15 -0
  160. package/src/sdk/analytics.ts +72 -0
  161. package/src/sdk/cacheHeaders.ts +268 -0
  162. package/src/sdk/cachedLoader.ts +206 -0
  163. package/src/sdk/clx.ts +3 -0
  164. package/src/sdk/cookie.ts +39 -0
  165. package/src/sdk/createInvoke.ts +57 -0
  166. package/src/sdk/csp.ts +59 -0
  167. package/src/sdk/env.ts +27 -0
  168. package/src/sdk/index.ts +63 -0
  169. package/src/sdk/instrumentedFetch.ts +137 -0
  170. package/src/sdk/invoke.ts +133 -0
  171. package/src/sdk/mergeCacheControl.ts +150 -0
  172. package/src/sdk/redirects.ts +217 -0
  173. package/src/sdk/requestContext.ts +184 -0
  174. package/src/sdk/serverTimings.ts +68 -0
  175. package/src/sdk/signal.ts +41 -0
  176. package/src/sdk/sitemap.ts +143 -0
  177. package/src/sdk/urlUtils.ts +117 -0
  178. package/src/sdk/useDevice.ts +82 -0
  179. package/src/sdk/useId.ts +7 -0
  180. package/src/sdk/useScript.ts +101 -0
  181. package/src/sdk/workerEntry.ts +703 -0
  182. package/src/sdk/wrapCaughtErrors.ts +107 -0
  183. package/src/types/index.ts +39 -0
  184. package/src/types/widgets.ts +13 -0
  185. package/tsconfig.json +13 -0
@@ -0,0 +1,518 @@
1
+ ---
2
+ name: deco-to-tanstack-migration
3
+ description: Migrate Deco.cx storefronts from Fresh/Preact to TanStack Start/React on Cloudflare Workers. Phase-based playbook with automation scripts, battle-tested templates, and cross-references to specialized skills. Use when migrating a deco-site, porting Preact components to React, or setting up TanStack Start for a Deco storefront.
4
+ ---
5
+
6
+ # Deco-to-TanStack-Start Migration Playbook
7
+
8
+ Phase-based playbook for converting `deco-sites/*` storefronts from Fresh/Preact/Deno to TanStack Start/React/Cloudflare Workers. Battle-tested on espacosmart-storefront (100+ sections, VTEX, async rendering).
9
+
10
+ ## Architecture Boundaries
11
+
12
+ | Layer | npm Package | Purpose | Must NOT Contain |
13
+ |-------|-------------|---------|-----------------|
14
+ | **@decocms/start** | `@decocms/start` | CMS resolution, DecoPageRenderer, worker entry, sdk (useScript, signal, clx) | Preact shims, widget types, site-specific maps |
15
+ | **@decocms/apps** | `@decocms/apps` | VTEX/Shopify loaders, commerce types, commerce sdk (useOffer, formatPrice, analytics) | Passthrough HTML components, Preact/Fresh refs |
16
+ | **Site repo** | (not published) | All UI: components, hooks, types, routes, styles | No compat/ layer, no aliases beyond `~` |
17
+
18
+ ### Architecture Map
19
+
20
+ | Old Stack | New Stack |
21
+ |-----------|-----------|
22
+ | Deno + Fresh | Node + TanStack Start |
23
+ | Preact + Islands | React 19 + React Compiler |
24
+ | @preact/signals | @tanstack/store + @tanstack/react-store |
25
+ | Deco CMS runtime | Static JSON blocks via @decocms/start |
26
+ | $fresh/runtime.ts | Inlined (asset() removed, IS_BROWSER inlined) |
27
+ | @deco/deco/* | @decocms/start/sdk/* or inline stubs |
28
+ | apps/commerce/types | @decocms/apps/commerce/types |
29
+ | apps/website/components/* | ~/components/ui/* (local React) |
30
+ | apps/{platform}/hooks/* | ~/hooks/useCart (real implementation) |
31
+ | ~/sdk/useOffer | @decocms/apps/commerce/sdk/useOffer |
32
+ | ~/sdk/useScript | @decocms/start/sdk/useScript |
33
+ | ~/sdk/signal | @decocms/start/sdk/signal |
34
+
35
+ ## Migration Phases
36
+
37
+ Each phase has entry/exit criteria. Follow in order. Automation % indicates how much can be done with bulk sed/grep.
38
+
39
+ | Phase | Name | Automation | Related Skill |
40
+ |-------|------|-----------|---------------|
41
+ | [0](#phase-0--scaffold) | Scaffold & Copy | 100% | — |
42
+ | [1](#phase-1--imports--jsx) | Import Rewrites | ~90% | — |
43
+ | [2](#phase-2--signals--state) | Signals & State | ~50% | — |
44
+ | [3](#phase-3--deco-framework) | Deco Framework Elimination | ~80% | — |
45
+ | [4](#phase-4--commerce--types) | Commerce Types & UI | ~70% | deco-apps-vtex-porting |
46
+ | [5](#phase-5--platform-hooks) | Platform Hooks | 0% | deco-apps-vtex-porting |
47
+ | [6](#phase-6--islands-elimination) | Islands Elimination | ~60% | deco-islands-migration |
48
+ | [7](#phase-7--section-registry) | Section Registry & Setup | 0% | deco-async-rendering-site-guide |
49
+ | [8](#phase-8--routes--cms) | Routes & CMS | template | deco-tanstack-navigation |
50
+ | [9](#phase-9--worker-entry) | Worker Entry & Server | template | deco-edge-caching |
51
+ | [10](#phase-10--async-rendering) | Async Rendering & Polish | 0% | deco-async-rendering-site-guide |
52
+
53
+ ---
54
+
55
+ ### Phase 0 — Scaffold
56
+
57
+ **Entry**: Source site accessible, @decocms/start + @decocms/apps published
58
+
59
+ **Actions**:
60
+ 1. Create TanStack Start project
61
+ 2. Copy `src/components/`, `src/sections/`, `src/islands/`, `src/hooks/`, `src/sdk/`, `src/loaders/` from source
62
+ 3. Copy `.deco/blocks/` (CMS content)
63
+ 4. Copy `static/` assets
64
+ 5. Create `package.json` — see `templates/package-json.md`
65
+ 6. Create `vite.config.ts` — see `templates/vite-config.md`
66
+ 7. `npm install`
67
+
68
+ **Exit**: Empty project builds with `npm run build`
69
+
70
+ ---
71
+
72
+ ### Phase 1 — Imports & JSX
73
+
74
+ **Entry**: Source files copied to `src/`
75
+
76
+ **Actions** (bulk sed — see `references/codemod-commands.md`):
77
+ 1. Preact → React: `from "preact/hooks"` → `from "react"`, etc.
78
+ 2. `ComponentChildren` → `ReactNode`
79
+ 3. `class=` → `className=` in JSX
80
+ 4. SVG attrs: `stroke-width` → `strokeWidth`, `fill-rule` → `fillRule`, etc.
81
+ 5. HTML attrs: `for=` → `htmlFor=`, `fetchpriority` → `fetchPriority`, `autocomplete` → `autoComplete`
82
+ 6. Remove `/** @jsxRuntime automatic */` pragma comments
83
+
84
+ **Verification**: `grep -r 'from "preact' src/ | wc -l` → 0
85
+
86
+ **Exit**: Zero preact imports, zero `class=` in JSX
87
+
88
+ See: `references/imports/README.md`
89
+
90
+ ---
91
+
92
+ ### Phase 2 — Signals & State
93
+
94
+ **Entry**: Phase 1 complete
95
+
96
+ **Actions**:
97
+ 1. Bulk: `from "@preact/signals"` → `from "@decocms/start/sdk/signal"` (module-level signals)
98
+ 2. Manual: `useSignal(val)` → `useState(val)` (component hooks)
99
+ 3. Manual: `useComputed(() => expr)` → `useMemo(() => expr, [deps])` (component hooks)
100
+ 4. For global reactive state: use `signal()` from `@decocms/start/sdk/signal` + `useStore()` from `@tanstack/react-store`
101
+
102
+ **Verification**: `grep -r '@preact/signals' src/ | wc -l` → 0
103
+
104
+ **Exit**: Zero @preact/signals imports
105
+
106
+ See: `references/signals/README.md`
107
+
108
+ ---
109
+
110
+ ### Phase 3 — Deco Framework
111
+
112
+ **Entry**: Phase 2 complete
113
+
114
+ **Actions** (mostly bulk sed):
115
+ 1. Remove `$fresh/runtime.ts` imports (`asset()` → identity, `IS_BROWSER` → `typeof window !== "undefined"`)
116
+ 2. `from "deco-sites/SITENAME/"` → `from "~/"`
117
+ 3. `from "$store/"` → `from "~/"`
118
+ 4. `from "site/"` → `from "~/"`
119
+ 5. `SectionProps` → inline type or `import { SectionProps } from "~/types/section"`
120
+ 6. `useScript` → `from "@decocms/start/sdk/useScript"`
121
+ 7. `clx` → `from "@decocms/start/sdk/clx"`
122
+
123
+ **Verification**: `grep -rE 'from "(@deco/deco|\$fresh|deco-sites/)' src/ | wc -l` → 0
124
+
125
+ **Exit**: Zero @deco/deco, $fresh, deco-sites/ imports
126
+
127
+ See: `references/deco-framework/README.md`
128
+
129
+ ---
130
+
131
+ ### Phase 4 — Commerce & Types
132
+
133
+ **Entry**: Phase 3 complete
134
+
135
+ **Actions**:
136
+ 1. `from "apps/commerce/types.ts"` → `from "@decocms/apps/commerce/types"`
137
+ 2. `from "apps/admin/widgets.ts"` → `from "~/types/widgets"` (create local file with string aliases)
138
+ 3. `from "apps/website/components/Image.tsx"` → `from "~/components/ui/Image"` (create local components)
139
+ 4. SDK utilities: `~/sdk/useOffer` → `@decocms/apps/commerce/sdk/useOffer`, `~/sdk/format` → `@decocms/apps/commerce/sdk/formatPrice`, etc.
140
+
141
+ **Verification**: `grep -r 'from "apps/' src/ | wc -l` → 0
142
+
143
+ **Exit**: Zero `apps/` imports
144
+
145
+ See: `references/commerce/README.md`
146
+
147
+ ---
148
+
149
+ ### Phase 5 — Platform Hooks
150
+
151
+ **Entry**: Phase 4 complete
152
+
153
+ **Actions** (manual implementation):
154
+ 1. Create `src/hooks/useCart.ts` — module-level singleton + listener pattern
155
+ 2. Create `src/hooks/useUser.ts`, `src/hooks/useWishlist.ts` (stubs or real)
156
+ 3. Wire VTEX API calls via `@decocms/apps` invoke functions
157
+
158
+ **Pattern**: Closure state + `_listeners` Set + `useState` for re-renders. See espacosmart's useCart.ts as template.
159
+
160
+ **Exit**: Cart add/remove works, no `apps/{platform}/hooks` imports
161
+
162
+ See: `references/platform-hooks/README.md`, skill `deco-apps-vtex-porting`
163
+
164
+ ---
165
+
166
+ ### Phase 6 — Islands Elimination
167
+
168
+ **Entry**: Phase 5 complete
169
+
170
+ **Actions**:
171
+ 1. Audit `src/islands/` — categorize each file:
172
+ - **Wrapper**: just re-exports from `components/` → delete, repoint imports
173
+ - **Standalone**: has real logic → move to `src/components/`
174
+ 2. Update all imports pointing to `islands/` to point to `components/`
175
+ 3. Delete `src/islands/` directory
176
+
177
+ **Verification**: `ls src/islands/ 2>/dev/null` → directory not found
178
+
179
+ **Exit**: No islands/ directory
180
+
181
+ See: skill `deco-islands-migration`
182
+
183
+ ---
184
+
185
+ ### Phase 7 — Section Registry
186
+
187
+ **Entry**: Phase 6 complete
188
+
189
+ **Actions** (critical — build `src/setup.ts`):
190
+ 1. Register all sections via `registerSections()` with dynamic imports
191
+ 2. Register critical sections (Header, Footer) via `registerSectionsSync()` + `setResolvedComponent()`
192
+ 3. Register section loaders via `registerSectionLoaders()` for sections with `export const loader`
193
+ 4. Register layout sections via `registerLayoutSections()`
194
+ 5. Register commerce loaders via `registerCommerceLoaders()` with SWR caching
195
+ 6. Wire `onBeforeResolve()` → `initVtexFromBlocks()` for VTEX config
196
+ 7. Configure `setAsyncRenderingConfig()` with `alwaysEager` for critical sections
197
+ 8. Configure admin: `setMetaData()`, `setRenderShell()`, `setInvokeLoaders()`
198
+
199
+ **Template**: `templates/setup-ts.md`
200
+
201
+ **Exit**: `setup.ts` compiles, all sections registered
202
+
203
+ See: skill `deco-async-rendering-site-guide`
204
+
205
+ ---
206
+
207
+ ### Phase 8 — Routes & CMS
208
+
209
+ **Entry**: Phase 7 complete
210
+
211
+ **Actions**:
212
+ 1. Create `src/router.tsx` with scroll restoration
213
+ 2. Create `src/routes/__root.tsx` with QueryClient, LiveControls, NavigationProgress, analytics
214
+ 3. Create `src/routes/index.tsx` using `cmsHomeRouteConfig()`
215
+ 4. Create `src/routes/$.tsx` using `cmsRouteConfig()`
216
+
217
+ **Templates**: `templates/root-route.md`, `templates/router.md`
218
+
219
+ **Exit**: Routes compile, CMS pages resolve
220
+
221
+ See: skill `deco-tanstack-navigation`
222
+
223
+ ---
224
+
225
+ ### Phase 9 — Worker Entry
226
+
227
+ **Entry**: Phase 8 complete
228
+
229
+ **Actions**:
230
+ 1. Create `src/server.ts` — **CRITICAL: `import "./setup"` MUST be the first line**
231
+ 2. Create `src/worker-entry.ts` — same: `import "./setup"` first
232
+ 3. Wire admin handlers (handleMeta, handleDecofileRead, handleRender)
233
+ 4. Wire VTEX proxy if needed
234
+
235
+ **Template**: `templates/worker-entry.md`
236
+
237
+ **CRITICAL**: Without `import "./setup"` as the first import, server functions in Vite split modules will have empty state (blocks, registry, commerce loaders). This causes 404 on client-side navigation.
238
+
239
+ **Exit**: `npm run dev` serves pages, admin endpoints work
240
+
241
+ See: skill `deco-edge-caching`
242
+
243
+ ---
244
+
245
+ ### Phase 10 — Async Rendering
246
+
247
+ **Entry**: Phase 9 complete (site builds and serves pages)
248
+
249
+ **Actions**:
250
+ 1. Identify lazy sections from CMS Lazy wrappers
251
+ 2. Add `export function LoadingFallback()` to lazy sections
252
+ 3. Configure `registerCacheableSections()` for SWR on heavy sections
253
+ 4. Test deferred section loading on scroll
254
+
255
+ **Exit**: Above-the-fold renders instantly, below-fold loads on scroll
256
+
257
+ See: skill `deco-async-rendering-site-guide`
258
+
259
+ ---
260
+
261
+ ## Post-Migration Verification
262
+
263
+ ```bash
264
+ # 1. Build
265
+ npm run build
266
+
267
+ # 2. Zero old imports
268
+ grep -rE 'from "(preact|@preact|@deco/deco|\$fresh|deco-sites/|apps/)' src/ | wc -l
269
+ # Expected: 0
270
+
271
+ # 3. Dev server
272
+ npm run dev
273
+
274
+ # 4. SSR test — load homepage via F5
275
+ # 5. Client nav — click links, verify no 404
276
+ # 6. Console — no hydration warnings, no missing keys
277
+ # 7. Deferred — scroll down, sections load on scroll
278
+ # 8. Admin — /deco/meta returns JSON, /live/previews works
279
+ ```
280
+
281
+ ## Key Principles
282
+
283
+ 1. **No compat layer anywhere** -- not in `@decocms/start`, not in `@decocms/apps`, not in the site repo
284
+ 2. **Replace, don't wrap** -- change the import to the real thing, don't create a pass-through
285
+ 3. **Types from the library, UI from the site** -- `Product` type comes from `@decocms/apps/commerce/types`, but the `<Image>` component is site-local
286
+ 4. **One Vite alias maximum** -- `"~"` -> `"src/"` is the only acceptable alias in a finished migration
287
+ 5. **`tsconfig.json` mirrors `vite.config.ts`** -- only `"~/*": ["./src/*"]` in paths
288
+ 6. **Signals don't auto-subscribe in React** -- reading `signal.value` in render creates NO subscription; use `useStore(signal.store)` from `@tanstack/react-store`
289
+ 7. **Commerce loaders need request context** -- `resolve.ts` must pass URL/path to PLP/PDP loaders for search, categories, sort, and pagination to work
290
+ 8. **`wrangler.jsonc` main must be a custom worker-entry** -- TanStack Start ignores `export default` in `server.ts`; create a separate `worker-entry.ts` and point wrangler to it
291
+ 9. **Copy components faithfully, never rewrite** -- `cp` the original file, then only change: `class` → `className`, `for` → `htmlFor`, import paths (`apps/` → `~/`, `$store/` → `~/`), `preact` → `react`. NEVER regenerate, "clean up", or "improve" the component. AI-rewritten components are the #1 source of visual regressions -- the layout, grid classes, responsive variants, and conditional logic must be byte-identical to the original except for the mechanical migration changes
292
+ 10. **Tailwind v4 logical property hazard** -- mixed `px-*` + `pl-*/pr-*` on the same element breaks the cascade. Replace mixed patterns with consistent longhand (`pl-X pr-X` instead of `px-X`) on those elements only
293
+ 11. **oklch CSS variables need triplets, not hex** -- sites using `oklch(var(--x))` must store variables as oklch triplets (`100% 0.00 0deg`), not hex values. `oklch(#FFF)` is invalid CSS
294
+ 12. **Verify ALL imports resolve at runtime, not just build** -- Vite tree-shakes dead imports, so `npm run build` passes even with missing modules. But `registerSections` lazy imports execute at runtime, killing entire sections silently
295
+ 13. **`import "./setup"` first** — in both `server.ts` and `worker-entry.ts`
296
+ 14. **globalThis for split modules** — Vite server function split modules need `globalThis.__deco` to share state
297
+
298
+ ## Worker Entry Architecture
299
+
300
+ The Cloudflare Worker entry point has a strict layering. Admin routes MUST be handled in `createDecoWorkerEntry` (the outermost wrapper), NOT inside TanStack's `createServerEntry`. TanStack Start's Vite build strips custom logic from `createServerEntry` callbacks in production.
301
+
302
+ ```
303
+ Request
304
+ └─> createDecoWorkerEntry(serverEntry, { admin: { ... } })
305
+ ├─> tryAdminRoute() ← FIRST: /live/_meta, /.decofile, /live/previews/*
306
+ ├─> cache purge check ← __deco_purge_cache
307
+ ├─> static asset bypass ← /assets/*, favicon, sprites
308
+ ├─> Cloudflare cache (caches.open)
309
+ └─> serverEntry.fetch() ← TanStack Start handles everything else
310
+ ```
311
+
312
+ ### Site worker-entry.ts Pattern
313
+
314
+ ```typescript
315
+ import "./setup";
316
+ import handler, { createServerEntry } from "@tanstack/react-start/server-entry";
317
+ import { createDecoWorkerEntry } from "@decocms/start/sdk/workerEntry";
318
+ import {
319
+ handleMeta, handleDecofileRead, handleDecofileReload,
320
+ handleRender, corsHeaders,
321
+ } from "@decocms/start/admin";
322
+
323
+ const serverEntry = createServerEntry({
324
+ async fetch(request) {
325
+ return await handler.fetch(request);
326
+ },
327
+ });
328
+
329
+ export default createDecoWorkerEntry(serverEntry, {
330
+ admin: { handleMeta, handleDecofileRead, handleDecofileReload, handleRender, corsHeaders },
331
+ });
332
+ ```
333
+
334
+ Key rules:
335
+ - `./setup` MUST be imported first (registers sections, loaders, meta, render shell)
336
+ - Admin handlers are passed as options, NOT imported inside `createDecoWorkerEntry`
337
+ - `/live/` and `/.decofile` are in `DEFAULT_BYPASS_PATHS` -- never cached by the edge
338
+
339
+ ### Admin Preview HTML Shell
340
+
341
+ The preview at `/live/previews/*` renders sections into an HTML shell. This shell MUST match the production `<html>` attributes for CSS frameworks to work:
342
+
343
+ ```typescript
344
+ // In setup.ts
345
+ setRenderShell({
346
+ css: appCss, // Vite ?url import of app.css
347
+ fonts: ["https://fonts.googleapis.com/css2?family=Montserrat:wght@400;500;600;700&display=swap"],
348
+ theme: "light", // -> <html data-theme="light"> (required for DaisyUI v4)
349
+ bodyClass: "bg-base-100 text-base-content",
350
+ lang: "pt-BR",
351
+ });
352
+ ```
353
+
354
+ Without `data-theme="light"`, DaisyUI v4 theme variables (`--color-primary`, etc.) won't activate in the preview iframe, causing color mismatches vs production.
355
+
356
+ ### Client-Safe vs Server-Only Imports
357
+
358
+ `@decocms/start` has two admin entry points:
359
+ - **`@decocms/start/admin`** -- server-only handlers (handleMeta, handleRender, etc.) -- these may transitively import `node:async_hooks`
360
+ - **`@decocms/start/admin/setup`** (re-exported from `@decocms/start/admin`) -- client-safe setup functions (setMetaData, setInvokeLoaders, setRenderShell) -- NO node: imports
361
+
362
+ The site's `setup.ts` can safely import from `@decocms/start/admin` because it only uses the setup functions. But the barrel export must be structured so Vite tree-shaking doesn't pull server modules into client bundles.
363
+
364
+ ## Admin Self-Hosting Architecture
365
+
366
+ When a site is self-hosted (deployed to its own Cloudflare Worker), the admin communicates with the storefront via the `productionUrl`:
367
+
368
+ ```
369
+ admin.deco.cx
370
+ └─> createContentSiteSDK (when env.platform === "content" OR devContentUrl is set)
371
+ ├─> fetch(productionUrl + "/live/_meta") ← schema + manifest
372
+ ├─> fetch(productionUrl + "/.decofile") ← content blocks
373
+ └─> iframe src = productionUrl + "/live/previews/*" ← section preview
374
+ ```
375
+
376
+ ### Content URL Resolution Priority
377
+
378
+ 1. `devContentUrl` URL param → saved to `localStorage[deco::devContentUrl::${site}]` → used by Content SDK
379
+ 2. `devContentUrl` from localStorage → used by Content SDK
380
+ 3. `site.metadata.selfHosting.productionUrl` (Supabase) → used by Content SDK
381
+ 4. `https://${site}.deco.site` → fallback
382
+
383
+ ### Environment Platform Gate
384
+
385
+ The admin only uses `createContentSiteSDK` when:
386
+ - `devContentUrl` is set (localStorage or URL param), OR
387
+ - The current environment has `platform: "content"`
388
+
389
+ Setting `productionUrl` in Supabase alone is NOT sufficient. The environment must be "content" platform. This happens when `connectSelfHosting` is called with a `productionUrl` -- it deletes/recreates the staging environment as `platform: "content"`.
390
+
391
+ For local dev, use the URL param shortcut:
392
+ ```
393
+ https://admin.deco.cx/sites/YOUR_SITE/spaces/...?devContentUrl=http://localhost:5181
394
+ ```
395
+
396
+ ## Admin / CMS Schema Architecture
397
+
398
+ The deco admin (deco-cx/deco) communicates with the storefront via:
399
+ - `GET /live/_meta` -- returns full JSON Schema + manifest of block types
400
+ - `GET /.decofile` -- returns the site's content blocks
401
+ - `POST /deco/render` -- renders a section/page with given props in an iframe
402
+ - `POST /deco/invoke` -- calls a loader/action and returns JSON
403
+
404
+ ### Schema Composition (`composeMeta`)
405
+
406
+ The schema generator (`scripts/generate-schema.ts`) only produces section schemas from site TypeScript files. Framework-managed block types (pages) are defined in `src/admin/schema.ts` and injected at runtime via `composeMeta()`.
407
+
408
+ ```
409
+ [generate-schema.ts] --> meta.gen.json (sections only, pages: empty)
410
+ [setup.ts] --> imports meta.gen.json --> calls setMetaData(metaData)
411
+ [setMetaData] --> calls composeMeta() --> injects page schema + merges definitions
412
+ [/live/_meta] --> returns composed schema with content-hash ETag
413
+ ```
414
+
415
+ Key rules:
416
+ - `toBase64()` MUST produce padded Base64 (matching `btoa()`) -- admin uses `btoa()` to construct definition refs
417
+ - Page schema uses flat properties (no allOf + @Props indirection) to minimize RJSF resolution steps
418
+ - ETag is a content-based DJB2 hash, not string length, for reliable cache invalidation
419
+ - The etag is also included in the JSON response body for admin's `metaInfo.value?.etag` cache check
420
+
421
+ ### Admin Local Development
422
+
423
+ To use the deco admin with a local storefront:
424
+ 1. Start admin: `cd admin && deno task play` (port 4200)
425
+ 2. Start storefront: `bun run dev` (port 5181 or wherever it lands)
426
+ 3. Set `devContentUrl` in admin's browser console: `localStorage.setItem('deco::devContentUrl::YOUR_SITE_NAME', 'http://localhost:PORT')`
427
+ 4. Navigate to `http://localhost:4200/sites/YOUR_SITE_NAME/spaces/pages`
428
+ 5. After schema changes: clear admin cache (`localStorage.removeItem('meta::YOUR_SITE_NAME')`) and hard-refresh
429
+
430
+ ## Conductor / AI Bulk Migration Workflow
431
+
432
+ For sites with 100+ sections and 200+ components, manual file-by-file migration is impractical. The proven workflow:
433
+
434
+ ### Phase 1: Scaffold + Copy (human)
435
+ 1. Scaffold TanStack Start project
436
+ 2. `cp -r` the entire `src/` from the original site
437
+ 3. Set up `vite.config.ts`, `tsconfig.json`, `wrangler.jsonc`, `package.json`
438
+ 4. Install dependencies
439
+
440
+ ### Phase 2: Mechanical Rewrites (AI/conductor)
441
+ Let AI tackle the bulk TypeScript errors in a single pass:
442
+
443
+ 1. **Import rewrites** (safe for bulk `sed`):
444
+ - `from "preact"` → `from "react"`
445
+ - `from "preact/hooks"` → `from "react"`
446
+ - `from "preact/compat"` → `from "react"`
447
+ - `from "@preact/signals"` → `from "~/sdk/signal"`
448
+ - `from "apps/commerce/types"` → `from "@decocms/apps/commerce/types"`
449
+ - `from "$store/"` → `from "~/"`
450
+
451
+ 2. **JSX attribute rewrites** (safe for bulk):
452
+ - `class=` → `className=` (in JSX context)
453
+ - `for=` → `htmlFor=` (on `<label>` elements)
454
+ - `stroke-width` → `strokeWidth`, `fill-rule` → `fillRule` (SVG)
455
+ - Remove `data-fresh-disable-lock`
456
+
457
+ 3. **Type rewrites** (per-file, AI-assisted):
458
+ - `JSX.TargetedEvent<HTMLInputElement>` → `React.ChangeEvent<HTMLInputElement>`
459
+ - `JSX.TargetedMouseEvent` → `React.MouseEvent`
460
+ - `ComponentChildren` → `ReactNode`
461
+ - `SVGAttributes<SVGSVGElement>` → `React.SVGProps<SVGSVGElement>`
462
+ - Create consolidated type files (`~/types/vtex.ts`, `~/types/widgets.ts`)
463
+
464
+ 4. **Signal-to-state** (per-file, needs judgment):
465
+ - `useSignal(x)` → `useState(x)` with setter
466
+ - `.value` reads → direct variable reads
467
+ - `.value =` writes → `setState()` calls
468
+ - Toggle: `x.value = !x.value` → `setX(prev => !prev)`
469
+
470
+ ### Phase 3: Verify (human + AI)
471
+ 1. `npx tsc --noEmit` — catches remaining type errors
472
+ 2. `npm run build` — catches import resolution errors
473
+ 3. `bun run dev` + browser test — catches runtime errors
474
+ 4. Visual comparison with production — catches layout regressions
475
+
476
+ ### Phase 4: Fix Runtime Issues (human-guided)
477
+ This is where gotchas 1-45 apply. The mechanical rewrite gets you to "builds clean" but runtime issues require understanding the architectural differences.
478
+
479
+ ### Key Insight: Never Rewrite, Only Port
480
+
481
+ The conductor approach that worked (836 errors → 0 across 213 files) treated every file as: **copy the original, apply mechanical changes only**. The failed approach was: "look at the original and rewrite it in React" — this produced components that looked similar in code but rendered completely differently because of subtle grid/flex/responsive differences.
482
+
483
+ ## Reference Index
484
+
485
+ | Topic | Path |
486
+ |-------|------|
487
+ | Preact → React imports | `references/imports/` |
488
+ | Signals → TanStack Store | `references/signals/` |
489
+ | Deco framework elimination | `references/deco-framework/` |
490
+ | Commerce & widget types | `references/commerce/` |
491
+ | Platform hooks (VTEX) | `references/platform-hooks/` |
492
+ | Vite configuration | `references/vite-config/` |
493
+ | Automation commands | `references/codemod-commands.md` |
494
+ | Admin schema composition | `src/admin/schema.ts` in `@decocms/start` |
495
+ | Common gotchas (45 items) | `references/gotchas.md` |
496
+ | setup.ts template | `templates/setup-ts.md` |
497
+ | vite.config.ts template | `templates/vite-config.md` |
498
+ | worker-entry template | `templates/worker-entry.md` |
499
+ | __root.tsx template | `templates/root-route.md` |
500
+ | router.tsx template | `templates/router.md` |
501
+ | package.json template | `templates/package-json.md` |
502
+
503
+ ## Related Skills
504
+
505
+ | Skill | Use When |
506
+ |-------|----------|
507
+ | deco-apps-vtex-porting | Understanding VTEX loader internals (Phase 4-5) |
508
+ | deco-islands-migration | Eliminating islands/ (Phase 6) |
509
+ | deco-async-rendering-site-guide | Lazy wrappers, LoadingFallback (Phase 7, 10) |
510
+ | deco-tanstack-navigation | Link, prefetch, scroll issues (Phase 8) |
511
+ | deco-edge-caching | Worker caching, cache profiles (Phase 9) |
512
+ | deco-tanstack-hydration-fixes | Hydration mismatches post-migration |
513
+ | deco-tanstack-search | Search page not working |
514
+ | deco-typescript-fixes | Bulk TypeScript error resolution |
515
+ | deco-start-architecture | Understanding @decocms/start internals |
516
+ | deco-tanstack-storefront-patterns | Runtime bugs after migration |
517
+ | deco-server-functions-invoke | Server function patterns |
518
+ | deco-tanstack-data-flow | Data flow architecture |