Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Frontend code review guidance from the Dify LLM application development platform repository.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/performance.md
1# Performance Rules23Review performance only where there is realistic impact. Do not request `memo`, `useMemo`, `useCallback`, virtualization, or caching as style preferences.45## Async Waterfalls67Flag:89- Awaiting remote feature flags or fetches before checking cheap synchronous conditions.10- Sequential awaits for independent operations.11- API routes or server components starting requests late when they could start early.12- Nested per-item fetches running serially when each item can fetch in parallel.13- Suspense boundaries that force the whole page to wait when a lower boundary could stream or isolate loading.1415Prefer `Promise.all` for independent work and branch-local awaits for conditionally needed data.1617## Bundle Size1819Flag:2021- Barrel imports from heavy libraries or `@langgenius/dify-ui`.22- Dynamic paths that prevent static trace analysis.23- Heavy components loaded eagerly when hidden behind a dialog, tab, command, or feature activation.24- Analytics, logging, editor, visualization, or third-party SDK code loaded before it is needed.25- Feature-local optional modules imported at top level only for rare flows.2627Use direct imports and `next/dynamic` where the user-visible path benefits.2829## Server Rendering3031Flag:3233- Request-specific mutable state stored at module scope in SSR/RSC paths.34- Large duplicate data serialized across RSC/client boundaries.35- Static I/O repeated per request when it could be hoisted safely.36- Cross-request cache without a bounded invalidation strategy.37- Server actions lacking API-route-equivalent auth checks.3839Use request-scoped deduplication such as `React.cache()` when repeated server reads in one request are the problem.4041## Re-rendering4243Flag:4445- Effects or subscriptions reading broad state when a derived boolean or narrower selector is enough.46- Components defined inside components.47- Derived rendering state stored in state/effects.48- Non-primitive default props recreated for memoized children.49- Expensive work recalculated on every render where it affects real interaction cost.50- High-frequency transient values stored in state when refs or CSS variables would avoid render loops.5152Do not flag simple primitive expressions wrapped or not wrapped in `useMemo`; prefer no memo for simple work.5354Require stable object/array/function identity only when:5556- The child is memoized and identity affects renders.57- The value is an effect/query dependency.58- A library API requires stable references.59- Profiling or local behavior shows avoidable re-rendering.6061## DOM, Lists, And Rendering6263Flag:6465- Layout reads in render (`getBoundingClientRect`, `offset*`, `scrollTop`).66- Interleaved DOM reads/writes that can cause layout thrashing.67- Large lists rendering without virtualization, pagination, or `content-visibility`.68- SVG/animation code animating expensive properties when transform/opacity would work.69- `transition-all`.70- Long-running non-critical browser work performed immediately instead of idle/deferred scheduling.7172## React Flow7374For workflow React Flow components, keep this Dify-specific rule:7576- UI consumption should use React Flow hooks such as `useNodes` / `useEdges`.77- Callback-only reads or mutations can use `useStoreApi`.78- Node components under `web/app/components/workflow/nodes/[nodeName]/node.tsx` must not depend on workflow stores that are absent in RAG Pipe template rendering.79