Skip to content

Commit b0a0436

Browse files
authored
Merge branch 'main' into jest-27
2 parents 3cc8cf3 + e5beae8 commit b0a0436

File tree

18 files changed

+233
-31
lines changed

18 files changed

+233
-31
lines changed

.changeset/famous-ghosts-roll.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@emotion/cache': patch
3+
'@emotion/css': patch
4+
'@emotion/react': patch
5+
---
6+
7+
Fixed an edge case issue with incorrect rules being generated. When a context selector (`&`) was used not at the beginning of a selector (which is not valid SCSS but is allowed by the Stylis parser that we are using) within a group of selectors containing a pseudoclass then it was not replaced correctly with the current context selector.

.changeset/itchy-waves-beg.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@emotion/cache': patch
3+
---
4+
5+
Improved the declared types related to Stylis. This should improve the compatibility with the types published in `@types/stylis`.

README.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -111,17 +111,6 @@ Look here 👉 _[emotion babel plugin feature table and documentation](https://g
111111
- [CommercialRealEstate.com.au](https://www.commercialrealestate.com.au)
112112
- [codecademy.com](https://www.codecademy.com)
113113

114-
## Contributors
115-
116-
This project exists thanks to all the people who contribute. [[Contribute](CONTRIBUTING.md)].
117-
<a href="https://github.com/emotion-js/emotion/graphs/contributors"><img src="https://opencollective.com/emotion/contributors.svg?width=890&button=false" /></a>
118-
119-
## Backers
120-
121-
Thank you to all our backers! 🙏 [[Become a backer](https://opencollective.com/emotion#backer)]
122-
123-
<a href="https://opencollective.com/emotion#backers" target="_blank"><img src="https://opencollective.com/emotion/backers.svg?width=890"></a>
124-
125114
## Sponsors
126115

127116
Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [[Become a sponsor](https://opencollective.com/emotion#sponsor)]
@@ -137,3 +126,14 @@ Support this project by becoming a sponsor. Your logo will show up here with a l
137126
<a href="https://opencollective.com/emotion/sponsor/7/website" target="_blank"><img src="https://opencollective.com/emotion/sponsor/7/avatar.svg"></a>
138127
<a href="https://opencollective.com/emotion/sponsor/8/website" target="_blank"><img src="https://opencollective.com/emotion/sponsor/8/avatar.svg"></a>
139128
<a href="https://opencollective.com/emotion/sponsor/9/website" target="_blank"><img src="https://opencollective.com/emotion/sponsor/9/avatar.svg"></a>
129+
130+
## Backers
131+
132+
Thank you to all our backers! 🙏 [[Become a backer](https://opencollective.com/emotion#backer)]
133+
134+
<a href="https://opencollective.com/emotion#backers" target="_blank"><img src="https://opencollective.com/emotion/backers.svg?width=890"></a>
135+
136+
## Contributors
137+
138+
This project exists thanks to all the people who contribute. [[Contribute](CONTRIBUTING.md)].
139+
<a href="https://github.com/emotion-js/emotion/graphs/contributors"><img src="https://opencollective.com/emotion/contributors.svg?width=890&button=false" /></a>

docs/extract-static.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ extractStatic is deprecated and will be removed in emotion@10. We recommend disa
1212

1313
### Why is extractStatic being deprecated?
1414

15-
Static extraction was made for earlier versions of emotion which had a very different architecture to the architecture emotion has today. As emotion has gotten more performant and features such as [composition](/docs/composition.md) have been added, static extraction has become less important. Because most of the community is leveraging the composition and `extractStatic` is rarely used, the time spent maintaining `extractStatic` is much higher than the benefits we get from it. Libraries such as [linaria](https://github.com/callstack-io/linaria) and [css-literal-loader](https://github.com/4Catalyzer/css-literal-loader) do static extraction well and the people working on them are focused on this specific problem. As a team, we believe that projects like [prepack](https://github.com/facebook/prepack), when they are ready, will provide a better and more powerful way to pre-compile styles.
15+
Static extraction was made for earlier versions of emotion which had a very different architecture to the architecture emotion has today. As emotion has gotten more performant and features such as [composition](/docs/composition.mdx) have been added, static extraction has become less important. Because most of the community is leveraging the composition and `extractStatic` is rarely used, the time spent maintaining `extractStatic` is much higher than the benefits we get from it. Libraries such as [linaria](https://github.com/callstack-io/linaria) and [css-literal-loader](https://github.com/4Catalyzer/css-literal-loader) do static extraction well and the people working on them are focused on this specific problem. As a team, we believe that projects like [prepack](https://github.com/facebook/prepack), when they are ready, will provide a better and more powerful way to pre-compile styles.
1616

17-
The `extractStatic` option to `babel-plugin-emotion` allows you to extract styles with no interpolations into external css files. **`extractStatic` is not recommended** because it **breaks [composition](/docs/composition.md)** and other powerful patterns from libraries like [facepaint](https://github.com/emotion-js/facepaint).
17+
The `extractStatic` option to `babel-plugin-emotion` allows you to extract styles with no interpolations into external css files. **`extractStatic` is not recommended** because it **breaks [composition](/docs/composition.mdx)** and other powerful patterns from libraries like [facepaint](https://github.com/emotion-js/facepaint).
1818

1919
**If you want to use dynamic values you must use css variables.**
2020

docs/ssr.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ hydrate(ids)
187187

188188
## Next.js
189189

190-
To use emotion's SSR with Next.js you need a custom `Document` component in `pages/_document.js` that renders the styles and inserts them into the `<head>`. [An example of Next.js with emotion can be found in the Next.js repo](https://github.com/zeit/next.js/tree/master/examples/with-emotion).
190+
To use emotion's SSR with Next.js you need a custom `Document` component in `pages/_document.js` that renders the styles and inserts them into the `<head>`. [An example of Next.js with emotion can be found in the Next.js repo](https://github.com/vercel/next.js/tree/master/examples/with-emotion-vanilla).
191191

192192
> Note:
193193
>

docs/typescript.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ const Component: FC<ComponentProps> = ({
176176
}) => <div className={className}>{label}</div>
177177

178178
const StyledComponent0 = styled(Component)`
179-
color: ${props => label === 'Important' ? 'red' : 'green'};
179+
color: ${props => props.label === 'Important' ? 'red' : 'green'};
180180
`
181181

182182
const StyledComponent1 = styled(Component)({

packages/babel-plugin/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"escape-string-regexp": "^4.0.0",
2525
"find-root": "^1.1.0",
2626
"source-map": "^0.5.7",
27-
"stylis": "^4.0.3"
27+
"stylis": "^4.0.10"
2828
},
2929
"peerDependencies": {
3030
"@babel/core": "^7.0.0"

packages/cache/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"@emotion/sheet": "^1.0.0",
2020
"@emotion/utils": "^1.0.0",
2121
"@emotion/weak-memoize": "^0.2.5",
22-
"stylis": "^4.0.3"
22+
"stylis": "^4.0.10"
2323
},
2424
"devDependencies": {
2525
"@emotion/hash": "*",

packages/cache/src/stylis-plugins.js

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,37 @@ import {
77
token,
88
char,
99
from,
10-
identifier,
1110
peek,
12-
position
11+
position,
12+
slice
1313
} from 'stylis'
1414

1515
const last = arr => (arr.length ? arr[arr.length - 1] : null)
1616

17+
// based on https://github.com/thysultan/stylis.js/blob/e6843c373ebcbbfade25ebcc23f540ed8508da0a/src/Tokenizer.js#L239-L244
18+
const identifierWithPointTracking = (begin, points, index) => {
19+
let previous = 0
20+
let character = 0
21+
22+
while (true) {
23+
previous = character
24+
character = peek()
25+
26+
// &\f
27+
if (previous === 38 && character === 12) {
28+
points[index] = 1
29+
}
30+
31+
if (token(character)) {
32+
break
33+
}
34+
35+
next()
36+
}
37+
38+
return slice(begin, position)
39+
}
40+
1741
const toRules = (parsed, points) => {
1842
// pretend we've started with a comma
1943
let index = -1
@@ -30,7 +54,11 @@ const toRules = (parsed, points) => {
3054
// it's very unlikely for this sequence to actually appear in a different context, so we just leverage this fact here
3155
points[index] = 1
3256
}
33-
parsed[index] += identifier(position - 1)
57+
parsed[index] += identifierWithPointTracking(
58+
position - 1,
59+
points,
60+
index
61+
)
3462
break
3563
case 2:
3664
parsed[index] += delimit(character)

packages/cache/types/index.d.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ export { EmotionCache }
77
export interface StylisElement {
88
type: string
99
value: string
10-
props: Array<string>
10+
props: Array<string> | string
1111
root: StylisElement | null
12-
children: Array<StylisElement>
12+
parent: StylisElement | null
13+
children: Array<StylisElement> | string
1314
line: number
1415
column: number
1516
length: number
@@ -20,14 +21,14 @@ export type StylisPluginCallback = (
2021
index: number,
2122
children: Array<StylisElement>,
2223
callback: StylisPluginCallback
23-
) => string | undefined
24+
) => string | void
2425

2526
export type StylisPlugin = (
2627
element: StylisElement,
2728
index: number,
2829
children: Array<StylisElement>,
2930
callback: StylisPluginCallback
30-
) => string | undefined
31+
) => string | void
3132

3233
export interface Options {
3334
nonce?: string

0 commit comments

Comments
 (0)