Skip to content

Commit

Permalink
Fixed bug that would instanciate new components when not necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielbull committed Oct 8, 2016
1 parent cef4938 commit eefeaee
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 11 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG

## 0.2.2 (October 8th, 2016)

- Fixed bug that would instantiate new components when not necessary

## 0.2.1 (October 6th, 2016)

- Fixed issue with webpack bundle that would import the wrong module
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "react-router-server",
"author": "Gabriel Bull",
"version": "0.2.1",
"version": "0.2.2",
"description": "Server Side Rendering library for React Router v4",
"main": "./build/index.js",
"keywords": [
Expand Down
19 changes: 14 additions & 5 deletions src/match.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,26 @@ class Match extends Component {
serverRouter: PropTypes.object
}

render() {
const { match, render, ...props } = this.props;
const nextRender = matchProps => wrapperComponent(
componentWillMount() {
const { render } = this.props;
this.wrapperComponent = wrapperComponent(
render,
{ ...this.props },
this.context.serverRouter && this.context.serverRouter.asyncRenderer ?
this.context.serverRouter.asyncRenderer : null
)(matchProps);
);
const WrapperComponent = this.wrapperComponent;
this.nextRender = matchProps => {
return <WrapperComponent matchProps={matchProps}/>;
}
}

render() {
const { match, ...props } = this.props;
delete props.render;
delete props.willEnter;
const Match = match;
return <Match render={nextRender} {...props}/>;
return <Match render={this.nextRender} {...props}/>;
}
}

Expand Down
12 changes: 7 additions & 5 deletions src/wrapperComponent.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import React, { Component, PropTypes, isValidElement } from 'react'
import { setAsyncRenderer } from './importModule';

export default (render, options, asyncRenderer) => (matchProps) => {
class WrapperComponent extends Component {
export default (render, options, asyncRenderer) => {
return class extends Component {
static propTypes = {
matchProps: PropTypes.object
};

isComponentMounted = false;

constructor() {
Expand All @@ -28,7 +32,7 @@ export default (render, options, asyncRenderer) => (matchProps) => {

if (!WrappedComponent) {
setAsyncRenderer(asyncRenderer);
WrappedComponent = render(matchProps, { ...this.state.nextProps });
WrappedComponent = render(this.props.matchProps, { ...this.state.nextProps });
}

if (WrappedComponent.then) {
Expand Down Expand Up @@ -64,6 +68,4 @@ export default (render, options, asyncRenderer) => (matchProps) => {
return null;
}
}

return <WrapperComponent/>;
};

0 comments on commit eefeaee

Please sign in to comment.