Skip to content

perf(js): memoize sharedProps in EnrichedMarkdownText#496

Open
hryhoriiK97 wants to merge 2 commits into
mainfrom
perf/js-shared-props-memo
Open

perf(js): memoize sharedProps in EnrichedMarkdownText#496
hryhoriiK97 wants to merge 2 commits into
mainfrom
perf/js-shared-props-memo

Conversation

@hryhoriiK97

@hryhoriiK97 hryhoriiK97 commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Wraps the sharedProps object in useMemo with precise dependencies
  • Prevents native prop diffing on the bridge when a parent component re-renders without changing any markdown-related props
  • Extracts enableLinkPreviewResolved for a clean dependency array

Made with Cursor

The sharedProps object passed to the native component was recreated on
every render, forcing native prop diffing even when no values changed.
Wrap it in useMemo with precise dependencies so parent re-renders that
don't change any markdown-related props skip the native bridge entirely.

Co-authored-by: Cursor <cursoragent@cursor.com>

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 aims to reduce unnecessary React Native native-prop updates by stabilizing the prop references passed from EnrichedMarkdownText to the underlying native components.

Changes:

  • Introduces enableLinkPreviewResolved to simplify the sharedProps dependency list.
  • Wraps the sharedProps construction in useMemo with an explicit dependency array.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/react-native-enriched-markdown/src/native/EnrichedMarkdownText.tsx Outdated
Comment thread packages/react-native-enriched-markdown/src/native/EnrichedMarkdownText.tsx Outdated
rest comes from parameter destructuring and gets a new object identity
on every render, which invalidated the memo every time. Move rest out
of the memoized object and spread it at the JSX render site instead.

Co-authored-by: Cursor <cursoragent@cursor.com>

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

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

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.

2 participants