Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add test for EMOTION_RUNTIME_AUTO_LABEL
  • Loading branch information
srmagura committed Jul 9, 2022
commit c397de18a31c85426bfbbeb5fc5dd5ad07c66999
17 changes: 17 additions & 0 deletions packages/react/__tests__/element.no-babel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/** @jsx jsx */
import 'test-utils/dev-mode'
import { render, screen } from '@testing-library/react'
import { jsx } from '@emotion/react'

describe('EmotionElement', () => {
it('only does runtime auto labels if the global flag is set', () => {
const Comp = () => <div css={{ color: 'orchid' }} data-testid="comp" />

const { rerender } = render(<Comp />)
expect(screen.getByTestId('comp').className).toMatch(/^css-[^-]+$/)

globalThis.EMOTION_RUNTIME_AUTO_LABEL = true
rerender(<Comp />)
expect(screen.getByTestId('comp').className).toMatch(/^css-[^-]+-Comp$/)
})
})
3 changes: 3 additions & 0 deletions packages/react/src/emotion-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ export const createEmotionProps = (type: React.ElementType, props: Object) => {
// Runtime labeling is an opt-in feature because:
// - It causes hydration warnings when using Safari and SSR
// - It can degrade performance if there are a huge number of elements
//
// Even if the flag is set, we still don't compute the label if it has already
// been determined by the Babel plugin.
if (
process.env.NODE_ENV !== 'production' &&
globalThis.EMOTION_RUNTIME_AUTO_LABEL &&
Expand Down