File tree Expand file tree Collapse file tree 1 file changed +11
-2
lines changed
packages/react-refresh/src Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -178,6 +178,15 @@ function cloneSet<T>(set: Set<T>): Set<T> {
178
178
return clone ;
179
179
}
180
180
181
+ // This is a safety mechanism to protect against rogue getters and Proxies.
182
+ function getProperty(object, property) {
183
+ try {
184
+ return object [ property ] ;
185
+ } catch ( err ) {
186
+ return undefined ;
187
+ }
188
+ }
189
+
181
190
export function performReactRefresh(): RefreshUpdate | null {
182
191
if ( ! __DEV__ ) {
183
192
throw new Error (
@@ -322,7 +331,7 @@ export function register(type: any, id: string): void {
322
331
323
332
// Visit inner types because we might not have registered them.
324
333
if (typeof type === 'object' && type !== null ) {
325
- switch ( type . $$typeof ) {
334
+ switch ( getProperty ( type , ' $$typeof' ) ) {
326
335
case REACT_FORWARD_REF_TYPE :
327
336
register ( type . render , id + '$render' ) ;
328
337
break ;
@@ -676,7 +685,7 @@ export function isLikelyComponentType(type: any): boolean {
676
685
}
677
686
case 'object': {
678
687
if ( type != null ) {
679
- switch ( type . $$typeof ) {
688
+ switch ( getProperty ( type , ' $$typeof' ) ) {
680
689
case REACT_FORWARD_REF_TYPE :
681
690
case REACT_MEMO_TYPE :
682
691
// Definitely React components.
You can’t perform that action at this time.
0 commit comments