-
Notifications
You must be signed in to change notification settings - Fork 208
Reset roolEl when calling withComponent #377
Conversation
ebf936a
to
c1bf2ce
Compare
Codecov Report
@@ Coverage Diff @@
## master #377 +/- ##
=====================================
Coverage 100% 100%
=====================================
Files 10 10
Lines 182 182
Branches 52 52
=====================================
Hits 182 182
Continue to review full report at Codecov.
|
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.
Looks good! Just one more case to satisfy :) Thanks so much!
src/create-glamorous.js
Outdated
@@ -114,6 +114,7 @@ function createGlamorous(splitProps) { | |||
{ | |||
...componentProperties, | |||
comp: newComp, | |||
rootEl: newComp, |
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.
This should probably be rootEl: getRootEl(newComp)
just in case someone passes withComponent(SomeGlamorousComponent)
👍
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.
done
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.
hmm... getRootEl
might do more harm than help there. Could you try if this example works for your code? (bigger font size should be applied) https://codesandbox.io/s/pkr1rn24vx
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.
Hmm... I'm not sure I understand. I think your codesandbox simply reveals the bug that would be fixed by these changes.
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.
@kentcdodds I didn't have time to explain this properly yesterday, so here it goes:
Normally, when you pass a glamorous component to a glamourous()
, it 'merges' all the glamorous props so that there is only one instance of a glamorous component. withComponent
works differently - when you pass a glamorous component to it there will be two instances - one glamorous instance rendering the other.
rootEl
purpose is to decide what props should be filtered out (props that are invalid for a given rootEl
won't be passed to the rendered component). When you assign rootEl
to a wrapped non-glamorous component (mosty html element) all custom props will be filtered out.
This causes problems when this inner glamorous component (the one given to withComponent
) relies on custom props for dynamic styles (it won't be able to access the custom props).
In summary: when passing glamorous component to withComponent
, the component that will be directly rendered is the glamorous component itself so it should be assigned to rootEl
.
tldr;
this works in 4.11.2 https://codesandbox.io/s/pkr1rn24vx
but doesn't in the latest (4.11.4) https://codesandbox.io/s/n0yrxyrnl
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.
I think I understand. Could you perhaps open a pull request which adds a test for your scenario and see if we can satisfy both cases? If not then we can have a discussion about which to favor...
@kentcdodds one other thing... I can fix it by removing |
Thanks for catching that. Let's go ahead and merge this and you can fix that test in another PR if you like. I like to try to avoid snapshots if I can, preferring a more explicit assertion. So if you're able to come up with something more explicit it would be appreciated. Thanks! |
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.
Wonderful! Thank you for fixing this!
Thanks so much for your help @tikotzky! I've added you as a collaborator on the project. Please make sure that you review the |
What:
A fix and failing test for #376
Why:
Added as per #376 (comment)
How:
When calling
withComponent
therootEl
is now set to the component being passed in.You can still manually set the
rootEl
by passing inoptions
in the second param.Checklist: