Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic SSR support for error boundaries #6694

Merged
merged 1 commit into from
May 6, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions src/core/__tests__/ReactErrorBoundaries-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@

var React;
var ReactDOM;
var ReactDOMServer;

describe('ReactErrorBoundaries', function() {

beforeEach(function() {
ReactDOM = require('ReactDOM');
ReactDOMServer = require('ReactDOMServer');
React = require('React');
});

Expand Down Expand Up @@ -55,6 +57,41 @@ describe('ReactErrorBoundaries', function() {
expect(EventPluginHub.putListener).not.toBeCalled();
});

it('renders an error state (ssr)', function() {
class Angry extends React.Component {
render() {
throw new Error('Please, do not render me.');
}
}

class Boundary extends React.Component {
constructor(props) {
super(props);
this.state = {error: false};
}
render() {
if (!this.state.error) {
return (<div><button onClick={this.onClick}>ClickMe</button><Angry /></div>);
} else {
return (<div>Happy Birthday!</div>);
}
}
onClick() {
/* do nothing */
}
unstable_handleError() {
this.setState({error: true});
}
}

var EventPluginHub = require('EventPluginHub');
var container = document.createElement('div');
EventPluginHub.putListener = jest.fn();
container.innerHTML = ReactDOMServer.renderToString(<Boundary />);
expect(container.firstChild.innerHTML).toBe('Happy Birthday!');
expect(EventPluginHub.putListener).not.toBeCalled();
});

it('will catch exceptions in componentWillUnmount', function() {
class ErrorBoundary extends React.Component {
constructor() {
Expand Down
6 changes: 6 additions & 0 deletions src/renderers/dom/server/ReactServerRenderingTransaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ var Mixin = {
*/
destructor: function() {
},

checkpoint: function() {
},

rollback: function() {
},
};


Expand Down