From 0244879c8fceb714039a9e95e53d9ad6ad5889a8 Mon Sep 17 00:00:00 2001 From: Jim Date: Fri, 6 May 2016 16:54:06 -0700 Subject: [PATCH] Basic SSR support for error boundaries (#6694) (cherry picked from commit 96cb8c5fc4ca20ff7393b5e7fd0271bd7c18cb7d) --- .../__tests__/ReactErrorBoundaries-test.js | 37 +++++++++++++++++++ .../server/ReactServerRenderingTransaction.js | 6 +++ 2 files changed, 43 insertions(+) diff --git a/src/core/__tests__/ReactErrorBoundaries-test.js b/src/core/__tests__/ReactErrorBoundaries-test.js index 0ba37323d5522..6272c89c58d75 100644 --- a/src/core/__tests__/ReactErrorBoundaries-test.js +++ b/src/core/__tests__/ReactErrorBoundaries-test.js @@ -13,11 +13,13 @@ var React; var ReactDOM; +var ReactDOMServer; describe('ReactErrorBoundaries', function() { beforeEach(function() { ReactDOM = require('ReactDOM'); + ReactDOMServer = require('ReactDOMServer'); React = require('React'); }); @@ -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 (
); + } else { + return (
Happy Birthday!
); + } + } + 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(); + 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() { diff --git a/src/renderers/dom/server/ReactServerRenderingTransaction.js b/src/renderers/dom/server/ReactServerRenderingTransaction.js index 176a550c599aa..e7909eeeedf13 100644 --- a/src/renderers/dom/server/ReactServerRenderingTransaction.js +++ b/src/renderers/dom/server/ReactServerRenderingTransaction.js @@ -60,6 +60,12 @@ var Mixin = { */ destructor: function() { }, + + checkpoint: function() { + }, + + rollback: function() { + }, };