Skip to content

Styled Components: Fix interpolated className #277

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

Merged

Conversation

ItsJonQ
Copy link
Owner

@ItsJonQ ItsJonQ commented Mar 1, 2021

This update consolidates how the interpolated className is created, in an attempt to resolve WordPress/gutenberg#29084 (comment)

Changes:

  • A new getInterpolatedClassName util is created and exported from @wp-g2/create-styles
  • getInterpolatedClassName ensures the @emotion/hash function is only called if the argument is valid
  • @wp-g2/context adds @wp-g2/create-styles as a dependency (was previously missing)
  • All calls to @emotion/hash go through the new getInterpolatedClassName util

@vercel
Copy link

vercel bot commented Mar 1, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/itsjonq/g2/9w5rDTVhEGpVEQkdyCXnxCYP5UQa
✅ Preview: https://g2-git-try-context-fix-interpolated-classnam-f978f7.vercel.app

@ItsJonQ
Copy link
Owner Author

ItsJonQ commented Mar 1, 2021

Going to try an alpha 0.0.160 release to test in Gutenberg

* @returns {string} The interpolated className.
*/
export function getInterpolatedClassName(displayName) {
return typeof displayName === 'string' ? `ic-${hash(displayName)}` : '';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we raise a development-env warning that the displayName was undefined?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea. But maybe not here. Perhaps in contextConnect() or useContext()?

What you think :)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, that makes sense to me!

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just pushed that update :). Lemme know if that works

@ItsJonQ ItsJonQ merged commit 02388cc into main Mar 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants