-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
flex: cleanup Flex* custom styling in favor of Flex primitive #93809
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
base: master
Are you sure you want to change the base?
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.
Generally in favor of this!
Not a blocker, but still not sure where I land on the styled(Flex)
pattern. Intuitively feels like we shouldn't need to create an override to define padding / overflow behavior?
@@ -163,12 +164,12 @@ export function CodeSnippet({ | |||
</Tab> | |||
))} | |||
</TabsWrapper> | |||
<FlexSpacer /> | |||
<Flex.Item grow={1} /> |
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.
Wonder if we should have <Flex.Spacer />
as a shorthand here? Seems easier to remember than this.
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.
Yeah, that could also work. I don't have a strong opinion on it tbh, it seems like an edge case we can iron out later
static/app/utils/discover/styles.tsx
Outdated
@@ -52,9 +52,6 @@ export const BarContainer = styled('div')` | |||
`; | |||
|
|||
export const FlexContainer = styled('div')` | |||
display: flex; | |||
align-items: center; | |||
justify-content: flex-end; | |||
width: 100%; | |||
`; |
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.
Missing a replacement here?
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.
Ah no, I actually want to revert this one, and possibly just rename the component given that it's exported
@@ -42,12 +43,8 @@ const Container = styled('div')` | |||
min-width: 0; /* flex-hack for overflow-ellipsised children */ | |||
`; | |||
|
|||
const FlexWrapper = styled('div')` | |||
const FlexWrapper = styled(Flex)` |
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.
personally think this is worse
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.
also it changes how it displays since overflowEllipsis is overriding display flex
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 don't disagree, but I think it suffers from the same problem as inline styles (which are somewhat growing in popularity across the codebase).
I will try and modify these styled usages to use TextOverflow (at least in this case, it should help)
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've reverted the change locally, to make sure I don't break anything, and I'm either not testing this correctly, or it doesn't even work in it's current state.
CleanShot.2025-06-18.at.14.02.09.mp4
@@ -99,10 +100,8 @@ const ProjectBadge = styled(IdBadge)` | |||
flex-shrink: 0; | |||
`; | |||
|
|||
const FlexCenter = styled('div')` | |||
const FlexCenter = styled(Flex)` |
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 doesn't work
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.
Same as the comment above, I will change it to use TextOverflow
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.
display: flex; | ||
const FulllHeightFlex = styled(Flex)` | ||
flex-grow: 1; |
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 this is also worse
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 it can actually be avoided by moving the container to the parent component, I will try to do that.
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.
avoid styled(Flex) at all costs
display: flex; | ||
const FullWidthFlex = styled(Flex)` | ||
width: 100%; |
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.
probably actually a flex-grow 1
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.
We don't even need it, just flex with align right looks identical
@@ -244,7 +244,7 @@ function InformationCard({ | |||
return ( | |||
<Fragment> | |||
<Flex align="center"> | |||
<FlexContainer> | |||
<Flex.Item grow={1}> |
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.
What is a flex item?
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.
currently, just a convenient way of setting the flex property on the child.
We can't unfortunately do that. The fact that we are using styled components won't give us the isolation we need. |
i can lint against it. It is too hard to understand what the styles are. Even in this pr we're overriding display: flex in the wrong way |
I agree. I think that calls for a better set of primitives or a more complete API - this change mostly surfaces that problem. |
Linters can be disabled, and I wouldn't count on them as the ultimate solution. Ultimately, what we want it to give people the least amount of reason to even use styles for anything. We are pretty far from that, but this is a start. You are right about pointing out the problem about overriding display, I missed that, however the root cause is still in the fact that we are restyling things and that overflow ellipsis ends up overriding display, which is imo not what it should be doing. I would bet you that there are actually cases in the codebase where that bug already exists today. |
@scttcper it really didn't take that long to find one either, and I'm pretty sure we have more sentry/static/app/components/deprecatedSmartSearchBar/searchDropdown.tsx Lines 584 to 595 in 480e641
|
the problem i have is that styles now come from 3 places Flex has styles, the props are declaring styles |
still in favor of adopting a subset of tailwind display styles. Would reduce runtime overhead at least |
I agree, and I want us to move away from both inline styled and styled components. I will see if I can actually move entirely away of the styled flex in this PR, I think it should be doable. For the question of "just wanting div with flex", there is usually more behind that, like you most probably want something else with that display flex too, maybe direction='column', or something, which is where other higher level primitives can come in, things like Stack or List, those have better semantic meaning, but also allow you to tweak the subset like gap, as opposed to having to set display=column on everything. We don't provide those, but we probably should. |
I'll never use stack or list because I have styled('div') and won't remember they exist. just like nobody knows Flex.Item exists |
If we never add documentation or guidelines for any of this, then neither will anyone else for that matter, but that's actually something we want to change. The assumption is that if the primitives are good, people won't need to use styled. Now, I don't know if we will actually get there in practice, I think it's going to be hard, however we should at least be able to get to a point where styled is used much less frequently than it is today. |
Just remove a couple custom Flex* classes in favor of the Flex primitive