Skip to content

Commit

Permalink
[Fast Refresh] Fix crashes caused by some rogue getters and Proxies (f…
Browse files Browse the repository at this point in the history
  • Loading branch information
kri committed Oct 15, 2020
1 parent 2eb3181 commit fd981d6
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions packages/react-refresh/src/ReactFreshRuntime.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,15 @@ function cloneSet<T>(set: Set<T>): Set<T> {
return clone;
}

// This is a safety mechanism to protect against rogue getters and Proxies.
function getProperty(object, property) {
try {
return object[property];
} catch (err) {
return undefined;
}
}

export function performReactRefresh(): RefreshUpdate | null {
if (!__DEV__) {
throw new Error(
Expand Down Expand Up @@ -322,7 +331,7 @@ export function register(type: any, id: string): void {

// Visit inner types because we might not have registered them.
if (typeof type === 'object' && type !== null) {
switch (type.$$typeof) {
switch (getProperty(type, '$$typeof')) {
case REACT_FORWARD_REF_TYPE:
register(type.render, id + '$render');
break;
Expand Down Expand Up @@ -676,7 +685,7 @@ export function isLikelyComponentType(type: any): boolean {
}
case 'object': {
if (type != null) {
switch (type.$$typeof) {
switch (getProperty(type, '$$typeof')) {
case REACT_FORWARD_REF_TYPE:
case REACT_MEMO_TYPE:
// Definitely React components.
Expand Down

0 comments on commit fd981d6

Please sign in to comment.