From 3ed3bce2f533aa4c83a94e67ad6ee91be858fde9 Mon Sep 17 00:00:00 2001 From: Guilherme Rodrigues Date: Wed, 3 Sep 2025 19:17:16 -0300 Subject: [PATCH 1/3] Add site migration plan prompt --- .../prompts/deco-cx-store-migration-plan.md | 432 ++++++++++++++++++ 1 file changed, 432 insertions(+) create mode 100644 website/prompts/deco-cx-store-migration-plan.md diff --git a/website/prompts/deco-cx-store-migration-plan.md b/website/prompts/deco-cx-store-migration-plan.md new file mode 100644 index 000000000..0db86f2ea --- /dev/null +++ b/website/prompts/deco-cx-store-migration-plan.md @@ -0,0 +1,432 @@ +# Deco.cx Store Update & Migration Plan + +**Version:** 1.0 +**Date:** September 2025 +**Target Audience:** AI Coding Agents & Developers + +This comprehensive guide outlines the migration patterns and fixes required to upgrade older deco.cx stores based on analysis of recent fixes applied to jasmine, brandili, tools-dna, and apps repositories. + +## 🎯 Overview + +The deco.cx framework has evolved significantly, and older stores require systematic updates to maintain compatibility, performance, and security. This guide covers the most common issues found in legacy stores and their solutions. + +## 🔧 Key Migration Areas + +### 1. Dependency Management & Updates + +#### 1.1 Core Dependencies Update +**Issue:** Outdated deco.cx core dependencies causing compatibility issues. + +**Solution:** +```json +// deno.json - Update to latest stable versions +{ + "imports": { + "deco/": "https://cdn.jsdelivr.net/gh/deco-cx/deco@1.120.11/", + "apps/": "https://cdn.jsdelivr.net/gh/deco-cx/apps@0.121.0/", + "@deco/deco": "jsr:@deco/deco@1.120.11", + "@deco/dev": "jsr:@deco/dev@1.120.11", + "$fresh/": "https://deno.land/x/fresh@1.7.3/" + } +} +``` + +#### 1.2 Standard Library Migration +**Issue:** Old `std/` imports causing deprecation warnings. + +**Solution:** +- Migrate from `https://deno.land/std@0.190.0/` to JSR-based imports: +```json +"@std/assert": "jsr:@std/assert@^1.0.2", +"@std/async": "jsr:@std/async@^0.224.1", +"@std/crypto": "jsr:@std/crypto@1.0.0-rc.1", +"@std/encoding": "jsr:@std/encoding@^1.0.0-rc.1", +"@std/http": "jsr:@std/http@^1.0.0" +``` + +#### 1.3 Remove Unnecessary Dependencies +**Common removals:** +- Remove unused social-library imports +- Clean up stray PostCSS version overrides +- Remove deprecated partytown references + +### 2. DecoHub Cleanup & App Restructuring + +#### 2.1 Remove Legacy DecHub References +**Issue:** Old `apps/decohub.ts` files and related blocks causing errors. + +**Actions:** +1. Delete `apps/decohub.ts` file +2. Remove DecHub-related blocks from `.deco/blocks/`: + - `Deco%20HUB.json` + - `Workflows.json` (if DecHub-specific) + - `sales-assistant.json` + - `weather.json` + - `files.json` + +#### 2.2 Migrate to Namespaced Apps Structure +**Pattern:** Migrate from direct app imports to `apps/deco/` namespacing. + +**Before:** +``` +apps/ +├── decohub.ts (delete) +├── algolia.ts (move) +├── analytics.ts (move) +└── vtex.ts (move) +``` + +**After:** +``` +apps/ +├── deco/ +│ ├── algolia.ts +│ ├── analytics.ts +│ ├── htmx.ts +│ ├── vtex.ts +│ └── workflows.ts +└── site.ts +``` + +**File content example:** +```typescript +// apps/deco/analytics.ts +export { default } from "apps/analytics/mod.ts"; +export * from "apps/analytics/mod.ts"; +``` + +### 3. SEO Component Updates + +#### 3.1 Migrate to SEOPLPv2 & SEOPDPv2 +**Issue:** Outdated SEO components causing SSR compatibility issues. + +**Actions:** +1. Update product pages to use `SeoPDPV2.tsx` +2. Update category pages to use `SeoPLPV2.tsx` +3. Remove old SEO component previews from `.deco/blocks/` + +#### 3.2 Add Missing Image Dimensions +**Issue:** Images without proper dimensions causing layout shifts. + +**Fix:** Ensure all components have proper `width` and `height` attributes: +```typescript +// components/footer/Logo.tsx +{alt} +``` + +### 4. Performance Optimizations + +#### 4.1 Enable Async Render for Better Performance +**Issue:** Synchronous rendering causing slower page loads and poor user experience. + +**Solution:** +Implement async render for sections to reduce server-to-browser resource transfer and optimize loading performance. + +**Benefits:** +- Reduced initial page load time +- Better perceived performance +- Optimized resource utilization +- Improved user experience metrics + +**Implementation:** +1. **Configure sections for async rendering:** +```typescript +// sections/YourSection.tsx +export interface Props { + // Your existing props + asyncRender?: boolean; // Add async render flag +} + +export default function YourSection(props: Props) { + // Section implementation +} + +// Add async configuration to section metadata +export const loader = async (props: Props, req: Request) => { + // If async render enabled, return minimal data first + if (props.asyncRender) { + return { + ...props, + placeholder: true + }; + } + // Full data loading logic +}; +``` + +2. **Enable in section blocks:** +```json +// .deco/blocks/your-section.json +{ + "asyncRender": true, + "loadingStrategy": "lazy", + "priority": "low" +} +``` + +**Performance Monitoring:** +- Monitor async render performance via deco.cx analytics +- Analyze section size optimization impact +- Track loading time improvements + +#### 4.2 Implement Shared Loaders +**Issue:** Multiple duplicate API calls on category and search pages. + +**Solution:** +Create shared loaders to reduce redundant requests: +```json +// .deco/blocks/Shared Category Loader.json +// .deco/blocks/Shared Search Loader.json +``` + +#### 4.2 Add Loading States & Error Handling +**Pattern:** Add proper loading fallbacks and dev-only error display. + +```typescript +// sections/Component.tsx +export default function Component({ loader }: Props) { + if (!loader) { + if (Deno.env.get("DENO_ENV") === "development") { + return
Error: Missing loader configuration
; + } + return
Loading...
; + } + + return ; +} +``` + +### 5. Search & Filter Improvements + +#### 5.1 Fix Search Parameter Handling +**Issue:** Search forms sending '+' instead of '%20' for spaces. + +**Fix:** +```typescript +// components/search/SearchForm.tsx +const handleSubmit = (e: FormEvent) => { + e.preventDefault(); + const query = searchTerm.replace(/\+/g, ' ').trim(); + const encodedQuery = encodeURIComponent(query); + window.location.href = `/search?q=${encodedQuery}`; +}; +``` + +#### 5.2 Implement Price Range Filters +**Issue:** Missing or broken price filtering functionality. + +**Solution:** Update filter components with proper min/max handling and form submission. + +### 6. Build System & Configuration Updates + +#### 6.1 Update deno.json Configuration +**Required changes:** +```json +{ + "nodeModulesDir": true, // Keep as true, "auto" fails in K8s production + "lock": false, + "exclude": [ + "node_modules", + "static/", + "README.md", + "_fresh", + "**/_fresh/*", + ".deco" + ], + "lint": { + "rules": { + "exclude": ["no-window"], + "tags": ["fresh", "recommended"] + } + } +} +``` + +#### 6.2 Update Fresh Configuration +**File:** `fresh.config.ts` +```typescript +import { defineConfig } from "$fresh/server.ts"; +import plugins from "https://deno.land/x/fresh_charts@0.3.1/mod.ts"; + +export default defineConfig({ + plugins: [plugins], +}); +``` + +#### 6.3 Regenerate Manifest +**Action:** Always regenerate `manifest.gen.ts` after app structure changes: +```bash +deno task gen +``` + +### 7. SEO & Robots.txt Setup + +#### 7.1 Add robots.txt +**File:** `static/robots.txt` +``` +User-agent: * +Disallow: / + +User-agent: Googlebot +Allow: / +Disallow: /live/ +Disallow: /live/* +Sitemap: https://yourdomain.com/sitemap.xml +``` + +#### 7.2 Middleware for Bot Detection +Add bot detection and caching in `routes/_middleware.ts`. + +### 8. SSR Compatibility Fixes + +#### 8.1 Window Object Checks +**Issue:** Direct window access causing SSR failures. + +**Fix:** +```typescript +// Use proper guards +if (typeof window !== 'undefined') { + // Browser-only code +} +``` + +#### 8.2 Component Lazy Loading +Implement proper lazy loading for heavy components: +```typescript +// Use dynamic imports for client-side only components +const ClientOnlyComponent = lazy(() => import("../islands/ClientComponent.tsx")); +``` + +## 🚀 Migration Checklist + +### Phase 1: Dependencies & Structure +- [ ] Update core deco.cx dependencies to latest stable versions +- [ ] Migrate std library imports to JSR +- [ ] Remove unnecessary dependencies +- [ ] Clean up DecHub references +- [ ] Restructure apps directory with proper namespacing + +### Phase 2: Components & SEO +- [ ] Update SEO components to v2 versions +- [ ] Add missing image dimensions +- [ ] Fix SSR compatibility issues +- [ ] Update search parameter handling + +### Phase 3: Performance & Caching +- [ ] Enable async render for heavy sections (ProductShelf, CategoryList, etc.) +- [ ] Implement shared loaders +- [ ] Add cache middleware +- [ ] Add loading states and error handling +- [ ] Optimize component rendering + +### Phase 4: Configuration & Build +- [ ] Update deno.json configuration +- [ ] Update Fresh configuration +- [ ] Add/update robots.txt +- [ ] Regenerate manifest files +- [ ] Test build and deployment + +## 🔍 Common Issues & Solutions + +### Issue: "Module not found" errors +**Cause:** Outdated import paths or missing dependencies +**Solution:** Update import maps in deno.json and regenerate manifest + +### Issue: SSR hydration mismatches +**Cause:** Client-server rendering differences +**Solution:** Add proper typeof window checks and use islands for dynamic content + +### Issue: Performance degradation +**Cause:** Multiple duplicate API calls +**Solution:** Implement shared loaders and proper caching + +### Issue: SEO problems +**Cause:** Missing or outdated SEO components +**Solution:** Migrate to latest SEO component versions + +## 🤖 Evolution Agent Workflow Menu + +These are key optimization workflows that can be applied to any deco.cx store: + +### Quick Optimization Menu +1. **Enable Async Render** - Apply async rendering to heavy sections for performance +2. **Update Dependencies** - Migrate to latest stable versions +3. **Clean DecHub References** - Remove legacy DecHub imports and blocks +4. **Implement Caching** - Add cache middleware for bot traffic +5. **Fix SEO Components** - Update to latest SEO component versions +6. **Add Shared Loaders** - Reduce duplicate API calls +7. **SSR Compatibility Check** - Fix window object access issues + +### Async Render Activation Workflow +**When to use:** Any store with slow loading sections (ProductShelf, CategoryList, SearchResults) + +**Steps:** +1. Identify heavy sections in the store +2. Add async render configuration to section props +3. Update section blocks with async settings +4. Test performance improvements +5. Monitor loading metrics + +**Priority sections for async render:** +- ProductShelf components +- CategoryList sections +- SearchResult displays +- Complex filter components +- Image-heavy carousels + +## 📋 Automated Migration Script Template + +```bash +#!/bin/bash + +# 1. Backup current state +git checkout -b migration-backup + +# 2. Update dependencies +echo "Updating dependencies..." +# Update deno.json with latest versions + +# 3. Clean up structure +echo "Cleaning up DecHub references..." +rm -f apps/decohub.ts +rm -f .deco/blocks/Deco\ HUB.json + +# 4. Enable async render for performance sections +echo "Configuring async render..." +# Update heavy sections with async configuration + +# 5. Regenerate manifest +echo "Regenerating manifest..." +deno task gen + +# 6. Run checks +echo "Running checks..." +deno task check + +# 7. Test build +echo "Testing build..." +deno task build +``` + +## 🎯 Success Metrics + +After migration, verify: +- [ ] All TypeScript checks pass +- [ ] Build completes without errors +- [ ] No console errors in browser +- [ ] SEO components render properly +- [ ] Performance metrics improved +- [ ] Cache headers present for bot traffic + +--- + +**Note:** Always test migrations in a staging environment before applying to production. Keep backups of working configurations. + +**Last Updated:** September 2025 +**Framework Version:** Deco.cx 1.120.11+ \ No newline at end of file From a33d248c35b5876a3ed2ff9997c7d0f6725773f7 Mon Sep 17 00:00:00 2001 From: Guilherme Rodrigues Date: Thu, 4 Sep 2025 16:36:28 -0300 Subject: [PATCH 2/3] Update migration plan --- .../prompts/deco-cx-store-migration-plan.md | 66 ++++++++++++++----- 1 file changed, 49 insertions(+), 17 deletions(-) diff --git a/website/prompts/deco-cx-store-migration-plan.md b/website/prompts/deco-cx-store-migration-plan.md index 0db86f2ea..b8eeebdde 100644 --- a/website/prompts/deco-cx-store-migration-plan.md +++ b/website/prompts/deco-cx-store-migration-plan.md @@ -259,12 +259,6 @@ export default defineConfig({ }); ``` -#### 6.3 Regenerate Manifest -**Action:** Always regenerate `manifest.gen.ts` after app structure changes: -```bash -deno task gen -``` - ### 7. SEO & Robots.txt Setup #### 7.1 Add robots.txt @@ -306,8 +300,9 @@ const ClientOnlyComponent = lazy(() => import("../islands/ClientComponent.tsx")) ## 🚀 Migration Checklist ### Phase 1: Dependencies & Structure -- [ ] Update core deco.cx dependencies to latest stable versions -- [ ] Migrate std library imports to JSR +- [ ] **Start with `deno task update`** - Update all dependencies to latest versions first +- [ ] Update core deco.cx dependencies to latest stable versions (1.120.11+) +- [ ] Migrate std library imports to JSR (handled by deno task update) - [ ] Remove unnecessary dependencies - [ ] Clean up DecHub references - [ ] Restructure apps directory with proper namespacing @@ -350,6 +345,47 @@ const ClientOnlyComponent = lazy(() => import("../islands/ClientComponent.tsx")) **Cause:** Missing or outdated SEO components **Solution:** Migrate to latest SEO component versions +## 📚 Lessons Learned from Real Migration Work + +Based on analyzing the miess-01 repository and applying fixes: + +### ✅ **What Works Well in Existing Stores** +- **Apps structure already migrated**: Many stores have already been updated to use `apps/deco/` namespacing +- **No DecHub references**: Most legacy DecHub cleanup has already been done +- **Good SEO foundation**: Custom SEO components and robots.txt are properly configured +- **Proper image handling**: Many components already use explicit dimensions and Picture components + +### 🔧 **Critical Fixes Often Needed** +1. **Dependency versions**: Always update deco.cx core to latest stable (1.120.11+) +2. **Window object guards**: Analytics and client-side code needs `typeof window !== 'undefined'` checks +3. **Search parameter encoding**: Use `encodeURIComponent()` instead of manual string replacement +4. **Image dimensions**: Add explicit `width` and `height` attributes to prevent layout shifts +5. **Fresh config plugins**: Ensure `tailwind` is passed to plugins configuration + +### 🎯 **Common Patterns for Window Guards** +```typescript +// ❌ Bad - Direct window access +window.DECO.events.dispatch(event) + +// ✅ Good - With guards +if (typeof window !== 'undefined' && window.DECO?.events) { + window.DECO.events.dispatch(event) +} +``` + +### 🚫 **Don't Need to Regenerate Manifest** +After dependency updates, you DON'T need to run `deno task gen` - this was a misconception in earlier migration guides. The build process handles this automatically. + +### 🔄 **Std Import Migration is Automatic** +When you run `deno task update`, Deno automatically handles the migration of `std/` imports to JSR `@std/` imports. **DO NOT** manually change import statements in your code files - let Deno handle this automatically through its dependency resolution. + +### ⚡ **Priority Order for Fixes** +1. **SSR compatibility** (window guards) - prevents runtime errors +2. **Dependency updates** - ensures compatibility and security +3. **Performance optimizations** - image dimensions, async render +4. **Search functionality** - parameter encoding affects UX +5. **Build configuration** - nodeModulesDir, excludes + ## 🤖 Evolution Agent Workflow Menu These are key optimization workflows that can be applied to any deco.cx store: @@ -388,9 +424,9 @@ These are key optimization workflows that can be applied to any deco.cx store: # 1. Backup current state git checkout -b migration-backup -# 2. Update dependencies -echo "Updating dependencies..." -# Update deno.json with latest versions +# 2. Update dependencies (includes automatic std import migration) +echo "Updating dependencies and migrating std imports automatically..." +deno task update # 3. Clean up structure echo "Cleaning up DecHub references..." @@ -401,15 +437,11 @@ rm -f .deco/blocks/Deco\ HUB.json echo "Configuring async render..." # Update heavy sections with async configuration -# 5. Regenerate manifest -echo "Regenerating manifest..." -deno task gen - -# 6. Run checks +# 5. Run checks echo "Running checks..." deno task check -# 7. Test build +# 6. Test build echo "Testing build..." deno task build ``` From ce395edfcbb8b7d580c88675d65486cc05a0a0fb Mon Sep 17 00:00:00 2001 From: Guilherme Rodrigues Date: Sat, 6 Sep 2025 12:41:38 -0300 Subject: [PATCH 3/3] Add more docs --- .../deco-cx-error-handling-patterns.md | 351 ++++++++++++++ .../deco-cx-production-issues-stacktraces.md | 438 ++++++++++++++++++ .../prompts/deco-cx-store-migration-plan.md | 63 ++- 3 files changed, 838 insertions(+), 14 deletions(-) create mode 100644 website/prompts/deco-cx-error-handling-patterns.md create mode 100644 website/prompts/deco-cx-production-issues-stacktraces.md diff --git a/website/prompts/deco-cx-error-handling-patterns.md b/website/prompts/deco-cx-error-handling-patterns.md new file mode 100644 index 000000000..9c086d9fa --- /dev/null +++ b/website/prompts/deco-cx-error-handling-patterns.md @@ -0,0 +1,351 @@ +# Deco.cx Error Handling & Security Patterns + +**Version:** 1.0 +**Date:** September 2025 +**Target Audience:** AI Coding Agents & Developers +**Parent Guide:** [deco-cx-store-migration-plan.md](./deco-cx-store-migration-plan.md) + +This document contains real-world error handling patterns and security fixes derived from analyzing recent commits in production deco.cx stores. + +## 🛡️ Security & Input Sanitization Patterns + +### 1. Search Parameter Sanitization + +**Real Issue Found:** VTEX search API was receiving malformed query strings and embedded data URIs causing 500 errors. + +**Stack Trace Example:** +``` +SearchResult: failed to load productListingPage err=Request failed with status 500 +url=https://example-store.deco.site/search?q=product+data:text/html,