@@ -128,9 +128,6 @@ return /******/ (function(modules) { // webpackBootstrap
128128 var renderSubtreeIntoContainer = _reactDom2 . default . unstable_renderSubtreeIntoContainer ;
129129
130130 var SafeHTMLElement = EE . canUseDOM ? window . HTMLElement : { } ;
131- var AppElement = EE . canUseDOM ? document . body : {
132- appendChild : function appendChild ( ) { }
133- } ;
134131
135132 function getParentElement ( parentSelector ) {
136133 return parentSelector ( ) ;
@@ -249,7 +246,7 @@ return /******/ (function(modules) { // webpackBootstrap
249246 } ] , [ {
250247 key : 'setAppElement' ,
251248 value : function setAppElement ( element ) {
252- ariaAppHider . setElement ( element || AppElement ) ;
249+ ariaAppHider . setElement ( element ) ;
253250 }
254251
255252 /* eslint-disable no-console */
@@ -1809,27 +1806,46 @@ return /******/ (function(modules) { // webpackBootstrap
18091806 Object . defineProperty ( exports , "__esModule" , {
18101807 value : true
18111808 } ) ;
1809+ exports . assertNodeList = assertNodeList ;
18121810 exports . setElement = setElement ;
1811+ exports . tryForceFallback = tryForceFallback ;
18131812 exports . validateElement = validateElement ;
18141813 exports . hide = hide ;
18151814 exports . show = show ;
18161815 exports . toggle = toggle ;
1816+ exports . documentNotReadyOrSSRTesting = documentNotReadyOrSSRTesting ;
18171817 exports . resetForTesting = resetForTesting ;
1818- var globalElement = typeof document !== 'undefined' ? document . body : null ;
1818+ var globalElement = null ;
1819+
1820+ function assertNodeList ( nodeList , selector ) {
1821+ if ( ! nodeList || ! nodeList . length ) {
1822+ throw new Error ( 'react-modal: No elements were found for selector ' + selector + '.' ) ;
1823+ }
1824+ }
18191825
18201826 function setElement ( element ) {
18211827 var useElement = element ;
18221828 if ( typeof useElement === 'string' ) {
18231829 var el = document . querySelectorAll ( useElement ) ;
1830+ assertNodeList ( el , useElement ) ;
18241831 useElement = 'length' in el ? el [ 0 ] : el ;
18251832 }
18261833 globalElement = useElement || globalElement ;
18271834 return globalElement ;
18281835 }
18291836
1837+ function tryForceFallback ( ) {
1838+ if ( document && document . body ) {
1839+ // force fallback to document.body
1840+ setElement ( document . body ) ;
1841+ return true ;
1842+ }
1843+ return false ;
1844+ }
1845+
18301846 function validateElement ( appElement ) {
1831- if ( ! appElement && ! globalElement ) {
1832- throw new Error ( [ 'react-modal: You must set an element with ' , '`Modal.setAppElement(el)` to make this accessible' ] ) ;
1847+ if ( ! appElement && ! globalElement && ! tryForceFallback ( ) ) {
1848+ throw new Error ( [ 'react-modal: Cannot fallback to `document.body`, because it\'s not ready or available.' , 'If you are doing server-side rendering, use this function to defined an element. ', '`Modal.setAppElement(el)` to make this accessible' ] ) ;
18331849 }
18341850 }
18351851
@@ -1848,6 +1864,10 @@ return /******/ (function(modules) { // webpackBootstrap
18481864 apply ( appElement ) ;
18491865 }
18501866
1867+ function documentNotReadyOrSSRTesting ( ) {
1868+ globalElement = null ;
1869+ }
1870+
18511871 function resetForTesting ( ) {
18521872 globalElement = document . body ;
18531873 }
0 commit comments