-
Notifications
You must be signed in to change notification settings - Fork 673
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
add display names to components #817
add display names to components #817
Conversation
React devtools and Emotion will now render the correct component names
This is awesome! Any reason we can’t do it with the simpler syntax though? |
For that instance it is due to the emotion |
The function name approach is needed when using |
Rad, thanks! Would changing the Box component to not use the |
No it should be okay, if it's just a regular component, it will only need to pass a named function to |
Hey! Thanks for this PR related to my issue. I may not be approaching this the right way, but when I inspect the components in the Deploy preview all I see are |
Yeah that is odd, I'll have a look into it |
Ok after digging into it a bit, I think the best solution to ensure emotion renders the correct names is to add the label property to all components. I'll push a fix soon. |
Edit: See #823 I'm kinda second guessing using the emotion This should be able to be greatly simplified by writing components without reference to /** @jsx jsx */
import { jsx } from 'theme-ui'
import React from 'react'
export const Alert = React.forwardRef(function Alert(props, ref) {
return (
<div
ref={ref}
{...props}
sx={{
display: 'flex',
alignItems: 'center',
px: 3,
py: 2,
fontWeight: 'bold',
color: 'white',
bg: 'primary',
borderRadius: 4,
...(props.variant && { variant: `alerts.${props.variant}` }),
}}
/>
)
}) Some of these components use <Alert variant='secondary' mb={2}>Secondary</Alert> IMO, there is no need for this now that we have the |
I think I'll roll with the |
Alright so I think this is ready! Emotion will now render the component names, it's unfortunate but they'll all be named like
It would be even better if we could get CSS sourcemaps working too, the emotion babel plugin will require changes to support theme-ui. Something to look at in future :) |
}} | ||
/> | ||
)) | ||
export const Alert = React.forwardRef(function Alert(props, ref) { |
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.
For my understanding: is the named function
syntax still necessary with the Emotion label
property added below?
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, holy smokes! I don't think I realized the label
property would work more generally in the sx
prop – that's probably worth putting in a guide in the docs or mentioning somewhere 🤔
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.
For my understanding: is the named
function
syntax still necessary with the Emotionlabel
property added below?
Just for React devtools
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.
Does the displayName
static property no longer work for React devtools?
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.
It does but just not when you’re using forwardRef
https://reactjs.org/docs/forwarding-refs.html#displaying-a-custom-name-in-devtools
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.
Just thought I'd double check it, it does indeed work with forwardRef
! Strange, I am sure that it wasn't working at the time, anyway, I'd probably stick with this approach as it's what's recommended and is more concise.
Hi @dburles - this is a great PR. Can you please upgrade it to resolve conflicts and we also have some new components
Also whats the final status on displayName? I hope we can merge this soon, as @lachlanjc is working on a rewrite to remove emotion/styled and it seems there is some overlap here. |
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/systemui/theme-ui/20uog2mlc |
@atanasster Thanks. I've just fixed the merge conflicts. Named functions serve the same purpose as I think we should probably remove the
I'm not sure If we can make a decision on that I am happy to remove it and at least sort out the naming in devtools for now. Emotion |
Thanks @dburles thats great I would say remove label. You are correct this PR should be only about the devTools and we can decide about label in some other PR if its requested by users. Would you mind switching to static displayName, its a bit more standard and will be also easier for the rework that @lachlanjc is doing. |
I can't find why |
@dburles i think displaying the component name looks cleaner too, no? |
I mean like, technically you shouldn't be able to use |
I see you are correct it was recommended by bvaughn in that thread. You make the call, seems both work so we should be good. |
We could do this too, but it's not really as nice: const Component = ({}, ref) => ...;
Component.displayName = 'Button';
const Button = React.forwardRef(Component);
export default Button; |
I'll aim to have the label removed by early next week. |
Fantastic, really looking forward to have your PR merged. For displayName - any choice you make is fine by me, but until then (monday) if @hasparus @lachlanjc have any notes about it 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.
Great PR, @dburles! Thank you!
@atanasster let's merge this after the label
removal.
@dburles - would you mind updating Paragraph and Switch, just so we dont forget to bring them up to date as well. |
@atanasster Whoops, nice spot. Just updated those, should be good to go then. |
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.
Thanks a bunch, great PR
You wrote it like I'm some sort of authority. This PR is open since March, and IMHO it's a bugfix, as I'd expect proper names in React DevTools. |
Sorry it took so long to merge it, @dburles 🙏 |
React devtools and Emotion will now render the correct component names, for #811