Skip to content
Closed
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
ff3cb16
Change `Global` component to use the `StyleSheet` constructor of the …
Jack-Works Mar 10, 2022
7f8910a
Removed the direct dependency on from as it's no longer used that way
Andarist Mar 10, 2022
239f2d0
Version Packages (#2679)
github-actions[bot] Mar 10, 2022
2d3d7dd
Fixed `CacheProvider` demo in the docs (#2678)
pengx17 Mar 10, 2022
1a25293
Added `includeStyles` option to `createSerializer` to optionally disa…
thompsongl Apr 5, 2022
d935762
Fixed a false positive warning for `content` properties that included…
arturmuller Apr 5, 2022
8c1c7c7
Fixed a Prettier error
Andarist Apr 5, 2022
fc52bed
Update snapshots after renaming a test (#2711)
Andarist Apr 6, 2022
7a478fc
Version Packages (#2710)
github-actions[bot] Apr 6, 2022
3743483
Fixed an issue with `createEnzymeSerializer` not handling the recentl…
thompsongl Apr 7, 2022
6c9dbe5
Version Packages (#2716)
github-actions[bot] Apr 7, 2022
cd535bf
Update to new DocSearch index (#2718)
emmatown Apr 9, 2022
ae0f650
Fixed an issue in the minifying logic that could remove rules with th…
Andarist Apr 10, 2022
888377a
Version Packages (#2722)
github-actions[bot] Apr 10, 2022
409b237
Replace CodeSandbox link in bug report issue template (#2726)
srmagura Apr 16, 2022
6c652d9
Fix TS 4.7 error related to isPropValid
srmagura Apr 24, 2022
b575ef7
Merge branch 'main' of https://github.com/emotion-js/emotion into ts-…
srmagura Apr 24, 2022
69b3e06
Merge branch 'ts-april-23' into ts-merge
srmagura Apr 24, 2022
6bf9be3
Remove accidentally-committed .d.ts files
srmagura Apr 24, 2022
b9640a5
Fix unintentional breaking change to @emotion/memoize
srmagura Apr 24, 2022
f187b1d
Reorder function overloads in packages/memoize/src/index.ts
srmagura Apr 24, 2022
ba5f146
Make snapshots more readable (#2733)
SimenB Apr 25, 2022
7a3f608
Merge branch 'main' of https://github.com/emotion-js/emotion into ts-…
srmagura Apr 28, 2022
bf0a262
Merge pull request #2734 from emotion-js/preconstruct-upgrade
Andarist Apr 28, 2022
6c2d7a6
Allow any `Node` as container (#2728)
Peeja Apr 28, 2022
26e4e3e
Update "no component selectors" error message (#2727)
srmagura Apr 28, 2022
30f5cc4
Merge branch 'main' of https://github.com/emotion-js/emotion into ts-…
srmagura Apr 30, 2022
a485db3
styled: require prop to be a string
srmagura Apr 30, 2022
b45662d
Put in hacks to make .d.ts generation succeed for @emotion/eslint-plugin
srmagura Apr 30, 2022
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
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/--bug-report.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ assignees: ''
**To reproduce:**

<!--
Please edit this CodeSandbox (https://codesandbox.io/s/zljgy)
Please edit this CodeSandbox (https://codesandbox.io/s/emotion-issue-template-y306ue)
to help us reproduce your issue. Alternatively, create a GitHub repository.
Issues without a reproducible example will take longer to get addressed.
-->
Expand Down
2 changes: 2 additions & 0 deletions docs/cache-provider.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import { CacheProvider, jsx, css } from '@emotion/react'
import createCache from '@emotion/cache'
import { prefixer } from 'stylis'

const customPlugin = () => {}

const myCache = createCache({
key: 'my-prefix-key',
stylisPlugins: [
Expand Down
18 changes: 18 additions & 0 deletions packages/babel-plugin/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
# @emotion/babel-plugin

## 11.9.2

### Patch Changes

- [#2721](https://github.com/emotion-js/emotion/pull/2721) [`ae0f650b`](https://github.com/emotion-js/emotion/commit/ae0f650b5ad8ef658b61edca6157fe208be23b43) Thanks [@Andarist](https://github.com/Andarist)! - Fixed an issue in the minifying logic that could remove rules with the same context values as their parent rules. Like in the example below:

```js
styled.div`
> div {
color: blue;

> div {
color: hotpink;
}
}
`
```

## 11.7.2

### Patch Changes
Expand Down
36 changes: 36 additions & 0 deletions packages/babel-plugin/__tests__/__snapshots__/styled.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,42 @@ something.View(\\"color:hotpink;\\");
something.View(\\"\\");"
`;

exports[`emotion-babel-plugin styled same-nested-contex-value 1`] = `
"import styled from '@emotion/styled'

export const Comp = styled.div\`
> div {
color: blue;

> div {
color: hotpink;
}
}
\`


↓ ↓ ↓ ↓ ↓ ↓

import _styled from \\"@emotion/styled/base\\";

function _EMOTION_STRINGIFIED_CSS_ERROR__() { return \\"You have tried to stringify object returned from \`css\` function. It isn't supposed to be used directly (e.g. as value of the \`className\` prop), but rather handed to emotion so it can handle it (e.g. as value of \`css\` prop).\\"; }

export const Comp = _styled(\\"div\\", process.env.NODE_ENV === \\"production\\" ? {
target: \\"e1dl4grl0\\"
} : {
target: \\"e1dl4grl0\\",
label: \\"Comp\\"
})(process.env.NODE_ENV === \\"production\\" ? {
name: \\"11tack0\\",
styles: \\">div{color:blue;>div{color:hotpink;}}\\"
} : {
name: \\"11tack0\\",
styles: \\">div{color:blue;>div{color:hotpink;}}\\",
map: \\"/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNhbWUtbmVzdGVkLWNvbnRleC12YWx1ZS5qcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFFOEIiLCJmaWxlIjoic2FtZS1uZXN0ZWQtY29udGV4LXZhbHVlLmpzIiwic291cmNlc0NvbnRlbnQiOlsiaW1wb3J0IHN0eWxlZCBmcm9tICdAZW1vdGlvbi9zdHlsZWQnXG5cbmV4cG9ydCBjb25zdCBDb21wID0gc3R5bGVkLmRpdmBcbiAgPiBkaXYge1xuICAgIGNvbG9yOiBibHVlO1xuXG4gICAgPiBkaXYge1xuICAgICAgY29sb3I6IGhvdHBpbms7XG4gICAgfVxuICB9XG5gXG4iXX0= */\\",
toString: _EMOTION_STRINGIFIED_CSS_ERROR__
});"
`;

exports[`emotion-babel-plugin styled shorthand-property 1`] = `
"import styled from '@emotion/styled'

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import styled from '@emotion/styled/macro'

export const Comp = styled.div`
> div {
color: blue;

> div {
color: hotpink;
}
}
`
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,42 @@ something.View\`
something.View({});"
`;

exports[`@emotion/styled.macro same-nested-contex-value 1`] = `
"import styled from '@emotion/styled/macro'

export const Comp = styled.div\`
> div {
color: blue;

> div {
color: hotpink;
}
}
\`


↓ ↓ ↓ ↓ ↓ ↓

import _styled from \\"@emotion/styled/base\\";

function _EMOTION_STRINGIFIED_CSS_ERROR__() { return \\"You have tried to stringify object returned from \`css\` function. It isn't supposed to be used directly (e.g. as value of the \`className\` prop), but rather handed to emotion so it can handle it (e.g. as value of \`css\` prop).\\"; }

export const Comp = _styled(\\"div\\", process.env.NODE_ENV === \\"production\\" ? {
target: \\"e1dl4grl0\\"
} : {
target: \\"e1dl4grl0\\",
label: \\"Comp\\"
})(process.env.NODE_ENV === \\"production\\" ? {
name: \\"11tack0\\",
styles: \\">div{color:blue;>div{color:hotpink;}}\\"
} : {
name: \\"11tack0\\",
styles: \\">div{color:blue;>div{color:hotpink;}}\\",
map: \\"/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNhbWUtbmVzdGVkLWNvbnRleC12YWx1ZS5qcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFFOEIiLCJmaWxlIjoic2FtZS1uZXN0ZWQtY29udGV4LXZhbHVlLmpzIiwic291cmNlc0NvbnRlbnQiOlsiaW1wb3J0IHN0eWxlZCBmcm9tICdAZW1vdGlvbi9zdHlsZWQvbWFjcm8nXG5cbmV4cG9ydCBjb25zdCBDb21wID0gc3R5bGVkLmRpdmBcbiAgPiBkaXYge1xuICAgIGNvbG9yOiBibHVlO1xuXG4gICAgPiBkaXYge1xuICAgICAgY29sb3I6IGhvdHBpbms7XG4gICAgfVxuICB9XG5gXG4iXX0= */\\",
toString: _EMOTION_STRINGIFIED_CSS_ERROR__
});"
`;

exports[`@emotion/styled.macro shorthand-property 1`] = `
"import styled from '@emotion/styled/macro'

Expand Down
2 changes: 1 addition & 1 deletion packages/babel-plugin/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@emotion/babel-plugin",
"version": "11.7.2",
"version": "11.9.2",
"description": "A recommended babel preprocessing plugin for emotion, The Next Generation of CSS-in-JS.",
"main": "dist/emotion-babel-plugin.cjs.js",
"module": "dist/emotion-babel-plugin.esm.js",
Expand Down
6 changes: 5 additions & 1 deletion packages/babel-plugin/src/utils/minify.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { compile } from 'stylis'

const haveSameLocation = (element1, element2) => {
return element1.line === element2.line && element1.column === element2.column
}

const isAutoInsertedRule = element => {
if (element.type !== 'rule' || !element.parent) {
return false
Expand All @@ -10,7 +14,7 @@ const isAutoInsertedRule = element => {
parent = parent.parent
} while (parent && parent.type !== 'rule')

return !!parent && element.value === parent.value
return !!parent && haveSameLocation(element, parent)
}

const toInputTree = (elements, tree) => {
Expand Down
9 changes: 9 additions & 0 deletions packages/css/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# emotion

## 11.9.0

### Patch Changes

- [#2700](https://github.com/emotion-js/emotion/pull/2700) [`d9357621`](https://github.com/emotion-js/emotion/commit/d935762131b1474f2474296ee4706f7ecd59b6dd) Thanks [@arturmuller](https://github.com/arturmuller)! - Fixed a false positive warning for `content` properties that included `var()`.

- Updated dependencies [[`d9357621`](https://github.com/emotion-js/emotion/commit/d935762131b1474f2474296ee4706f7ecd59b6dd)]:
- @emotion/[email protected]

## 11.7.1

### Patch Changes
Expand Down
4 changes: 2 additions & 2 deletions packages/css/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@emotion/css",
"version": "11.7.1",
"version": "11.9.0",
"description": "The Next Generation of CSS-in-JS.",
"main": "dist/emotion-css.cjs.js",
"module": "dist/emotion-css.esm.js",
Expand All @@ -19,7 +19,7 @@
"dependencies": {
"@emotion/babel-plugin": "^11.7.1",
"@emotion/cache": "^11.7.1",
"@emotion/serialize": "^1.0.0",
"@emotion/serialize": "^1.0.3",
"@emotion/sheet": "^1.0.3",
"@emotion/utils": "^1.0.0"
},
Expand Down
1 change: 1 addition & 0 deletions packages/css/test/__snapshots__/warnings.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ exports[`does not warn when valid values are passed for the content property 1`]
content: inherit;
content: "some thing";
content: 'another thing';
content: var(--variable-name);
content: url("http://www.example.com/test.png");
content: linear-gradient(hotpink, #8be9fd);
content: radial-gradient(hotpink, #8be9fd);
Expand Down
1 change: 1 addition & 0 deletions packages/css/test/warnings.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const validValues = [
'inherit',
'"some thing"',
"'another thing'",
'var(--variable-name)',
'url("http://www.example.com/test.png")',
'linear-gradient(hotpink, #8be9fd)',
'radial-gradient(hotpink, #8be9fd)',
Expand Down
12 changes: 12 additions & 0 deletions packages/jest/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# @emotion/jest

## 11.9.1

### Patch Changes

- [#2715](https://github.com/emotion-js/emotion/pull/2715) [`37434836`](https://github.com/emotion-js/emotion/commit/3743483613b8fcb84bc25dde1fcd51a079b009b9) Thanks [@thompsongl](https://github.com/thompsongl)! - Fixed an issue with `createEnzymeSerializer` not handling the recently added `includeStyles` option.

## 11.9.0

### Minor Changes

- [#2709](https://github.com/emotion-js/emotion/pull/2709) [`1a25293f`](https://github.com/emotion-js/emotion/commit/1a25293fffa348d55bbf78e8855a6390bc54230b) Thanks [@thompsongl](https://github.com/thompsongl)! - Added `includeStyles` option to `createSerializer` to optionally disable styles printing.

## 11.8.0

### Patch Changes
Expand Down
11 changes: 11 additions & 0 deletions packages/jest/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,17 @@ import { createSerializer } from '@emotion/jest'
expect.addSnapshotSerializer(createSerializer({ DOMElements: false }))
```

### `includeStyles`

@emotion/jest's snapshot serializer inserts styles. If you would like to disable this behavior, you can do so by passing `{ includeStyles: false }`. For example:

```jsx
import { createSerializer } from '@emotion/jest'

// configures @emotion/jest to not insert styles
expect.addSnapshotSerializer(createSerializer({ includeStyles: false }))
```

# Custom matchers

## toHaveStyleRule
Expand Down
6 changes: 3 additions & 3 deletions packages/jest/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@emotion/jest",
"version": "11.8.0",
"version": "11.9.1",
"description": "Jest utilities for emotion",
"main": "dist/emotion-jest.cjs.js",
"module": "dist/emotion-jest.esm.js",
Expand Down Expand Up @@ -36,8 +36,8 @@
}
},
"devDependencies": {
"@emotion/css": "11.7.1",
"@emotion/react": "11.8.1",
"@emotion/css": "11.9.0",
"@emotion/react": "11.9.0",
"@types/jest": "^27.0.3",
"dtslint": "^4.2.1",
"enzyme-to-json": "^3.6.1",
Expand Down
8 changes: 5 additions & 3 deletions packages/jest/src/create-enzyme-serializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,13 @@ const wrappedEnzymeSerializer = {

export function createEnzymeSerializer({
classNameReplacer,
DOMElements = true
} /*: Options */ = {}) {
DOMElements = true,
includeStyles = true
} /* : Options */ = {}) {
const emotionSerializer = createEmotionSerializer({
classNameReplacer,
DOMElements
DOMElements,
includeStyles
})
return {
test(node) {
Expand Down
16 changes: 8 additions & 8 deletions packages/jest/src/create-serializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ function getPrettyStylesFromClassNames(
/*
export type Options = {
classNameReplacer?: (className: string, index: number) => string,
DOMElements?: boolean
DOMElements?: boolean,
includeStyles?: boolean
}
*/

Expand Down Expand Up @@ -185,8 +186,9 @@ function clean(node, classNames /*: string[] */) {

export function createSerializer({
classNameReplacer,
DOMElements = true
} /*: Options */ = {}) {
DOMElements = true,
includeStyles = true
} /* : Options */ = {}) {
const cache = new WeakSet()
const isTransformed = val => cache.has(val)

Expand All @@ -204,11 +206,9 @@ export function createSerializer({
const converted = deepTransform(val, convertEmotionElements)
const nodes = getNodes(converted)
const classNames = getClassNamesFromNodes(nodes)
const styles = getPrettyStylesFromClassNames(
classNames,
elements,
config.indent
)
const styles = includeStyles
? getPrettyStylesFromClassNames(classNames, elements, config.indent)
: ''
clean(converted, classNames)

nodes.forEach(cache.add, cache)
Expand Down
10 changes: 10 additions & 0 deletions packages/jest/test/__snapshots__/printer.test.js.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`allows to opt-out from styles printing 1`] = `
"<div
class=\\"emotion-0\\"
>
<svg
class=\\"emotion-1\\"
/>
</div>"
`;

exports[`does not replace class names that are not from emotion 1`] = `
".emotion-0 {
color: darkorchid;
Expand Down
25 changes: 25 additions & 0 deletions packages/jest/test/printer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,31 @@ describe('jest-emotion with DOM elements disabled', () => {
})
})

test('allows to opt-out from styles printing', () => {
const emotionPlugin = createSerializer({ includeStyles: false })

const divStyle = css`
color: red;
`

const svgStyle = css`
width: 100%;
`

const divRef = React.createRef()
render(
<div css={divStyle} ref={divRef}>
<svg css={svgStyle} />
</div>
)

const output = prettyFormat(divRef.current, {
plugins: [emotionPlugin, ReactElement, ReactTestComponent, DOMElement]
})

expect(output).toMatchSnapshot()
})

test('does not replace class names that are not from emotion', () => {
let tree = renderer
.create(
Expand Down
1 change: 1 addition & 0 deletions packages/jest/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const matchers: EmotionMatchers
export interface CreateSerializerOptions {
classNameReplacer?: (className: string, index: number) => string
DOMElements?: boolean
includeStyles?: boolean
}
export function createSerializer(
options?: CreateSerializerOptions
Expand Down
2 changes: 1 addition & 1 deletion packages/primitives-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"react": ">=16.8.0"
},
"devDependencies": {
"@emotion/react": "11.8.1",
"@emotion/react": "11.9.0",
"react": "16.14.0"
},
"homepage": "https://emotion.sh",
Expand Down
Loading