@@ -58,19 +58,34 @@ exports.create = function (config) {
58
58
if ( process . env . NODE_ENV !== 'production' ) {
59
59
renderer . sh . setAttribute ( 'data-nano-css-dev' , '' ) ;
60
60
61
- // Test style sheet used in dev mode to test if .insetRule() would throw.
61
+ // Test style sheet used in DEV mode to test if .insetRule() would throw.
62
62
renderer . shTest = document . createElement ( 'style' ) ;
63
63
renderer . shTest . setAttribute ( 'data-nano-css-dev-tests' , '' ) ;
64
64
document . head . appendChild ( renderer . shTest ) ;
65
65
}
66
66
67
67
renderer . putRaw = function ( rawCssRule ) {
68
+ // .insertRule() is faster than .appendChild(), that's why we use it in PROD.
69
+ // But CSS injected using .insertRule() is not displayed in Chrome Devtools,
70
+ // that's why we use .appendChild in DEV.
68
71
if ( process . env . NODE_ENV === 'production' ) {
69
72
var sheet = renderer . sh . sheet ;
70
- sheet . insertRule ( rawCssRule , sheet . cssRules . length ) ;
73
+
74
+ // Unknown pseudo-selectors will throw, this try/catch swallows all errors.
75
+ try {
76
+ sheet . insertRule ( rawCssRule , sheet . cssRules . length ) ;
77
+ // eslint-disable-next-line no-empty
78
+ } catch ( error ) { }
71
79
} else {
72
- // Test if .insertRule() works (does not throw).
73
- renderer . shTest . sheet . insertRule ( rawCssRule , renderer . shTest . sheet . cssRules . length ) ;
80
+ // Test if .insertRule() works in dev mode. Unknown pseudo-selectors will throw when
81
+ // .insertRule() is used, but .appendChild() will not throw.
82
+ try {
83
+ renderer . shTest . sheet . insertRule ( rawCssRule , renderer . shTest . sheet . cssRules . length ) ;
84
+ } catch ( error ) {
85
+ if ( config . verbose ) {
86
+ console . error ( error ) ;
87
+ }
88
+ }
74
89
75
90
// Insert pretty-printed CSS for dev mode.
76
91
renderer . sh . appendChild ( document . createTextNode ( rawCssRule ) ) ;
0 commit comments