Skip to content

Commit

Permalink
force-update-fix fix bug where delayed render from componentDidMount …
Browse files Browse the repository at this point in the history
…can be called after unmount, which re-adds the unmounted portal

upgrade preact to latest and fix failing test case from that
  • Loading branch information
billneff79 committed Jan 29, 2018
1 parent afdc746 commit 1817743
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"babel-preset-es2015-minimal-rollup": "^2.0.0",
"babel-preset-react": "^6.5.0",
"babel-preset-stage-0": "^6.5.0",
"chai": "^3.5.0",
"chai": "^4.1.2",
"eslint": "^3.4.0",
"gzip-size-cli": "^1.0.0",
"karma": "^1.2.0",
Expand All @@ -63,16 +63,16 @@
"karma-sourcemap-loader": "^0.3.7",
"karma-webpack": "^1.7.0",
"mkdirp": "^0.5.1",
"mocha": "^3.0.2",
"mocha": "^5.0.0",
"npm-run-all": "^3.0.0",
"phantomjs-prebuilt": "^2.1.4",
"preact": "^5.7.0",
"preact": "^8.2.7",
"pretty-bytes-cli": "^1.0.0",
"rollup": "^0.34.11",
"rollup-plugin-babel": "^2.4.0",
"rollup-plugin-commonjs": "^3.3.1",
"rollup-plugin-node-resolve": "^2.0.0",
"sinon": "^1.17.2",
"sinon": "^4.2.2",
"sinon-chai": "^2.8.0",
"uglify-js": "^2.6.2",
"webpack": "^1.12.14"
Expand Down
4 changes: 4 additions & 0 deletions src/preact-portal.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ export default class Portal extends Component {
}

componentDidMount() {
this.isMounted=true;
this.renderLayer = this.renderLayer.bind(this);
this.renderLayer();
}

componentWillUnmount() {
this.renderLayer(false);
this.isMounted=false;
if (this.remote) this.remote.parentNode.removeChild(this.remote);
}

Expand All @@ -30,6 +32,8 @@ export default class Portal extends Component {
}

renderLayer(show=true) {
if (!this.isMounted) return;

// clean up old node if moving bases:
if (this.props.into!==this.intoPointer) {
this.intoPointer = this.props.into;
Expand Down
2 changes: 1 addition & 1 deletion test/preact-portal.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ describe('preact-portal', () => {

expect(Child)
.to.have.been.calledOnce
.and.calledWith({}, ctx);
.and.calledWith({children: []}, ctx);
});

it('should only create one instance when forced to rerender by parent during first render', () => {
Expand Down

0 comments on commit 1817743

Please sign in to comment.