File tree 1 file changed +16
-7
lines changed
packages/react-devtools-shared/src/backend/StyleX
1 file changed +16
-7
lines changed Original file line number Diff line number Diff line change @@ -67,7 +67,10 @@ function crawlObjectProperties(
67
67
// Special case; this key is the name of the style's source/file/module.
68
68
sources . add ( key ) ;
69
69
} else {
70
- resolvedStyles [ key ] = getPropertyValueForStyleName ( value ) ;
70
+ const propertyValue = getPropertyValueForStyleName ( value ) ;
71
+ if ( propertyValue != null ) {
72
+ resolvedStyles [ key ] = propertyValue ;
73
+ }
71
74
}
72
75
} else {
73
76
const nestedStyle = { } ;
@@ -90,13 +93,19 @@ function getPropertyValueForStyleName(styleName: string): string | null {
90
93
const styleSheet = ( ( document . styleSheets [
91
94
styleSheetIndex
92
95
] : any ) : CSSStyleSheet ) ;
93
- // $FlowFixMe Flow doesn't konw about these properties
94
- const rules = styleSheet . rules || styleSheet . cssRules ;
95
- // $FlowFixMe `rules` is mixed
96
+ let rules : CSSRuleList | null = null ;
97
+ // this might throw if CORS rules are enforced https://www.w3.org/TR/cssom-1/#the-cssstylesheet-interface
98
+ try {
99
+ rules = styleSheet . cssRules ;
100
+ } catch ( _e ) {
101
+ continue ;
102
+ }
103
+
96
104
for ( let ruleIndex = 0 ; ruleIndex < rules . length ; ruleIndex ++ ) {
97
- // $FlowFixMe `rules` is mixed
98
- const rule = rules [ ruleIndex ] ;
99
- // $FlowFixMe Flow doesn't konw about these properties
105
+ if ( ! ( rules [ ruleIndex ] instanceof CSSStyleRule ) ) {
106
+ continue ;
107
+ }
108
+ const rule = ( ( rules [ ruleIndex ] : any ) : CSSStyleRule ) ;
100
109
const { cssText, selectorText, style} = rule ;
101
110
102
111
if ( selectorText != null ) {
You can’t perform that action at this time.
0 commit comments