Skip to content

Commit 3a8b81d

Browse files
Merge branch 'main' into main
2 parents fd87787 + 149194e commit 3a8b81d

File tree

5 files changed

+74
-4
lines changed

5 files changed

+74
-4
lines changed

packages/cache/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# @emotion/cache
22

3+
## 11.10.7
4+
5+
### Patch Changes
6+
7+
- [#3019](https://github.com/emotion-js/emotion/pull/3019) [`b02be0ba`](https://github.com/emotion-js/emotion/commit/b02be0bae0048df4b3a8567436bc31059b00d213) Thanks [@Andarist](https://github.com/Andarist)! - Fixed `/* emotion-disable-server-rendering-unsafe-selector-warning-please-do-not-use-this-the-warning-exists-for-a-reason */` not disabling the warning for rules defined inside other rules.
8+
39
## 11.10.5
410

511
### Patch Changes

packages/cache/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@emotion/cache",
3-
"version": "11.10.5",
3+
"version": "11.10.7",
44
"description": "emotion's cache",
55
"main": "dist/emotion-cache.cjs.js",
66
"module": "dist/emotion-cache.esm.js",

packages/cache/src/stylis-plugins.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,8 @@ export let createUnsafeSelectorsAlarm = cache => (element, index, children) => {
165165
)
166166

167167
if (unsafePseudoClasses) {
168-
const isNested = element.parent === children[0]
169-
// in nested rules comments become children of the "auto-inserted" rule
168+
const isNested = !!element.parent
169+
// in nested rules comments become children of the "auto-inserted" rule and that's always the `element.parent`
170170
//
171171
// considering this input:
172172
// .a {
@@ -182,7 +182,7 @@ export let createUnsafeSelectorsAlarm = cache => (element, index, children) => {
182182
// .b {}
183183
// }
184184
const commentContainer = isNested
185-
? children[0].children
185+
? element.parent.children
186186
: // global rule at the root level
187187
children
188188

packages/react/__tests__/__snapshots__/warnings.js.snap

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,16 @@ exports[`global with css prop 1`] = `null`;
3535

3636
exports[`unsafe pseudo classes does not warn when using with flag: /* emotion-disable-server-rendering-unsafe-selector-warning-please-do-not-use-this-the-warning-exists-for-a-reason */ does not warn when using the flag on a global rule 1`] = `null`;
3737

38+
exports[`unsafe pseudo classes does not warn when using with flag: /* emotion-disable-server-rendering-unsafe-selector-warning-please-do-not-use-this-the-warning-exists-for-a-reason */ does not warn when using the flag on a rule that is defined in another one 1`] = `
39+
.emotion-0 div span:first-child {
40+
border-bottom-left-radius: 0;
41+
}
42+
43+
<div
44+
className="emotion-0"
45+
/>
46+
`;
47+
3848
exports[`unsafe pseudo classes does not warn when using with flag: /* emotion-disable-server-rendering-unsafe-selector-warning-please-do-not-use-this-the-warning-exists-for-a-reason */ does not warn when using the flag on the rule that follows a declaration 1`] = `
3949
.emotion-0 {
4050
color: hotpink;
@@ -93,6 +103,16 @@ exports[`unsafe pseudo classes does not warn when using with flag: /* emotion-di
93103

94104
exports[`unsafe pseudo classes does not warn when using with flag: /* emotion-disable-server-rendering-unsafe-selector-warning-please-do-not-use-this-the-warning-exists-for-a-reason */ does warn when not using the flag on a global rule 1`] = `null`;
95105

106+
exports[`unsafe pseudo classes does not warn when using with flag: /* emotion-disable-server-rendering-unsafe-selector-warning-please-do-not-use-this-the-warning-exists-for-a-reason */ does warn when not using the flag on a rule that is defined in another one 1`] = `
107+
.emotion-0 div span:first-child {
108+
border-bottom-left-radius: 0;
109+
}
110+
111+
<div
112+
className="emotion-0"
113+
/>
114+
`;
115+
96116
exports[`unsafe pseudo classes does not warn when using with flag: /* emotion-disable-server-rendering-unsafe-selector-warning-please-do-not-use-this-the-warning-exists-for-a-reason */ does warn when not using the flag on the rule that follows a declaration 1`] = `
97117
.emotion-0 {
98118
color: hotpink;

packages/react/__tests__/warnings.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,50 @@ describe('unsafe pseudo classes', () => {
343343
).toMatchSnapshot()
344344
expect(console.error).not.toBeCalled()
345345
})
346+
347+
test('does warn when not using the flag on a rule that is defined in another one', () => {
348+
expect(
349+
renderer
350+
.create(
351+
<div
352+
css={css`
353+
div {
354+
span:first-child {
355+
border-bottom-left-radius: 0;
356+
}
357+
}
358+
`}
359+
/>
360+
)
361+
.toJSON()
362+
).toMatchSnapshot()
363+
expect((console.error: any).mock.calls).toMatchInlineSnapshot(`
364+
[
365+
[
366+
"The pseudo class ":first-child" is potentially unsafe when doing server-side rendering. Try changing it to ":first-of-type".",
367+
],
368+
]
369+
`)
370+
})
371+
372+
test('does not warn when using the flag on a rule that is defined in another one', () => {
373+
expect(
374+
renderer
375+
.create(
376+
<div
377+
css={css`
378+
div {
379+
span:first-child${ignoreSsrFlag} {
380+
border-bottom-left-radius: 0;
381+
}
382+
}
383+
`}
384+
/>
385+
)
386+
.toJSON()
387+
).toMatchSnapshot()
388+
expect(console.error).not.toBeCalled()
389+
})
346390
})
347391
})
348392

0 commit comments

Comments
 (0)