Skip to content

Commit

Permalink
Fixed styles inserted by <Global/> component not inheriting `speedy…
Browse files Browse the repository at this point in the history
…` option (#1734)
  • Loading branch information
Andarist authored and emmatown committed Jan 22, 2020
1 parent d950d7d commit 7dea6d7
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/dry-frogs-perform.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@emotion/react': patch
---

Fixed styles inserted by `<Global/>` component not inheriting `speedy` option from a cache passed to a wrapping `<CacheProvider/>`.
17 changes: 16 additions & 1 deletion packages/react/__tests__/css.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// @flow
/** @jsx jsx */
import 'test-utils/next-env'
import { safeQuerySelector } from 'test-utils'
import * as React from 'react'
import { jsx, css, CacheProvider, ThemeProvider } from '@emotion/react'
import { jsx, css, Global, CacheProvider, ThemeProvider } from '@emotion/react'
import { render } from '@testing-library/react'
import renderer from 'react-test-renderer'
import createCache from '@emotion/cache'
Expand All @@ -14,6 +15,7 @@ console.warn = jest.fn()

afterEach(() => {
jest.clearAllMocks()
safeQuerySelector('body').innerHTML = ''
})

const SomeComponent = (props: { lol: true }) => (props.lol ? 'yes' : 'no')
Expand Down Expand Up @@ -173,6 +175,19 @@ test('can set speedy via custom cache', () => {
expect(cache.sheet.tags).toHaveLength(1)
})

test('speedy option from a custom cache is inherited for <Global/> styles', () => {
let cache = createCache({
container: safeQuerySelector('body'),
speedy: true
})
renderer.create(
<CacheProvider value={cache}>
<Global styles={{ html: { fontSize: 16 } }} />>
</CacheProvider>
)
expect(safeQuerySelector('body style').textContent).toEqual('')
})

test('autoLabel without babel', () => {
let SomeComp = props => {
return (
Expand Down
3 changes: 2 additions & 1 deletion packages/react/src/global.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ export let Global: React.AbstractComponent<
let sheet = new StyleSheet({
key: `${cache.key}-global`,
nonce: cache.sheet.nonce,
container: cache.sheet.container
container: cache.sheet.container,
speedy: cache.sheet.isSpeedy
})
// $FlowFixMe
let node: HTMLStyleElement | null = document.querySelector(
Expand Down

0 comments on commit 7dea6d7

Please sign in to comment.