Skip to content

Commit

Permalink
breaking refactor(stylis): disable vendor prefixing by default
Browse files Browse the repository at this point in the history
Thankfully vendor prefixes are far less likely to be needed
thes days. They can still be enabled via `StyleSheetManager`.

Accordingly, the `disableVendorPrefixes` prop in `StyleSheetManager`
has been revised to `enableVendorPrefixes`.
  • Loading branch information
quantizor committed Mar 19, 2023
1 parent fe1ceb1 commit 2b4f6cb
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 184 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -456,36 +456,15 @@ describe(`createGlobalStyle`, () => {
expect(getRenderedCSS()).toMatchInlineSnapshot(`
"div {
display: inline-block;
-webkit-animation: a 2s linear infinite;
animation: a 2s linear infinite;
padding: 2rem 1rem;
font-size: 1.2rem;
}
@-webkit-keyframes a {
from {
-webkit-transform: rotate(0deg);
-moz-transform: rotate(0deg);
-ms-transform: rotate(0deg);
transform: rotate(0deg);
}
to {
-webkit-transform: rotate(360deg);
-moz-transform: rotate(360deg);
-ms-transform: rotate(360deg);
transform: rotate(360deg);
}
}
@keyframes a {
from {
-webkit-transform: rotate(0deg);
-moz-transform: rotate(0deg);
-ms-transform: rotate(0deg);
transform: rotate(0deg);
}
to {
-webkit-transform: rotate(360deg);
-moz-transform: rotate(360deg);
-ms-transform: rotate(360deg);
transform: rotate(360deg);
}
}"
Expand Down
154 changes: 29 additions & 125 deletions packages/styled-components/src/constructors/test/keyframes.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,8 @@ describe('keyframes', () => {

expect(getRenderedCSS()).toMatchInlineSnapshot(`
".c {
-webkit-animation: a 2s linear infinite;
animation: a 2s linear infinite;
}
@-webkit-keyframes a {
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}
@keyframes a {
0% {
opacity: 0;
Expand Down Expand Up @@ -108,27 +99,18 @@ describe('keyframes', () => {
TestRenderer.create(<Comp />);

expect(getRenderedCSS()).toMatchInlineSnapshot(`
".c {
-webkit-animation: a 2s linear infinite;
animation: a 2s linear infinite;
}
@-webkit-keyframes a {
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}
@keyframes a {
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}"
`);
".c {
animation: a 2s linear infinite;
}
@keyframes a {
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}"
`);
});

it('should insert the correct styles for objects with nesting', () => {
Expand Down Expand Up @@ -161,33 +143,23 @@ describe('keyframes', () => {
TestRenderer.create(<Comp />);

expect(getRenderedCSS()).toMatchInlineSnapshot(`
"@media(max-width:700px) {
.c {
-webkit-animation: a 2s linear infinite;
animation: a 2s linear infinite;
}
.c :hover {
-webkit-animation: a 10s linear infinite;
animation: a 10s linear infinite;
}
}
@-webkit-keyframes a {
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}
@keyframes a {
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}"
`);
"@media(max-width:700px) {
.c {
animation: a 2s linear infinite;
}
.c :hover {
animation: a 10s linear infinite;
}
}
@keyframes a {
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}"
`);
});

it('should insert the correct styles when keyframes in props', () => {
Expand All @@ -211,17 +183,8 @@ describe('keyframes', () => {

expect(getRenderedCSS()).toMatchInlineSnapshot(`
".c {
-webkit-animation: a 2s linear infinite;
animation: a 2s linear infinite;
}
@-webkit-keyframes a {
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}
@keyframes a {
0% {
opacity: 0;
Expand Down Expand Up @@ -287,57 +250,25 @@ describe('keyframes', () => {

expect(getRenderedCSS()).toMatchInlineSnapshot(`
".d {
-webkit-animation: none;
animation: none;
}
.e {
-webkit-animation: b 1s linear, a 1s linear;
animation: b 1s linear, a 1s linear;
}
.f {
-webkit-animation: a 1s linear;
animation: a 1s linear;
}
.g {
-webkit-animation: b 1s linear;
animation: b 1s linear;
}
@-webkit-keyframes b {
from {
-webkit-transform: translateX(-10px);
-moz-transform: translateX(-10px);
-ms-transform: translateX(-10px);
transform: translateX(-10px);
}
to {
-webkit-transform: none;
-moz-transform: none;
-ms-transform: none;
transform: none;
}
}
@keyframes b {
from {
-webkit-transform: translateX(-10px);
-moz-transform: translateX(-10px);
-ms-transform: translateX(-10px);
transform: translateX(-10px);
}
to {
-webkit-transform: none;
-moz-transform: none;
-ms-transform: none;
transform: none;
}
}
@-webkit-keyframes a {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
@keyframes a {
from {
opacity: 0;
Expand Down Expand Up @@ -380,17 +311,8 @@ describe('keyframes', () => {

expect(getRenderedCSS()).toMatchInlineSnapshot(`
".c {
-webkit-animation: a-1567285458 2s linear infinite;
animation: a-1567285458 2s linear infinite;
}
@-webkit-keyframes a-1567285458 {
0% {
right: 0%;
}
100% {
right: 100%;
}
}
@keyframes a-1567285458 {
0% {
right: 0%;
Expand Down Expand Up @@ -430,21 +352,11 @@ describe('keyframes', () => {

expect(getRenderedCSS()).toMatchInlineSnapshot(`
".c {
-webkit-animation: a 2s linear infinite;
animation: a 2s linear infinite;
}
.d {
-webkit-animation: a-1567285458 2s linear infinite;
animation: a-1567285458 2s linear infinite;
}
@-webkit-keyframes a {
0% {
left: 0%;
}
100% {
left: 100%;
}
}
@keyframes a {
0% {
left: 0%;
Expand All @@ -453,14 +365,6 @@ describe('keyframes', () => {
left: 100%;
}
}
@-webkit-keyframes a-1567285458 {
0% {
right: 0%;
}
100% {
right: 100%;
}
}
@keyframes a-1567285458 {
0% {
right: 0%;
Expand Down
6 changes: 3 additions & 3 deletions packages/styled-components/src/models/StyleSheetManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export type IStyleSheetManager = React.PropsWithChildren<{
* If you are working exclusively with modern browsers, vendor prefixes can often be omitted
* to reduce the weight of CSS on the page.
*/
disableVendorPrefixes?: boolean;
enableVendorPrefixes?: boolean;
/**
* Provide an optional selector to be prepended to all generated style rules.
*/
Expand Down Expand Up @@ -100,10 +100,10 @@ export function StyleSheetManager(props: IStyleSheetManager): JSX.Element {
const stylis = useMemo(
() =>
createStylisInstance({
options: { namespace: props.namespace, prefix: !props.disableVendorPrefixes },
options: { namespace: props.namespace, prefix: props.enableVendorPrefixes },
plugins,
}),
[props.disableVendorPrefixes, props.namespace, plugins]
[props.enableVendorPrefixes, props.namespace, plugins]
);

useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,13 +279,13 @@ describe('StyleSheetManager', () => {
expect(indexOfBlueStyle).toBeGreaterThan(indexOfRedStyle);
});

it('passing disableVendorPrefixes to StyleSheetManager works', () => {
it('passing `enableVendorPrefixes` to StyleSheetManager works', () => {
const Test = styled.div`
display: flex;
`;

TestRenderer.create(
<StyleSheetManager disableVendorPrefixes>
<StyleSheetManager enableVendorPrefixes>
<Test>Foo</Test>
</StyleSheetManager>
);
Expand All @@ -294,7 +294,7 @@ describe('StyleSheetManager', () => {
<style data-styled="active"
data-styled-version="JEST_MOCK_VERSION"
>
.b{display:flex;}
.b{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;}
</style>
`);
});
Expand Down Expand Up @@ -529,7 +529,7 @@ describe('StyleSheetManager', () => {
<style data-styled="active"
data-styled-version="JEST_MOCK_VERSION"
>
#foo .b{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;}
#foo .b{display:flex;}
</style>
`);
});
Expand Down
9 changes: 0 additions & 9 deletions packages/styled-components/src/test/css.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ describe('css features', () => {
TestRenderer.create(<Comp />);
expect(getRenderedCSS()).toMatchInlineSnapshot(`
".b {
-webkit-transition: opacity 0.3s;
transition: opacity 0.3s;
}"
`);
Expand All @@ -35,16 +34,8 @@ describe('css features', () => {
TestRenderer.create(<Comp />);
expect(getRenderedCSS()).toMatchInlineSnapshot(`
".b {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-flex-direction: column;
-ms-flex-direction: column;
flex-direction: column;
-webkit-align-items: center;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
}"
`);
Expand Down

0 comments on commit 2b4f6cb

Please sign in to comment.