File tree 1 file changed +12
-2
lines changed
packages/react-refresh/src 1 file changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -178,6 +178,16 @@ 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
+ // Intentionally ignore.
187
+ return undefined ;
188
+ }
189
+ }
190
+
181
191
export function performReactRefresh(): RefreshUpdate | null {
182
192
if ( ! __DEV__ ) {
183
193
throw new Error (
@@ -322,7 +332,7 @@ export function register(type: any, id: string): void {
322
332
323
333
// Visit inner types because we might not have registered them.
324
334
if (typeof type === 'object' && type !== null ) {
325
- switch ( type . $$typeof ) {
335
+ switch ( getProperty ( type , ' $$typeof' ) ) {
326
336
case REACT_FORWARD_REF_TYPE :
327
337
register ( type . render , id + '$render' ) ;
328
338
break ;
@@ -676,7 +686,7 @@ export function isLikelyComponentType(type: any): boolean {
676
686
}
677
687
case 'object': {
678
688
if ( type != null ) {
679
- switch ( type . $$typeof ) {
689
+ switch ( getProperty ( type , ' $$typeof' ) ) {
680
690
case REACT_FORWARD_REF_TYPE :
681
691
case REACT_MEMO_TYPE :
682
692
// Definitely React components.
You can’t perform that action at this time.
0 commit comments