@@ -4,7 +4,7 @@ import { removeCSS, updateCSS } from 'rc-util/lib/Dom/dynamicCSS';
44import * as React from 'react' ;
55// @ts -ignore
66import unitless from '@emotion/unitless' ;
7- import { compile , serialize , stringify } from 'stylis' ;
7+ import { compile , middleware , prefixer , serialize , stringify } from 'stylis' ;
88import type { Theme , Transformer } from '..' ;
99import type Keyframes from '../Keyframes' ;
1010import type { Linter } from '../linters' ;
@@ -80,8 +80,11 @@ export interface CSSObject
8080// == Parser ==
8181// ============================================================================
8282// Preprocessor style content to browser support one
83- export function normalizeStyle ( styleStr : string ) {
84- const serialized = serialize ( compile ( styleStr ) , stringify ) ;
83+ export function normalizeStyle ( styleStr : string , autoPrefix : boolean ) {
84+ const serialized = autoPrefix
85+ ? serialize ( compile ( styleStr ) , middleware ( [ prefixer , stringify ] ) )
86+ : serialize ( compile ( styleStr ) , stringify ) ;
87+
8588 return serialized . replace ( / \{ % % % \: [ ^ ; ] ; } / g, ';' ) ;
8689}
8790
@@ -398,6 +401,7 @@ export default function useStyleRegister(
398401 linters,
399402 cache,
400403 layer : enableLayer ,
404+ autoPrefix,
401405 } = React . useContext ( StyleContext ) ;
402406
403407 const fullPath : string [ ] = [ hashId || '' ] ;
@@ -438,7 +442,7 @@ export default function useStyleRegister(
438442 linters,
439443 } ) ;
440444
441- const styleStr = normalizeStyle ( parsedStyle ) ;
445+ const styleStr = normalizeStyle ( parsedStyle , autoPrefix || false ) ;
442446 const styleId = uniqueHash ( fullPath , styleStr ) ;
443447
444448 return [ styleStr , styleId , effectStyle , clientOnly , order ] ;
@@ -486,7 +490,7 @@ export default function useStyleRegister(
486490 // Inject layer style
487491 effectLayerKeys . forEach ( ( effectKey ) => {
488492 updateCSS (
489- normalizeStyle ( effectStyle [ effectKey ] ) ,
493+ normalizeStyle ( effectStyle [ effectKey ] , autoPrefix || false ) ,
490494 `_layer-${ effectKey } ` ,
491495 { ...mergedCSSConfig , prepend : true } ,
492496 ) ;
@@ -507,7 +511,7 @@ export default function useStyleRegister(
507511 // Inject client side effect style
508512 effectRestKeys . forEach ( ( effectKey ) => {
509513 updateCSS (
510- normalizeStyle ( effectStyle [ effectKey ] ) ,
514+ normalizeStyle ( effectStyle [ effectKey ] , autoPrefix || false ) ,
511515 `_effect-${ effectKey } ` ,
512516 mergedCSSConfig ,
513517 ) ;
@@ -524,7 +528,7 @@ export const extract: ExtractStyle<StyleCacheValue> = (
524528) => {
525529 const [ styleStr , styleId , effectStyle , clientOnly , order ] : StyleCacheValue =
526530 cache ;
527- const { plain } = options || { } ;
531+ const { plain, autoPrefix } = options || { } ;
528532
529533 // Skip client only style
530534 if ( clientOnly ) {
@@ -549,7 +553,10 @@ export const extract: ExtractStyle<StyleCacheValue> = (
549553 // Effect style can be reused
550554 if ( ! effectStyles [ effectKey ] ) {
551555 effectStyles [ effectKey ] = true ;
552- const effectStyleStr = normalizeStyle ( effectStyle [ effectKey ] ) ;
556+ const effectStyleStr = normalizeStyle (
557+ effectStyle [ effectKey ] ,
558+ autoPrefix || false ,
559+ ) ;
553560 const effectStyleHTML = toStyleStr (
554561 effectStyleStr ,
555562 undefined ,
0 commit comments