-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
[RNMobile] memoize global styles in context to avoid unnecessary renders #28591
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Size Change: +259 B (0%) Total Size: 1.37 MB
ℹ️ View Unchanged
|
…/fix/performance/global-styles
lukewalczak
reviewed
Feb 2, 2021
}, [ | ||
defaultColors, | ||
globalStyle, | ||
JSON.stringify( wrapperProps.style ), |
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.
Could you please leave the comment there why you had to use JSON.stringify
(basically I mean something similar to the explanation which you posted in the PR description)?
lukewalczak
approved these changes
Feb 5, 2021
3 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
In this PR I added memorization of globalStyle value that is passed through context to nested blocks. Unfortunately, the redux store works In an odd way - the innerBlocks in the parent block is always a new reference when we change the attribute of nested block. Because of that if we change something in the block that is nested in Column/Group etc the whole "inner blocks" are re-rendered and it also forces to generate the new
globalStyle
. I added use memo to the globalStyle, however, i couldn't simply useattributes
andwrapperProps.styles
as a dependency because they are a new reference. I had to use JSON.stringify which works fine but I do not like the idea ;(This fixes the issue with a new reference of
globalStyle
that is passed to each block but I suggest also check why the redux store works like that and if it is necessary.How has this been tested?
To test if the app works exactly the same please follow these steps:
You can use this html for testing:
To test if the fix actually prevents unnecessary renders, follow these steps: (It can be done by comparison of performance charts from the performance tab in the debugger but can be also tested by adding console logs)
In the performance tab:
By console logs.
Screenshots
Types of changes
Bug-fix
Checklist: