11( function webpackUniversalModuleDefinition ( root , factory ) {
22 if ( typeof exports === 'object' && typeof module === 'object' )
3- module . exports = factory ( require ( "react" ) , require ( "react-dom" ) ) ;
3+ module . exports = factory ( require ( "react" ) , require ( "react-dom" ) , require ( "react-dom/server" ) ) ;
44 else if ( typeof define === 'function' && define . amd )
5- define ( [ "react" , "react-dom" ] , factory ) ;
5+ define ( [ "react" , "react-dom" , "react-dom/server" ] , factory ) ;
66 else if ( typeof exports === 'object' )
7- exports [ "ReactRailsUJS" ] = factory ( require ( "react" ) , require ( "react-dom" ) ) ;
7+ exports [ "ReactRailsUJS" ] = factory ( require ( "react" ) , require ( "react-dom" ) , require ( "react-dom/server" ) ) ;
88 else
9- root [ "ReactRailsUJS" ] = factory ( root [ "React" ] , root [ "ReactDOM" ] ) ;
10- } ) ( this , function ( __WEBPACK_EXTERNAL_MODULE_3__ , __WEBPACK_EXTERNAL_MODULE_4__ ) {
9+ root [ "ReactRailsUJS" ] = factory ( root [ "React" ] , root [ "ReactDOM" ] , root [ "ReactDOMServer" ] ) ;
10+ } ) ( this , function ( __WEBPACK_EXTERNAL_MODULE_3__ , __WEBPACK_EXTERNAL_MODULE_4__ , __WEBPACK_EXTERNAL_MODULE_5__ ) {
1111return /******/ ( function ( modules ) { // webpackBootstrap
1212/******/ // The module cache
1313/******/ var installedModules = { } ;
@@ -73,18 +73,18 @@ return /******/ (function(modules) { // webpackBootstrap
7373/******/ __webpack_require__ . p = "" ;
7474/******/
7575/******/ // Load entry module and return exports
76- /******/ return __webpack_require__ ( __webpack_require__ . s = 5 ) ;
76+ /******/ return __webpack_require__ ( __webpack_require__ . s = 6 ) ;
7777/******/ } )
7878/************************************************************************/
7979/******/ ( [
8080/* 0 */
8181/***/ ( function ( module , exports , __webpack_require__ ) {
8282
83- var nativeEvents = __webpack_require__ ( 6 )
84- var pjaxEvents = __webpack_require__ ( 7 )
85- var turbolinksEvents = __webpack_require__ ( 8 )
86- var turbolinksClassicDeprecatedEvents = __webpack_require__ ( 10 )
87- var turbolinksClassicEvents = __webpack_require__ ( 9 )
83+ var nativeEvents = __webpack_require__ ( 7 )
84+ var pjaxEvents = __webpack_require__ ( 8 )
85+ var turbolinksEvents = __webpack_require__ ( 9 )
86+ var turbolinksClassicDeprecatedEvents = __webpack_require__ ( 11 )
87+ var turbolinksClassicEvents = __webpack_require__ ( 10 )
8888
8989// see what things are globally available
9090// and setup event handlers to those things
@@ -127,13 +127,13 @@ module.exports = function(ujs) {
127127// Also, try to gracefully import Babel 6 style default exports
128128module . exports = function ( className ) {
129129 var constructor ;
130-
130+ var topLevel = typeof window === "undefined" ? this : window ;
131131 // Try to access the class globally first
132- constructor = window [ className ] ;
132+ constructor = topLevel [ className ] ;
133133
134134 // If that didn't work, try eval
135135 if ( ! constructor ) {
136- constructor = eval . call ( window , className ) ;
136+ constructor = eval . call ( topLevel , className ) ;
137137 }
138138
139139 // Lastly, if there is a default attribute try that
@@ -160,7 +160,6 @@ module.exports = function(reqctx) {
160160 var parts = className . split ( "." )
161161 var filename = parts . shift ( )
162162 var keys = parts
163- console . log ( filename , keys )
164163 // Load the module:
165164 var component = reqctx ( "./" + filename )
166165 // Then access each key:
@@ -190,10 +189,17 @@ module.exports = __WEBPACK_EXTERNAL_MODULE_4__;
190189
191190/***/ } ) ,
192191/* 5 */
192+ /***/ ( function ( module , exports ) {
193+
194+ module . exports = __WEBPACK_EXTERNAL_MODULE_5__ ;
195+
196+ /***/ } ) ,
197+ /* 6 */
193198/***/ ( function ( module , exports , __webpack_require__ ) {
194199
195200var React = __webpack_require__ ( 3 )
196201var ReactDOM = __webpack_require__ ( 4 )
202+ var ReactDOMServer = __webpack_require__ ( 5 )
197203
198204var detectEvents = __webpack_require__ ( 0 )
199205var constructorFromGlobal = __webpack_require__ ( 1 )
@@ -209,7 +215,7 @@ var ReactRailsUJS = {
209215 PROPS_ATTR : 'data-react-props' ,
210216
211217 // If jQuery is detected, save a reference to it for event handlers
212- jQuery : ( typeof window . jQuery !== 'undefined' ) && window . jQuery ,
218+ jQuery : ( typeof window !== 'undefined' ) && ( typeof window . jQuery !== 'undefined' ) && window . jQuery ,
213219
214220 // helper method for the mount and unmount methods to find the
215221 // `data-react-class` DOM elements
@@ -252,6 +258,14 @@ var ReactRailsUJS = {
252258 this . getConstructor = constructorFromRequireContext ( req )
253259 } ,
254260
261+ // Render `componentName` with `props` to a string,
262+ // using the specified `renderFunction` from `react-dom/server`.
263+ serverRender : function ( renderFunction , componentName , props ) {
264+ var componentClass = this . getConstructor ( componentName )
265+ var element = React . createElement ( componentClass , props )
266+ return ReactDOMServer [ renderFunction ] ( element )
267+ } ,
268+
255269 // Within `searchSelector`, find nodes which should have React components
256270 // inside them, and mount them with their props.
257271 mountComponents : function ( searchSelector ) {
@@ -289,13 +303,16 @@ var ReactRailsUJS = {
289303 } ,
290304}
291305
292- detectEvents ( ReactRailsUJS )
306+ if ( typeof window !== "undefined" ) {
307+ // Only setup events for browser (not server-rendering)
308+ detectEvents ( ReactRailsUJS )
309+ }
293310
294311module . exports = ReactRailsUJS
295312
296313
297314/***/ } ) ,
298- /* 6 */
315+ /* 7 */
299316/***/ ( function ( module , exports ) {
300317
301318module . exports = {
@@ -316,7 +333,7 @@ module.exports = {
316333
317334
318335/***/ } ) ,
319- /* 7 */
336+ /* 8 */
320337/***/ ( function ( module , exports ) {
321338
322339module . exports = {
@@ -330,7 +347,7 @@ module.exports = {
330347
331348
332349/***/ } ) ,
333- /* 8 */
350+ /* 9 */
334351/***/ ( function ( module , exports ) {
335352
336353module . exports = {
@@ -343,7 +360,7 @@ module.exports = {
343360
344361
345362/***/ } ) ,
346- /* 9 */
363+ /* 10 */
347364/***/ ( function ( module , exports ) {
348365
349366module . exports = {
@@ -357,7 +374,7 @@ module.exports = {
357374
358375
359376/***/ } ) ,
360- /* 10 */
377+ /* 11 */
361378/***/ ( function ( module , exports ) {
362379
363380module . exports = {
0 commit comments