Skip to content
This repository has been archived by the owner on Dec 31, 2020. It is now read-only.

Commit

Permalink
fix disposeOnUnmount when using react-hot-loader (#886)
Browse files Browse the repository at this point in the history
  • Loading branch information
fellmann authored Jul 26, 2020
1 parent 376bff7 commit a492988
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### 6.2.3

- Log warning if class component is already an observer to prevent memory leaks. [#839](https://github.com/mobxjs/mobx-react/issues/839)
- Fix disposeOnUnmount when using react-hot-loader. [#725](https://github.com/mobxjs/mobx-react/issues/725)

### 6.2.2

Expand Down
8 changes: 6 additions & 2 deletions src/disposeOnUnmount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,18 @@ export function disposeOnUnmount(
return propertyKeyOrFunction.map(fn => disposeOnUnmount(target, fn))
}

const c = Object.getPrototypeOf(target).constructor || Object.getPrototypeOf(target.constructor)
const c = Object.getPrototypeOf(target).constructor
const c2 = Object.getPrototypeOf(target.constructor)
// Special case for react-hot-loader
const c3 = Object.getPrototypeOf(Object.getPrototypeOf(target))
if (
!(
c === React.Component ||
c === React.PureComponent ||
c2 === React.Component ||
c2 === React.PureComponent
c2 === React.PureComponent ||
c3 === React.Component ||
c3 === React.PureComponent
)
) {
throw new Error(
Expand Down

0 comments on commit a492988

Please sign in to comment.