Skip to content

Conversation

@saseungmin
Copy link
Owner

@saseungmin saseungmin commented Aug 10, 2025

  • Remove key prop from View children when using FlatList/FlashList
  • Keep key prop only for ScrollView children
  • Improves FlashList performance by allowing proper item reuse
  • Follows FlashList official performance guidelines

Refs: https://shopify.github.io/flash-list/docs/fundamentals/performance#remove-key-prop

Summary by CodeRabbit

  • Bug Fixes
    • Improved performance when using FlashList or FlatList in the image viewer by removing unnecessary key props from list item children, following official guidelines.
  • Refactor
    • Optimized internal logic for determining scrollable components, enhancing rendering efficiency.

- Remove key prop from View children when using FlatList/FlashList
- Keep key prop only for ScrollView children
- Improves FlashList performance by allowing proper item reuse
- Follows FlashList official performance guidelines

Refs: https://shopify.github.io/flash-list/docs/fundamentals/performance#remove-key-prop
@changeset-bot
Copy link

changeset-bot bot commented Aug 10, 2025

🦋 Changeset detected

Latest commit: 163e85f

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai
Copy link

coderabbitai bot commented Aug 10, 2025

Walkthrough

This change updates the "react-native-gesture-image-viewer" package to conditionally assign the key prop to children of list items, applying it only when the parent component is scroll-view-like (e.g., ScrollView). The logic uses a memoized check for scroll-view types and aligns with FlashList performance recommendations.

Changes

Cohort / File(s) Change Summary
Patch Documentation
.changeset/tender-cows-flow.md
Documents the rationale for removing the key prop from children of list items except for ScrollView, referencing FlashList guidelines.
GestureViewer Logic Update
src/GestureViewer.tsx
Implements a memoized check for scroll-view-like components and conditionally assigns the key prop only for such components. Updates dependencies and rendering logic accordingly.

Sequence Diagram(s)

sequenceDiagram
    participant ParentComponent
    participant GestureViewer
    participant ListComponent (FlatList/FlashList/ScrollView)
    participant ChildItem

    ParentComponent->>GestureViewer: Render with list component
    GestureViewer->>GestureViewer: Memoize isScrollView based on Component
    GestureViewer->>ListComponent: Render items using renderItem
    alt isScrollView is true (e.g., ScrollView)
        ListComponent->>ChildItem: Render with key prop
    else isScrollView is false (e.g., FlatList/FlashList)
        ListComponent->>ChildItem: Render without key prop
    end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~7 minutes

Possibly related PRs

Suggested labels

size/M

Poem

A rabbit hopped through gesture code,
Adjusting keys along the road.
For ScrollView, keys remain in sight,
But FlashList runs much more light.
With memoized checks, performance grew—
A patch well-hopped, and tested too! 🐇✨

Note

🔌 MCP (Model Context Protocol) integration is now available in Early Access!

Pro users can now connect to remote MCP servers under the Integrations page to get reviews and chat conversations that understand additional development context.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/remove-key-prop-for-list-components

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@cloudflare-workers-and-pages
Copy link

Deploying react-native-gesture-image-viewer with  Cloudflare Pages  Cloudflare Pages

Latest commit: 163e85f
Status: ✅  Deploy successful!
Preview URL: https://32d5d220.react-native-gesture-image-viewer.pages.dev
Branch Preview URL: https://fix-remove-key-prop-for-list.react-native-gesture-image-viewer.pages.dev

View logs

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
.changeset/tender-cows-flow.md (1)

12-12: Fix markdownlint MD034 (bare URL).

Use a markdown link to avoid a bare URL and satisfy linting.

-Refs: https://shopify.github.io/flash-list/docs/fundamentals/performance#remove-key-prop
+Refs: [FlashList performance guidelines — Remove key prop](https://shopify.github.io/flash-list/docs/fundamentals/performance#remove-key-prop)
src/GestureViewer.tsx (1)

38-39: Minor: consider memoizing isScrollView (and note summary discrepancy).

AI summary mentions a “memoized boolean,” but here it’s a plain const. Functionally fine (cheap check), but to align with the summary and keep dependency identity stable:

-const isScrollView = isScrollViewLike(Component);
+const isScrollView = useMemo(() => isScrollViewLike(Component), [Component]);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4be9b35 and 163e85f.

📒 Files selected for processing (2)
  • .changeset/tender-cows-flow.md (1 hunks)
  • src/GestureViewer.tsx (4 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/GestureViewer.tsx (2)
src/utils.ts (1)
  • isScrollViewLike (5-7)
src/useGestureViewer.ts (1)
  • T (29-517)
🪛 markdownlint-cli2 (0.17.2)
.changeset/tender-cows-flow.md

12-12: Bare URL used

(MD034, no-bare-urls)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Cloudflare Pages
🔇 Additional comments (4)
.changeset/tender-cows-flow.md (1)

5-11: Changelog content reads well and matches intent.

Clear, actionable summary of the behavior change and rationale. LGTM.

src/GestureViewer.tsx (3)

76-76: Correct: only assign key for ScrollView children.

This prevents keys on list item wrappers in FlatList/FlashList, enabling proper cell reuse and improved FlashList performance.


91-91: Dependencies look right.

Including isScrollView ensures re-creation if ListComponent type changes. keyExtractor covers enableLoop changes, so no extra deps needed.


146-169: Clean conditional rendering with centralized isScrollView check.

Using the isScrollView flag simplifies the JSX and keeps key assignment logic consistent across branches. FlatList/FlashList path correctly relies on keyExtractor only.

@saseungmin saseungmin merged commit 6639939 into main Aug 10, 2025
6 checks passed
@saseungmin saseungmin deleted the fix/remove-key-prop-for-list-components branch August 10, 2025 07:00
saseungmin added a commit that referenced this pull request Aug 10, 2025
)

- Remove key prop from View children when using FlatList/FlashList
- Keep key prop only for ScrollView children
- Improves FlashList performance by allowing proper item reuse
- Follows FlashList official performance guidelines

Refs: https://shopify.github.io/flash-list/docs/fundamentals/performance#remove-key-prop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants