question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Class name labels not added when using a re-exported version of the styled function

See original GitHub issue

Current behavior:

babel-plugin-emotion doesn’t add a class name label when using a re-exported version to the styled function.

To reproduce:

https://codesandbox.io/s/emotion-issue-template-r8v3h

  1. Import styled from @emotion/styled and re-export it.
  2. Import the re-exported styled in your app and use it to create a component
  3. Notice how the class name generated by babel-plugin-emotion does not include the variable name.
Description Screenshot
Using styled directly from @emotion/styled. Notice -Title is appended to the class name of the <h1>. image
Using a re-exported version of styled. Notice -Title is missing from the class name of the <h1>. image

Expected behavior:

babel-plugin-emotion should add the appropriate label to class names when using a re-exported version of the styled function. I’m currently using a re-exported version of styled in order to add the correct TypeScript types to the function, as instructed in the documentation.

Environment information:

  • react version: 16.12.0
  • @emotion/core version: 10.0.22
  • @emotion/styled version: 10.0.23
  • babel-plugin-emotion version: 10.0.23

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
Andaristcommented, Jan 11, 2020

Closing this because, as mentioned, this will be resolved in v11 - but with it, there will also be fewer use cases for re-exporting styled. So, in general, it should become less of a pain to work with. Stay tuned.

2reactions
Andaristcommented, Dec 22, 2019

This is a known issue and it has been fixed in v11 (available on npm under next tag). Unfortunately, it’s too complicated to backport this to v10 - but hopefully we should be able to ship v11 in a month (I encourage you to try it out today though, it’s stable and doesn’t include many breaking changes).

Additionally - with v11 you shouldn’t have to reexport styled just to add Theme type. Instead, you will be able to augment builtin interface

Read more comments on GitHub >

github_iconTop Results From Across the Web

Debug class names do not work when styled function ... - GitHub
When importing styled and using it in the same file, debug class names work as expected. // main.js import styled from "styled-components/macro" ...
Read more >
re export styled from styled components macro not working
I tried with export { css, createGlobalStyle, keyframes, ThemeProvider, withTheme, styled } . But without success. import React from 'react'; ...
Read more >
How To Use React Styled Components Efficiently - Copycat
Learn how to set up organized React styled components in your project through examples, comprehensive explanations, and tips and tricks!
Read more >
Benefits of using styled-components in React - LogRocket Blog
With styled -components, the UI design's focus shifts from merely styling HTML elements or React components through className to defining ...
Read more >
API Reference - styled-components
You can pass an arbitrary classname to a styled component without problem ... This is a method that creates a new StyledComponent with...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found