Basic SSR support for error boundaries (#6694)
Jim committed
May 6, 2016 at 16:54 UTC
96cb8c5fc4ca20ff7393b5e7fd0271bd7c18cb7d
2 files changed
+43
src/core/__tests__/ReactErrorBoundaries-test.js
+37
@@ -13,11 +13,13 @@
13
14
var React;
15
var ReactDOM;
16
+var ReactDOMServer;
17
18
describe('ReactErrorBoundaries', function() {
19
20
beforeEach(function() {
21
ReactDOM = require('ReactDOM');
22
+ ReactDOMServer = require('ReactDOMServer');
23
React = require('React');
24
});
25
@@ -55,6 +57,41 @@ describe('ReactErrorBoundaries', function() {
57
expect(EventPluginHub.putListener).not.toBeCalled();
58
});
59
60
+ it('renders an error state (ssr)', function() {
61
+ class Angry extends React.Component {
62
+ render() {
63
+ throw new Error('Please, do not render me.');
64
+ }
65
+ }
66
+
67
+ class Boundary extends React.Component {
68
+ constructor(props) {
69
+ super(props);
70
+ this.state = {error: false};
71
+ }
72
+ render() {
73
+ if (!this.state.error) {
74
+ return (<div><button onClick={this.onClick}>ClickMe</button><Angry /></div>);
75
+ } else {
76
+ return (<div>Happy Birthday!</div>);
77
+ }
78
+ }
79
+ onClick() {
80
+ /* do nothing */
81
+ }
82
+ unstable_handleError() {
83
+ this.setState({error: true});
84
+ }
85
+ }
86
+
87
+ var EventPluginHub = require('EventPluginHub');
88
+ var container = document.createElement('div');
89
+ EventPluginHub.putListener = jest.fn();
90
+ container.innerHTML = ReactDOMServer.renderToString(<Boundary />);
91
+ expect(container.firstChild.innerHTML).toBe('Happy Birthday!');
92
+ expect(EventPluginHub.putListener).not.toBeCalled();
93
+ });
94
+
95
it('will catch exceptions in componentWillUnmount', function() {
96
class ErrorBoundary extends React.Component {
97
constructor() {
src/renderers/dom/server/ReactServerRenderingTransaction.js
+6
@@ -60,6 +60,12 @@ var Mixin = {
60
*/
61
destructor: function() {
62
},
63
+
64
+ checkpoint: function() {
65
+ },
66
+
67
+ rollback: function() {
68
+ },
69
};
70
71