Skip to content

Commit

Permalink
Clear dispatch token (#52)
Browse files Browse the repository at this point in the history
It seems that in certain versions of React it was possible for
`componentWillMount` to be called more than once. facebook/react#6613

If that happened to a `connect`ed component, it would cause
`dispatcher.unregister` to be called again with a token that was already
unregistered causing an exception.

This `null`s the token field so unregister can only be called once for a
given token.
  • Loading branch information
colbyr authored Mar 6, 2017
1 parent 89ed703 commit 0736f80
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 6 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 2.2.1
* Fix a potential bug in connect/StoreDependencyMixin that could cause an exeption in `componentWillUnmount`

## 2.2.0
* Component generated by `connect` inherits propTypes unrelated to the store dependencies from the BaseComponent

Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "general-store",
"version": "2.2.0",
"version": "2.2.1",
"homepage": "https://github.com/HubSpot/general-store",
"authors": [
"Colby Rabideau <crabideau@hubspot.com>"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "general-store",
"version": "2.2.0",
"version": "2.2.1",
"description": "Simple, flexible store implementation for Flux.",
"main": "lib/GeneralStore.js",
"scripts": {
Expand Down
6 changes: 4 additions & 2 deletions src/dependencies/StoreDependencyMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,10 @@ export default function StoreDependencyMixin(
},

componentWillUnmount(): void {
if (dispatcher && this.__dispatchToken) {
dispatcher.unregister(this.__dispatchToken);
const dispatchToken = this.__dispatchToken;
if (dispatcher && dispatchToken) {
this.__dispatchToken = null;
dispatcher.unregister(dispatchToken);
}
},

Expand Down
6 changes: 4 additions & 2 deletions src/dependencies/connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,10 @@ export default function connect(
}

componentWillUnmount(): void {
if (dispatcher && this.dispatchToken) {
dispatcher.unregister(this.dispatchToken);
const dispatchToken = this.dispatchToken;
if (dispatcher && dispatchToken) {
this.dispatchToken = null;
dispatcher.unregister(dispatchToken);
}
}

Expand Down

0 comments on commit 0736f80

Please sign in to comment.