Fix custom themed nested components props overwrite #241
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
Note: This was a team effort with @ElviraBurchik!
The issue
When using nested components with different variant values and breakpoints, the child was receiving the parent's value.
For example with the following variant, if the child had
mediumPadding
and the parent hadnoPadding
, the child ended up with a padding of 'none' / 0 rather than 'm' / 8:Why this happened
This was happening because when memoizing properties that were objects, we were converting them to Strings resulting in a memoized hash key ending with
"[object Object]"
. So the flow for nested components with variants was as follows:"1334x750-spacing-padding-[object Object]"
"1334x750-spacing-padding-[object Object]"
The fix
By stringifying properties that are objects, we create unique hash keys for each case. For the example above, this would result in two separate hash keys for each variant:
"1334x750-spacing-padding-{"phone":"none","tablet":"none"}"
"1334x750-spacing-padding-{"phone":"m","tablet":"m"}"
As a result, we wouldn't accidentally use the parent's hash key / styles.
The comment I added in the code is quite messy, and may be inaccurate as I'm still trying to completely understand how this works. I will update the code comment once I have some reviews and the chance to better understand how this fixes the issue.
Fixes #239
Reviewers’ hat-rack 🎩
yarn test useRestyle
- tests should all passScreenshots or videos (if needed)
Checklist