Skip to content

fix: eliminate home screen lag via memoization and FlashList migration - #16

Draft
prince-d-simform with Copilot wants to merge 3 commits into
mainfrom
copilot/fix-home-screen-lagging
Draft

fix: eliminate home screen lag via memoization and FlashList migration#16
prince-d-simform with Copilot wants to merge 3 commits into
mainfrom
copilot/fix-home-screen-lagging

Conversation

Copilot AI commented Apr 2, 2026

Copy link
Copy Markdown

The home screen was lagging due to unnecessary re-renders driven by unstable prop references and React Native's default FlatList rendering overhead.

Root causes & fixes

  • contentContainerStyle new array reference every render — stabilized with useMemo so FlashList receives a stable reference.
  • productFeedback calling 4 render functions unconditionally — now wrapped in useMemo, only re-evaluated when the underlying useCallback references change.
  • Replaced FlatList with FlashList — migrated the product grid to @shopify/flash-list for significantly better scroll performance via its internal recycling architecture.
// Before
import { FlatList } from 'react-native';
<FlatList<Product>
  removeClippedSubviews
  columnWrapperStyle={flatListColumnWrapperStyle}
  contentContainerStyle={flatListContentContainerStyle}
  initialNumToRender={6}
  maxToRenderPerBatch={4}
  windowSize={5}
  ...
/>

// After
import { FlashList } from '@shopify/flash-list';
<FlashList<Product>
  contentContainerStyle={flashListContentContainerStyle}
  estimatedItemSize={scale(300)}
  numColumns={2}
  ...
/>

FlashList migration

Aspect FlatList FlashList
Rendering Window-based Recycling (no blank cells)
estimatedItemSize N/A scale(300) — device-adaptive ProductCard height estimate
columnWrapperStyle Required for column spacing Not needed (handled internally)
removeClippedSubviews, windowSize, maxToRenderPerBatch, initialNumToRender Manual tuning required Handled internally by FlashList

estimatedItemSize uses the project's scale() utility so the estimate adapts to the current device's screen dimensions.

Copilot AI linked an issue Apr 2, 2026 that may be closed by this pull request
Copilot AI changed the title [WIP] Fix lagging issue on home screen fix: eliminate home screen lag via memoization and FlatList tuning Apr 2, 2026
Copilot AI requested a review from prince-d-simform April 2, 2026 07:56
@prince-d-simform
prince-d-simform requested a review from Copilot April 3, 2026 09:14

@prince-d-simform prince-d-simform left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot can you please use the Flashlist instead of flatlist

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR targets Home screen performance by reducing unnecessary re-renders and layout work in the product grid, primarily by stabilizing prop references passed to FlatList and tuning initial/batch rendering behavior.

Changes:

  • Memoizes productFeedback evaluation so the feedback element is only recomputed when the underlying render callbacks change.
  • Stabilizes FlatList contentContainerStyle and columnWrapperStyle references via useMemo to avoid triggering redundant work each render.
  • Tunes FlatList rendering with initialNumToRender={6} and maxToRenderPerBatch={4} to reduce initial and scroll-time JS thread pressure.

Agent-Logs-Url: https://github.com/prince-d-simform/AI-spec/sessions/cf2a3ba1-5ef2-4263-8d9e-c74de5fd6985

Co-authored-by: prince-d-simform <104822674+prince-d-simform@users.noreply.github.com>

Copilot AI commented Apr 3, 2026

Copy link
Copy Markdown
Author

@copilot can you please use the Flashlist instead of flatlist

Done in f543424. Replaced FlatList with FlashList from @shopify/flash-list (v2.3.1).

Key changes:

  • Added @shopify/flash-list to package.json
  • Swapped FlatListFlashList with estimatedItemSize={scale(300)} (required by FlashList, adapted to device size via the project's scale() utility)
  • Removed FlatList-only props that FlashList doesn't need: columnWrapperStyle, removeClippedSubviews, windowSize, maxToRenderPerBatch, initialNumToRender — FlashList handles these optimizations internally
  • Removed the now-unused columnWrapper style from HomeStyles.ts

Copilot AI changed the title fix: eliminate home screen lag via memoization and FlatList tuning fix: eliminate home screen lag via memoization and FlashList migration Apr 3, 2026
Copilot AI requested a review from prince-d-simform April 3, 2026 09:22
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.

home screen is lagging

3 participants