Fynd Theme Best Practices
Quick Start Decision Tree
Use this skill when the request involves:
- "Where is X feature?" → Codebase navigation workflow
- "How do I implement Y?" → Best practices + pattern workflow
- "This isn't working" → Debugging workflow
- "What's wrong with this code?" → Code review workflow
- "How do sections/blocks work?" → Theme architecture workflow
- "GraphQL query issues" → GraphQL workflow
Prerequisites:
- For codebase questions: ensure you have access to the project's
src/directory - For React/performance optimization: this skill includes Vercel React best practices (57 rules) — see
references/vercel_react_best_practices.md
⚠️ ALWAYS Follow FDK Best Practices
CRITICAL: When providing code examples, suggestions, or implementations, you MUST enforce these best practices:
SSR Safety (Non-Negotiable)
✅ ALWAYS check isRunningOnClient() before using browser APIs
import { isRunningOnClient } from '../../helper/utils';
if (isRunningOnClient()) {
// Safe to use window, document, localStorage, etc.
}
❌ NEVER access window, document, localStorage directly in component body
❌ NEVER use hooks conditionally
Component Standards
✅ ALWAYS use FDKLink from fdk-core/components for internal navigation
✅ ALWAYS use FyImage for product/content images (automatic optimization)
✅ ALWAYS use core components (FyButton, FyInput, Modal) instead of custom implementations
✅ ALWAYS use transformImage() utility for image optimization
❌ NEVER use <a> tags for internal routes (breaks client-side navigation)
❌ NEVER implement custom buttons/inputs when core components exist
Data Fetching
✅ ALWAYS use useFPI() and useGlobalStore() for data access
✅ ALWAYS implement serverFetch for SEO-critical data
✅ ALWAYS handle loading and error states
import { useFPI, useGlobalStore } from 'fdk-core/utils';
const fpi = useFPI();
const data = useGlobalStore(fpi.getters.CUSTOM_VALUE);
❌ NEVER make direct API calls; use FPI methods ❌ NEVER skip error handling
Performance (FDK + Vercel React Best Practices)
✅ ALWAYS lazy load images with defer={true}
✅ ALWAYS use InfiniteLoader for long lists
✅ ALWAYS memoize expensive computations
✅ ALWAYS implement proper code splitting
✅ ALWAYS use Promise.all() for independent async operations (eliminate waterfalls)
✅ ALWAYS import directly from source files, avoid barrel file imports
✅ ALWAYS use dynamic imports for heavy components (code editors, charts, maps)
✅ ALWAYS defer non-critical third-party libs (analytics, logging) to load after hydration
✅ ALWAYS use functional setState for stable callbacks
✅ ALWAYS derive state during render, not in effects
✅ ALWAYS use useRef for transient/frequently-changing values (scroll pos, timers)
❌ NEVER create sequential await chains for independent operations
❌ NEVER pass entire objects across server/client boundaries when only a few fields are needed
❌ NEVER wrap simple primitive expressions in useMemo
Styling
✅ ALWAYS use CSS modules (co-located .less files)
✅ ALWAYS import styles as import * as styles from './component.less'
❌ NEVER use inline styles for static styling ❌ NEVER use global CSS selectors
Accessibility
✅ ALWAYS provide alt text for images
✅ ALWAYS use semantic HTML
✅ ALWAYS provide ariaLabel for icon buttons
When Suggesting Code
Before providing any code suggestion:
- ✅ Check if pattern exists in
references/common_patterns.md - ✅ Verify against
references/common_gotchas.md - ✅ Use actual utilities from
references/actual_utilities.md - ✅ Use core components from
references/core_components.md - ✅ Follow patterns from
references/code_examples.md
If user's code violates best practices:
- 🚨 Clearly explain the issue
- ✅ Provide corrected code following FDK conventions
- 📚 Reference the specific best practice document
Core Workflows
1. Codebase Navigation Workflow
Goal: Locate specific features, components, or functionality
Step 1: Identify the feature domain
- UI Components →
src/components/ - Page Routes →
src/pages/ - Feature Modules (Cart, PLP, Auth, Checkout) →
src/page-layouts/ - Utilities/Hooks →
src/helper/ - Constants/Mappings →
src/constants/ - Styling →
src/styles/
Step 2: Use targeted search patterns
# Product listing/filters/facets
rg -n "filter|facet|sort|range" src/page-layouts/plp/
# Data fetching/GraphQL
rg -n "productPrice|graphql|fpi|useFPI" src/
# Sections/blocks
rg -n "SectionRenderer|settings|blocks" src/
# Authentication/user flows
rg -n "login|auth|user|token" src/page-layouts/
# Cart/checkout
rg -n "cart|checkout|payment|address" src/page-layouts/
Step 3: Read component READMEs
- Check
src/components/README.mdfor component index - Check
src/pages/README.mdfor page index - Most components have co-located README files with usage examples
Reference: references/codebase_fdk_react_templates.md
2. Debugging Workflow
Goal: Troubleshoot issues in FDK theme code
Common Issue Patterns:
A. SSR/Hydration Errors
- Symptom: "window is not defined", hydration mismatch
- Check: Is
isRunningOnClient()used before accessing browser APIs? - Reference:
references/common_gotchas.md(SSR Safety section)
B. Data Not Loading
- Check 1: Is
useFPI()properly imported and called? - Check 2: Are GraphQL queries fetching all required fields?
- Check 3: Is data available in both SSR and client-side navigation?
- Reference:
references/debugging_guide.md(Data Fetching section)
C. Styling Issues
- Check 1: Are LESS files properly imported?
- Check 2: Is CSS module scope conflicting?
- Check 3: Are Tailwind utilities (if used) configured correctly?
- Reference:
references/tailwind_integration.md
D. Section/Block Not Rendering
- Check 1: Does the component export both
Componentandsettings? - Check 2: Is the settings schema valid?
- Check 3: Is the section registered in theme configuration?
- Reference:
references/themes_sections.md
E. Hook Issues
- Check 1: Are hooks called at the top level (not conditional)?
- Check 2: Review custom hook usage in
references/global_components_and_hooks.md - Common hooks:
useFPI(),useGlobalStore(),useGlobalTranslation(),useMobile(),useViewport()
Reference: references/debugging_guide.md
3. Code Review Workflow
Goal: Review and improve existing theme code
Review Checklist:
- SSR Safety - All browser API usage guarded
- GraphQL Efficiency - Single query with minimal fields
- Component Size - Functions under 150 lines, components focused
- Hooks Usage - Proper dependency arrays, no violations
- Performance - Memoization, code splitting, lazy loading
- Accessibility - Semantic HTML, ARIA, keyboard navigation
- Error Handling - Error boundaries, fallback UI
- Type Safety - PropTypes or TypeScript
- Analytics - No duplicate events, proper tracking
- Security - Input sanitization, no hardcoded secrets
References:
references/themes_best_practices_full.mdreferences/development_best_practices_checklist.mdreferences/testing_best_practices_checklist.mdreferences/performance_optimization_core_web_vitals.md
4. Implementation Workflow
Goal: Build new features following FDK patterns
Step 1: Choose the right location
- Reusable UI →
src/components/(with README) - Feature-specific UI →
src/page-layouts/[feature]/Components/ - Route page →
src/pages/ - Custom hook →
src/helper/hooks/ - Utility function →
src/helper/ - Constants →
src/constants/
Step 2: Follow FDK patterns
// Platform access
import { useFPI } from "fdk-core/utils";
const fpi = useFPI();
// Global state
import { useGlobalStore } from "fdk-core/utils";
const userData = useGlobalStore(fpi.getters.getUserData);
// Translations
import { useGlobalTranslation } from "fdk-core/utils";
const t = useGlobalTranslation("translation");
// SSR safety
import { isRunningOnClient } from "fdk-core/utils";
if (isRunningOnClient()) {
// Browser-only code
}
Step 3: Apply best practices
- Use functional components
- Implement proper error boundaries
- Add co-located LESS modules it is being used else use tailwind
- Use code splitting for large components
References:
references/common_patterns.mdreferences/code_examples.mdreferences/global_provider_resolvers.md
5. Theme Sections Workflow
Goal: Work with theme sections and blocks
Understanding the hierarchy:
- Theme → collection of pages
- Page → collection of sections
- Section → configured component with settings
- Block → repeatable item within a section
Section structure:
// Must export both Component and settings
export const Component = ({ props, blocks, globalConfig }) => {
// Render logic
};
export const settings = {
name: "section-name",
label: "Section Label",
props: [
// Input schema for section settings
],
blocks: [
// Block definitions
]
};
References:
references/themes_sections.mdreferences/key_concepts_pages_sections_blocks.mdreferences/sections_code_splitting.md
6. GraphQL Workflow
Goal: Work with Storefront GraphQL queries
Best practices:
- Fetch all needed data in a single query
- Request only required fields
- Use variables for dynamic values
- Handle loading and error states
- Cache appropriately
Common queries:
productPrice- Product pricing data- Application configuration
- User data
- Cart data
References:
references/graphql_product_price.mdreferences/graphql_application_client_libraries.md
7. React Performance Optimization Workflow
Goal: Write optimized React code following Vercel Engineering best practices
Reference: references/vercel_react_best_practices.md (57 rules, 8 categories)
Priority order (highest impact first):
- CRITICAL — Eliminate Waterfalls: Use
Promise.all()for independent ops, deferawaitto branches where needed, use Suspense boundaries for streaming - CRITICAL — Bundle Size: Avoid barrel imports, use dynamic imports for heavy components, defer third-party libs, preload on user intent
- HIGH — Server-Side: Minimize serialization at RSC boundaries, parallelize data fetching with component composition, use
React.cache()for dedup - MEDIUM-HIGH — Client Data: Use SWR for dedup, deduplicate event listeners, use passive scroll listeners
- MEDIUM — Re-renders: Extract memoized components, use functional setState, derive state during render, use
startTransitionfor non-urgent updates - MEDIUM — Rendering: Use
content-visibilityfor long lists, hoist static JSX, use ternary (not &&) for conditionals - LOW-MEDIUM — JS Perf: Use Set/Map for O(1) lookups, early returns, combine array iterations, cache property access in loops
- LOW — Advanced:
useEffectEventfor stable callbacks, initialize once per app load
When reviewing or writing FDK theme code, apply these in combination with FDK-specific patterns above.
8. Testing \u0026 Verification Workflow
Local testing:
- Run development server
- Test SSR (first load) and SPA (navigation)
- Test on mobile and desktop viewports
- Check browser console for errors
- Verify analytics events
References:
references/local_testing_checklist.mdreferences/testing_best_practices_checklist.md
Advanced Topics
Multilingual Support
- Reference:
references/themes_multilingual.md - Use
useGlobalTranslation()for all user-facing text - Support RTL layouts with
useLocaleDirection()
Custom Templates
- Reference:
references/custom_templates.md - Create custom page templates for specific use cases
Tailwind Integration
- Reference:
references/tailwind_integration.md - Configure Tailwind for FDK themes
- Use utility classes alongside LESS
Performance Optimization
- Reference:
references/performance_optimization_core_web_vitals.md - Optimize Core Web Vitals (LCP, FID, CLS)
- Image optimization with
transformImage - Code splitting and lazy loading
Authentication Patterns
- Reference:
references/auth_guard.md - Protect routes and components
- Handle guest vs. authenticated users
Data Management
- Reference:
references/data_management_fdk_store.md - FPI store patterns
- Custom values and configuration
FDK CLI Usage
- References:
references/fdk_overview_cli.mdreferences/fdk_cli_getting_started_versioning.md
- Initialize, develop, and deploy themes
Output Guidelines
When answering requests:
- Be specific: Provide exact file paths and line numbers where relevant
- Explain why: Don't just point to a location, explain the architectural reason
- Show patterns: Reference existing code patterns in the codebase
- Provide examples: Use code snippets from references or create minimal examples
- Ask when uncertain: If context is missing (route name, feature flag, etc.), ask for it
- Think incrementally: Suggest small, safe changes that align with existing patterns
Complete Reference Index
Core Concepts
references/intro_themes.md- Introduction to Fynd themesreferences/anatomy_of_theme.md- Theme structurereferences/key_concepts_pages_sections_blocks.md- Architecture fundamentalsreferences/themes_get_started.md- Getting started guide
Best Practices
references/themes_best_practices.md- Concise best practicesreferences/themes_best_practices_full.md- Comprehensive best practicesreferences/development_best_practices_checklist.md- Development checklistreferences/testing_best_practices_checklist.md- Testing checklistreferences/performance_optimization_core_web_vitals.md- Performance guide
React Performance (Vercel Engineering)
references/vercel_react_best_practices.md- 57 rules across 8 categories (waterfalls, bundle size, SSR, client fetching, re-renders, rendering, JS perf, advanced patterns)
Development
references/themes_development.md- Development workflowreferences/boilerplate_overview.md- Boilerplate structurereferences/theme_sync.md- Theme synchronizationreferences/local_testing_checklist.md- Local testing guide
Sections & Blocks
references/themes_sections.md- Section architecturereferences/sections_code_splitting.md- Code splitting for sections
Data & State
references/data_management_fdk_store.md- FPI store patternsreferences/global_provider_resolvers.md- Global providersreferences/server_fetch.md- Server-side data fetchingreferences/fpi_mutations.md- FPI mutation patterns
GraphQL
references/graphql_application_client_libraries.md- GraphQL overviewreferences/graphql_product_price.md- Product price query
Components & Hooks
references/global_components_and_hooks.md- Global utilitiesreferences/color_palette_mapping.md- Color systemreferences/auth_guard.md- Authentication patterns
Styling
references/tailwind_integration.md- Tailwind setup and usage
Internationalization
references/themes_multilingual.md- Multilingual support
Customization
references/custom_templates.md- Custom page templates
CLI & Tooling
references/fdk_overview_cli.md- FDK CLI overviewreferences/fdk_cli_getting_started_versioning.md- CLI getting started
Codebase
references/codebase_fdk_react_templates.md- Codebase structure and patternsreferences/actual_utilities.md- Complete utility functions reference from actual codebasereferences/fdk_core_components.md- FDKLink, serverFetch, and core FDK componentsreferences/core_components.md- All 11 core UI components (fy-image, fy-button, modal, etc.)
Troubleshooting (Enhanced)
references/debugging_guide.md- Debugging common issuesreferences/common_gotchas.md- Common pitfalls and solutionsreferences/common_patterns.md- Reusable code patternsreferences/code_examples.md- Practical code examples