-
Notifications
You must be signed in to change notification settings - Fork 154
Conversation
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.
Hi @rfbotto!
Sorry it took me a couple days to get to this - I was at React Boston this weekend.
Overall it looks pretty good! I have a couple inline comments, mostly just small nitpicky things.
I have 1 big concern, though, about the performance with the new forwardRef
.
Here's the profiler, comparing selecting a different project:
(I also only tested in development mode. Maybe this is a non-issue in production... although I think dev mode performance is still important, so that Guppy is pleasant to work on and we can get a roughly-accurate sense of how our changes affect performance)
It looks like the issue is forwardRef
. For some reason it does a whole bunch of work.
I'm wondering if this might be fixed when we merge #265. That component already has some issues and I wonder if it's making this a lot worse. So I think I'd like to leave this PR open while we land that PR, and then we can check to see if that fixes it?
.storybook/config.js
Outdated
<> | ||
<GlobalStyles /> | ||
<Wrapper>{storyFn()}</Wrapper> | ||
</> |
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.
Nit: We've been using Fragment
instead of <>
in this project:
import React, { Fragment } from 'react';
<Fragment>
<GlobalStyles />
<Wrapper>{storyFn()}</Wrapper>
</Fragment>
It does exactly the same thing, but it's a bit more google-able, so for folks who haven't seen it before, it's not as mysterious/magical.
package.json
Outdated
@@ -132,7 +132,7 @@ | |||
"sass-loader": "7.0.0", | |||
"slug": "0.9.1", | |||
"style-loader": "0.19.1", | |||
"styled-components": "3.2.6", | |||
"styled-components": "^4.0.0-beta.9", |
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.
Nit: We tend to prefer exact versions, without the ^
.
You can specify this when installing by doing yarn add -DE dependency@version
. -D
for devDependencies, -E
- for exact version.
@@ -33,7 +34,7 @@ const Wrapper = styled.div` | |||
width: 100%; | |||
`; | |||
|
|||
injectGlobal` | |||
const SearchBoxGlobalStyle = createGlobalStyle` |
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 is so much nicer :D
this.node.focus(); | ||
if (this.node) { | ||
this.node.focus(); | ||
} |
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.
hah, nice. Digging that switching to ref
means that Flow now catches more issues
@@ -68,10 +68,12 @@ class WhimsicalInstaller extends PureComponent<Props, State> { | |||
|
|||
toggleRunning = () => { | |||
if (this.props.isRunning) { | |||
this.wrapperBoundingBox = this.wrapperNode.getBoundingClientRect(); | |||
if (this.wrapperNode) { |
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 we can roll this into the previous condition:
if (this.props.isRunning && this.wrapperNode) {
I like reducing nested conditionals, when possible.
src/global-styles.js
Outdated
@@ -1,10 +1,10 @@ | |||
import { injectGlobal } from 'styled-components'; | |||
import { createGlobalStyle } from 'styled-components'; |
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.
Hm, so with the new API, I think this should become a component, living in src/components/GlobalStyles/GlobalStyles.js
(with an index.js
that links to it, see existing components for examples).
Hey @joshwcomeau! I hope you had a great time at React Boston, looking forward to seeing your whimsy talk! :) I updated the PR with the changes you request. In the meantime, while #265 doesn't get merged, i will also try to investigate into the reason for the performance constraint with the usage of |
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 looks really good!! Thanks for making all my requested changes :D
I checked out this branch locally and rebased master. I fixed the conflicts, but because I did it with a rebase, I didn't want to push directly to your branch (since you'd need to hard-reset it).
I pushed my conflict-fix to improvement/213-upgrade-styled-components-to-v4-rebased
, if you wanna test things out there. You can also tackle the merge yourself (for the conflicts, just take what's in master, since I no longer need the ref
in CircularOutline
.
The performance is much better now, but still imperfect. Here's a side-by-side (The one on the left is your branch, the one on the right is the new master
):
I dug into this a little bit, but I'm confused why React is re-rendering so much. If you wanted to do some perf exploration, that'd be awesome, but I'm also happy to look at it myself as well :)
This PR is essentially approved, but I'd just love to get to the bottom of this before we merge it. All your changes are good, but it appears the new version of styled-components has exposed a pre-existing problem in our codebase, and we should fix that first 👍
<GlobalStyles /> | ||
<Wrapper>{storyFn()}</Wrapper> | ||
</Fragment> | ||
); |
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.
Good catch!
} | ||
`; | ||
|
||
export default GlobalStyles; |
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 great 👍
Oh! Something really interesting: I was assuming the problem was with So, there's clearly a Will continue looking later, but feel free to do some digging if it interests you :D |
I'm afraid |
Related Issue:
#213
Summary:
injectGlobal
by the newcreateGlobalStyle
innerRef
forref
React.forwardRef
in theTextInput
component in order to be able to forward theref
through the wrapper. This lead to a flow error as the flow types are not up to date with React > 16.3, hence the addition of the$FlowFixMe
annotation.ref
variables as maybe instance types (https://flow.org/en/docs/react/refs/) which in result led to some extra conditional checking before their usage..extend
forstyled()
Heading
component to use the newas
prop, instead ofwithComponent