@@ -128,9 +128,6 @@ return /******/ (function(modules) { // webpackBootstrap
128
128
var renderSubtreeIntoContainer = _reactDom2 . default . unstable_renderSubtreeIntoContainer ;
129
129
130
130
var SafeHTMLElement = EE . canUseDOM ? window . HTMLElement : { } ;
131
- var AppElement = EE . canUseDOM ? document . body : {
132
- appendChild : function appendChild ( ) { }
133
- } ;
134
131
135
132
function getParentElement ( parentSelector ) {
136
133
return parentSelector ( ) ;
@@ -249,7 +246,7 @@ return /******/ (function(modules) { // webpackBootstrap
249
246
} ] , [ {
250
247
key : 'setAppElement' ,
251
248
value : function setAppElement ( element ) {
252
- ariaAppHider . setElement ( element || AppElement ) ;
249
+ ariaAppHider . setElement ( element ) ;
253
250
}
254
251
255
252
/* eslint-disable no-console */
@@ -1809,27 +1806,46 @@ return /******/ (function(modules) { // webpackBootstrap
1809
1806
Object . defineProperty ( exports , "__esModule" , {
1810
1807
value : true
1811
1808
} ) ;
1809
+ exports . assertNodeList = assertNodeList ;
1812
1810
exports . setElement = setElement ;
1811
+ exports . tryForceFallback = tryForceFallback ;
1813
1812
exports . validateElement = validateElement ;
1814
1813
exports . hide = hide ;
1815
1814
exports . show = show ;
1816
1815
exports . toggle = toggle ;
1816
+ exports . documentNotReadyOrSSRTesting = documentNotReadyOrSSRTesting ;
1817
1817
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
+ }
1819
1825
1820
1826
function setElement ( element ) {
1821
1827
var useElement = element ;
1822
1828
if ( typeof useElement === 'string' ) {
1823
1829
var el = document . querySelectorAll ( useElement ) ;
1830
+ assertNodeList ( el , useElement ) ;
1824
1831
useElement = 'length' in el ? el [ 0 ] : el ;
1825
1832
}
1826
1833
globalElement = useElement || globalElement ;
1827
1834
return globalElement ;
1828
1835
}
1829
1836
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
+
1830
1846
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' ] ) ;
1833
1849
}
1834
1850
}
1835
1851
@@ -1848,6 +1864,10 @@ return /******/ (function(modules) { // webpackBootstrap
1848
1864
apply ( appElement ) ;
1849
1865
}
1850
1866
1867
+ function documentNotReadyOrSSRTesting ( ) {
1868
+ globalElement = null ;
1869
+ }
1870
+
1851
1871
function resetForTesting ( ) {
1852
1872
globalElement = document . body ;
1853
1873
}
0 commit comments