Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremy-davis-sonarsource committed Apr 26, 2023
2 parents fd87787 + 149194e commit 3a8b81d
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 4 deletions.
6 changes: 6 additions & 0 deletions packages/cache/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @emotion/cache

## 11.10.7

### Patch Changes

- [#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.

## 11.10.5

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/cache/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@emotion/cache",
"version": "11.10.5",
"version": "11.10.7",
"description": "emotion's cache",
"main": "dist/emotion-cache.cjs.js",
"module": "dist/emotion-cache.esm.js",
Expand Down
6 changes: 3 additions & 3 deletions packages/cache/src/stylis-plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ export let createUnsafeSelectorsAlarm = cache => (element, index, children) => {
)

if (unsafePseudoClasses) {
const isNested = element.parent === children[0]
// in nested rules comments become children of the "auto-inserted" rule
const isNested = !!element.parent
// in nested rules comments become children of the "auto-inserted" rule and that's always the `element.parent`
//
// considering this input:
// .a {
Expand All @@ -182,7 +182,7 @@ export let createUnsafeSelectorsAlarm = cache => (element, index, children) => {
// .b {}
// }
const commentContainer = isNested
? children[0].children
? element.parent.children
: // global rule at the root level
children

Expand Down
20 changes: 20 additions & 0 deletions packages/react/__tests__/__snapshots__/warnings.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ exports[`global with css prop 1`] = `null`;

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`;

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`] = `
.emotion-0 div span:first-child {
border-bottom-left-radius: 0;
}
<div
className="emotion-0"
/>
`;

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`] = `
.emotion-0 {
color: hotpink;
Expand Down Expand Up @@ -93,6 +103,16 @@ exports[`unsafe pseudo classes does not warn when using with flag: /* emotion-di

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`;

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`] = `
.emotion-0 div span:first-child {
border-bottom-left-radius: 0;
}
<div
className="emotion-0"
/>
`;

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`] = `
.emotion-0 {
color: hotpink;
Expand Down
44 changes: 44 additions & 0 deletions packages/react/__tests__/warnings.js
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,50 @@ describe('unsafe pseudo classes', () => {
).toMatchSnapshot()
expect(console.error).not.toBeCalled()
})

test('does warn when not using the flag on a rule that is defined in another one', () => {
expect(
renderer
.create(
<div
css={css`
div {
span:first-child {
border-bottom-left-radius: 0;
}
}
`}
/>
)
.toJSON()
).toMatchSnapshot()
expect((console.error: any).mock.calls).toMatchInlineSnapshot(`
[
[
"The pseudo class ":first-child" is potentially unsafe when doing server-side rendering. Try changing it to ":first-of-type".",
],
]
`)
})

test('does not warn when using the flag on a rule that is defined in another one', () => {
expect(
renderer
.create(
<div
css={css`
div {
span:first-child${ignoreSsrFlag} {
border-bottom-left-radius: 0;
}
}
`}
/>
)
.toJSON()
).toMatchSnapshot()
expect(console.error).not.toBeCalled()
})
})
})

Expand Down

0 comments on commit 3a8b81d

Please sign in to comment.