Skip to content

Commit 1286a65

Browse files
authored
fix(s2): Remove all: revert-layer to avoid Safari bugs (#7598)
1 parent ce54e26 commit 1286a65

File tree

11 files changed

+26
-39
lines changed

11 files changed

+26
-39
lines changed

.storybook-s2/docs/Icons.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {highlight} from './highlight' with {type: 'macro'};
66

77
export function Icons() {
88
return (
9-
<div className={style({marginX: 'auto'})}>
9+
<div className={'sb-unstyled ' + style({marginX: 'auto'})}>
1010
<div className={style({marginX: 48})}>
1111
<h1 className={style({font: 'heading-2xl', marginBottom: 48})}>
1212
Workflow icons

.storybook-s2/docs/Illustrations.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { useState } from 'react';
1111
export function Illustrations() {
1212
let [gradientStyle, setStyle] = useState('generic1');
1313
return (
14-
<div className={style({marginX: 'auto'})}>
14+
<div className={'sb-unstyled ' + style({marginX: 'auto'})}>
1515
<div className={style({marginX: 48})}>
1616
<h1 className={style({font: 'heading-2xl', marginBottom: 48})}>
1717
Illustrations

.storybook-s2/docs/Intro.jsx

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {H2, H3, H4, P, Pre, Code, Strong, Link} from './typography';
1313

1414
export function Docs() {
1515
return (
16-
<div className={style({marginX: 'auto', marginY: 48})}>
16+
<div className={'sb-unstyled ' + style({marginX: 'auto', marginY: 48})}>
1717
<header
1818
style={{
1919
backgroundImage: `url(${new URL('wallpaper_collaborative_S2_desktop.webp', import.meta.url).toString()})`,
@@ -228,7 +228,7 @@ import {ActionButton} from '@react-spectrum/s2';
228228
</ul>
229229
<H3>UNSAFE Style Overrides</H3>
230230
<P>We highly discourage overriding the styles of React Spectrum components because it may break at any time when we change our implementation, making it difficult for you to update in the future. Consider using <Link href="https://react-spectrum.adobe.com/react-aria/" target="_blank">React Aria Components</Link> with our <Link href="?path=/docs/style-macro--docs" target="_top">style macro</Link> to build a custom component with Spectrum styles instead.</P>
231-
<P>That said, just like in React Spectrum v3, the <Code>UNSAFE_className</Code> and <Code>UNSAFE_style</Code> props are supported on Spectrum 2 components as last-resort escape hatches. However, unlike in v3, UNSAFE_classNames must be placed in a special <Code>UNSAFE_overrides</Code> <Link href="https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Cascade_layers" target="_blank">CSS cascade layer</Link>. This guarentees that your overrides will always win over other styles on the page, no matter the order or specificity of the selector.</P>
231+
<P>That said, just like in React Spectrum v3, the <Code>UNSAFE_className</Code> and <Code>UNSAFE_style</Code> props are supported on Spectrum 2 components as last-resort escape hatches.</P>
232232
<Pre>{highlight(`/* YourComponent.tsx */
233233
import {Button} from '@react-spectrum/s2';
234234
import './YourComponent.css';
@@ -237,12 +237,10 @@ function YourComponent() {
237237
return <Button UNSAFE_className="your-unsafe-class">Button</Button>;
238238
}`)}</Pre>
239239
<Pre>{highlight(`/* YourComponent.css */
240-
@layer UNSAFE_overrides {
241-
/* Wrap all UNSAFE_className rules in this layer. */
242-
.your-unsafe-class {
243-
background: red;
244-
}
245-
}`, 'CSS')}</Pre>
240+
.your-unsafe-class {
241+
background: red;
242+
}
243+
`, 'CSS')}</Pre>
246244
</main>
247245
</div>
248246
)

.storybook-s2/docs/MDXLayout.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const mdxComponents = {
1919

2020
export function MDXLayout({children}) {
2121
return (
22-
<div className={style({marginX: 'auto'})}>
22+
<div className={'sb-unstyled ' + style({marginX: 'auto'})}>
2323
<main className={style({marginX: 48})}>
2424
<MDXProvider components={mdxComponents}>
2525
{children}

.storybook-s2/docs/Migrating.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {P, Code, Pre, H3, H2, Link} from './typography';
33

44
export function Migrating() {
55
return (
6-
<div className={style({marginX: 'auto', fontFamily: 'sans'})}>
6+
<div className={'sb-unstyled ' + style({marginX: 'auto', fontFamily: 'sans'})}>
77
<div className={style({marginX: 48})}>
88
<h1 className={style({font: 'heading-2xl', marginBottom: 48})}>
99
Migrating to Spectrum 2

.storybook-s2/docs/StyleMacro.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {Colors} from './Colors';
66

77
export function StyleMacro() {
88
return (
9-
<div className={style({marginX: 'auto'})}>
9+
<div className={'sb-unstyled ' + style({marginX: 'auto'})}>
1010
<header
1111
className={style({
1212
paddingX: 48,

packages/@react-spectrum/s2/src/Skeleton.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export const loadingStyle = raw(`
8282
* {
8383
visibility: hidden;
8484
}
85-
`, 'UNSAFE_overrides');
85+
`, 'L'); // add to a separate layer so it overrides default style macro styles
8686

8787
export function useSkeletonText(children: ReactNode, style: CSSProperties | undefined): [ReactNode, CSSProperties | undefined] {
8888
let isSkeleton = useContext(SkeletonContext);

packages/@react-spectrum/s2/stories/ActionButton.stories.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,7 @@ export const UnsafeClassName: Story = {
176176
render: (args) => {
177177
return (
178178
<div className={style({display: 'flex', gap: 8, justifyContent: 'center', overflow: 'auto'})}>
179-
<ActionButton {...args} UNSAFE_className="unsafe1">Global unsafe does not apply</ActionButton>
180-
<ActionButton {...args} UNSAFE_className="unsafe2">@layer UNSAFE_overrides works</ActionButton>
179+
<ActionButton {...args} UNSAFE_className="unsafe2">UNSAFE_className works</ActionButton>
181180
</div>
182181
);
183182
},

packages/@react-spectrum/s2/stories/unsafe.css

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,7 @@
1010
* governing permissions and limitations under the License.
1111
*/
1212

13-
button {
14-
/* This should not apply */
15-
background: red;
16-
}
17-
18-
html body .unsafe1 {
19-
/* This should not apply */
20-
background: red;
21-
}
22-
23-
@layer UNSAFE_overrides {
24-
.unsafe2 {
25-
/* This one should work */
26-
background: hotpink;
27-
}
13+
.unsafe2 {
14+
/* This one should work */
15+
background: hotpink;
2816
}

packages/@react-spectrum/s2/style/__tests__/style-macro.test.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@ describe('style-macro', () => {
3737
});
3838

3939
expect(css).toMatchInlineSnapshot(`
40-
".\\.:not(#a#b) { all: revert-layer }
41-
42-
@layer _.a, _.b, _.c, UNSAFE_overrides;
40+
"@layer _.a, _.b, _.c;
4341
4442
@layer _.b {
4543
.A-13alit4c {
@@ -72,9 +70,7 @@ describe('style-macro', () => {
7270
});
7371

7472
expect(css).toMatchInlineSnapshot(`
75-
".\\.:not(#a#b) { all: revert-layer }
76-
77-
@layer _.a, _.b, UNSAFE_overrides;
73+
"@layer _.a, _.b;
7874
7975
@layer _.a {
8076
.uc {

0 commit comments

Comments
 (0)