-
Notifications
You must be signed in to change notification settings - Fork 185
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(AppRoot): Use memo for AppRootContext value #7667
fix(AppRoot): Use memo for AppRootContext value #7667
Conversation
Otherwize even with memo any components based on Tappable/Clickable will rerender on parent rerender.
size-limit report 📦
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. |
e2e tests |
👀 Docs deployed
Commit 06fdff3 |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #7667 +/- ##
==========================================
+ Coverage 95.13% 95.16% +0.03%
==========================================
Files 383 383
Lines 11347 11335 -12
Branches 3726 3714 -12
==========================================
- Hits 10795 10787 -8
+ Misses 552 548 -4
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Выяснилось, что если AppRoot по какой-то причине ререндерится, то это вызывает ререндер компонентов, основанных на Tappable/Clickable компонентах, даже если они обернуты в React.memo. Виной тому пересоздающийся объект контекста. Когда может ререндерится AppRoot? Например, когда он обернут в компонент, который слушает изменения стора, бывает нужно для того, чтобы менять тему самого AppRoot. Тогда получается, что каждое обновление стора вызывает ререндер AppRoot и компонентов VKUI.
Выяснилось, что если AppRoot по какой-то причине ререндерится, то это вызывает ререндер компонентов, основанных на Tappable/Clickable компонентах, даже если они обернуты в React.memo. Виной тому пересоздающийся объект контекста. Когда может ререндерится AppRoot? Например, когда он обернут в компонент, который слушает изменения стора, бывает нужно для того, чтобы менять тему самого AppRoot. Тогда получается, что каждое обновление стора вызывает ререндер AppRoot и компонентов VKUI.
✅ v6.7.2 🎉 |
Описание
Выяснилось, что если
AppRoot
по какой-то причине ререндерится, то это вызывает ререндер компонентов, основанных наTappable
/Clickable
компонентах, даже если они обернуты вReact.memo
.Виной тому пересоздающийся объект контекста.
Когда может ререндерится
AppRoot
?Например, когда он обернут в компонент, который слушает изменения стора, бывает нужно для того, чтобы менять тему самого
AppRoot
. Тогда получается, что каждое обновление стора вызывает ререндерAppRoot
и компонентовVKUI
.Пример с вспроизведением: https://7zmxhp.csb.app/
Нужно посмотреть что происходит в react profiler при каждом ререндере AppRoot.
Код:
Изменения
Используем
React.useMemo
для объекта, который мы передаем как значение контекстаAppRootContext
.Release notes
Исправления
AppRootContext
, чтобы компоненты, зависящие от него, лишний раз не ререндерелись при ререндереAppRoot
.