@@ -97,8 +97,19 @@ exports.default = reactTreeWalker;
9797
9898var _react = __webpack_require__ ( 0 ) ;
9999
100+ var defaultOptions = {
101+ componentWillUnmount : false
102+ } ;
103+
100104// Lifted from https://github.com/sindresorhus/p-reduce
101105// Thanks @sindresorhus !
106+ /* eslint-disable no-console */
107+
108+ // Inspired by the awesome work done by the Apollo team.
109+ // See https://github.com/apollostack/react-apollo/blob/master/src/server.ts
110+ // This version has been adapted to be promise based.
111+
112+ // eslint-disable-next-line import/no-extraneous-dependencies
102113var pReduce = function pReduce ( iterable , reducer , initVal ) {
103114 return new Promise ( function ( resolve , reject ) {
104115 var iterator = iterable [ Symbol . iterator ] ( ) ;
@@ -124,13 +135,6 @@ var pReduce = function pReduce(iterable, reducer, initVal) {
124135
125136// Lifted from https://github.com/sindresorhus/p-map-series
126137// Thanks @sindresorhus !
127- /* eslint-disable no-console */
128-
129- // Inspired by the awesome work done by the Apollo team.
130- // See https://github.com/apollostack/react-apollo/blob/master/src/server.ts
131- // This version has been adapted to be promise based.
132-
133- // eslint-disable-next-line import/no-extraneous-dependencies
134138var pMapSeries = function pMapSeries ( iterable , iterator ) {
135139 var ret = [ ] ;
136140
@@ -151,6 +155,8 @@ var isPromise = exports.isPromise = function isPromise(x) {
151155// If visitor returns `false`, don't call the element's render function
152156// or recurse into its child elements
153157function reactTreeWalker ( element , visitor , context ) {
158+ var options = arguments . length > 3 && arguments [ 3 ] !== undefined ? arguments [ 3 ] : defaultOptions ;
159+
154160 return new Promise ( function ( resolve ) {
155161 var doVisit = function doVisit ( getChildren , visitorResult , childContext , isChildren ) {
156162 var doTraverse = function doTraverse ( shouldContinue ) {
@@ -229,7 +235,21 @@ function reactTreeWalker(element, visitor, context) {
229235 instance . componentWillMount ( ) ;
230236 }
231237
232- return instance . render ( ) ;
238+ var children = instance . render ( ) ;
239+
240+ if ( options . componentWillUnmount && instance . componentWillUnmount ) {
241+ try {
242+ instance . componentWillUnmount ( ) ;
243+ } catch ( err ) {
244+ // This is an experimental feature, we don't want to break
245+ // the bootstrapping process, but lets warn the user it
246+ // occurred.
247+ console . warn ( 'Error calling componentWillUnmount whilst walking your react tree' ) ;
248+ console . warn ( err ) ;
249+ }
250+ }
251+
252+ return children ;
233253 } , visitor ( element , instance , context ) , function ( ) {
234254 return (
235255 // Ensure the child context is initialised if it is available. We will
0 commit comments