Skip to content

perf: React Compiler compat, bundle size & architecture improvements#1465

Open
haddoumounir wants to merge 8 commits intovercel:mainfrom
haddoumounir:fix/react-optimizations
Open

perf: React Compiler compat, bundle size & architecture improvements#1465
haddoumounir wants to merge 8 commits intovercel:mainfrom
haddoumounir:fix/react-optimizations

Conversation

@haddoumounir
Copy link

Summary

  • Bundle size: Migrate all motionm components + wrap app in LazyMotion provider (~30kb savings), replace dangerouslySetInnerHTML script with next/script
  • Image optimization: Replace native <img> with next/image in image-editor, console, and model-selector
  • React Compiler compatibility: Fix refs-during-render patterns, replace effect-based state sync with derived state and conditional setState during render
  • State consolidation: Merge related useState calls into useReducer in ActiveChatProvider and PureArtifact
  • Architecture: Extract large components into focused sub-components and custom hooks:
    • PureArtifact (412 → 179 lines): ArtifactHeader, ArtifactContentArea, useArtifactDocuments
    • PureMultimodalInput (475 → 292 lines): useFileUpload, useSlashCommands
    • PromptInput (429 → 137 lines): usePromptInputFiles, useDropHandlers
  • Accessibility: Add prefers-reduced-motion CSS media query, use-reduced-motion hook, remove autoFocus
  • SEO: Add page metadata on chat routes

Switch from `motion` to `m` components across all files and wrap the
app in a LazyMotion provider with `domAnimation` features. This avoids
bundling the full framer-motion runtime (~30kb savings).

Also replaces dangerouslySetInnerHTML script with next/script for
safer loading.
Use Next.js Image component for automatic optimization, lazy loading,
and responsive sizing in image-editor, console, and model-selector.
- Derive hasReasoning inline instead of useState+useEffect latch
- Use conditional setState during render instead of ref patterns for
  detecting prop/state changes (shell, sheet-editor, use-messages)
- Add portalTarget state in text-editor to avoid reading ref during render

These patterns are compatible with React Compiler optimization.
Merge currentModelId, input, showCreditCardAlert, and
hasLoadedCookieModel into a single useReducer in ActiveChatProvider.
Make setInput and setShowCreditCardAlert stable callbacks with empty
dependency arrays since no callers use functional updates.
Break PureArtifact (412 lines) into focused pieces:
- ArtifactHeader: title, save status, version badge
- ArtifactContentArea: content renderer, toolbar, version footer
- useArtifactDocuments: document fetching, versioning, content saving

Also consolidates mode/document/versionIndex/isContentDirty into a
single useReducer and fixes try/finally patterns for compiler compat.
Extract useFileUpload and useSlashCommands hooks from
PureMultimodalInput (475 → 292 lines). Simplify toolbar by removing
redundant isHovered state and driving tooltip from selection state.
…Input

Break PromptInput (429 → 137 lines) by extracting file management
into usePromptInputFiles hook and drag-and-drop setup into
useDropHandlers hook. Add onKeyDown support to input-group.
- Add prefers-reduced-motion CSS media query to disable animations
- Add page metadata for SEO on chat routes
- Add use-reduced-motion hook for runtime motion preference detection
- Remove autoFocus from auth form input (a11y best practice)
@vercel
Copy link
Contributor

vercel bot commented Mar 22, 2026

@haddoumounir is attempting to deploy a commit to the Templates Test vtest314 Team on Vercel.

A member of the Team first needs to authorize it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant