1- import React , { Component } from 'react' ;
1+ import React , { Component } from 'react' ;
22import PropTypes from 'prop-types' ;
3- import isNode from 'detect-node' ;
4- import { useMark } from './marks' ;
3+ import { useMark } from './marks' ;
54import toLoadable from "./loadable" ;
6- import { UIDConsumer } from "./context" ;
5+ import { UIDConsumer } from "./context" ;
76
7+ const isBrowser = ( typeof window !== 'undefined' ) ;
88const STATE_LOADING = 'loading' ;
99const STATE_ERROR = 'error' ;
1010const STATE_DONE = 'done' ;
1111
12- const FragmentNode = ( { children} ) => < div > { children } </ div > ;
12+ const FragmentNode = ( { children } ) => < div > { children } </ div > ;
1313FragmentNode . propTypes = {
1414 children : PropTypes . any
1515} ;
1616
1717export const settings = {
1818 hot : ! ! module . hot ,
19- SSR : isNode
19+ SSR : ! isBrowser
2020} ;
2121
2222const getLoadable = importFunction => {
@@ -38,7 +38,7 @@ export class UnconnectedReactImportedComponent extends Component {
3838 loadable . load ( ) . catch ( ( ) => ( { } ) ) ;
3939 this . state . mark = loadable . mark ;
4040
41- if ( isNode && settings . SSR && typeof this . props . streamId !== 'undefined' ) {
41+ if ( ! isBrowser && settings . SSR && typeof this . props . streamId !== 'undefined' ) {
4242 useMark ( this . props . streamId , loadable . mark ) ;
4343 if ( this . state . state !== STATE_DONE ) {
4444 this . state . state = STATE_LOADING ;
@@ -127,8 +127,8 @@ export class UnconnectedReactImportedComponent extends Component {
127127 } ;
128128
129129 render ( ) {
130- const { AsyncComponent, state} = this . state ;
131- const { LoadingComponent, ErrorComponent} = this . props ;
130+ const { AsyncComponent, state } = this . state ;
131+ const { LoadingComponent, ErrorComponent } = this . props ;
132132
133133 if ( state === STATE_LOADING && this . props . async ) {
134134 throw this . loadingPromise ;
@@ -139,7 +139,7 @@ export class UnconnectedReactImportedComponent extends Component {
139139 }
140140
141141 if ( AsyncComponent ) {
142- return < AsyncComponent { ...this . props . forwardProps } ref = { this . props . forwardRef } />
142+ return < AsyncComponent { ...this . props . forwardProps } ref = { this . props . forwardRef } />
143143 }
144144
145145 switch ( state ) {
@@ -194,8 +194,8 @@ UnconnectedReactImportedComponent.defaultProps = {
194194
195195const ReactImportedComponent = ( props ) => (
196196 settings . SSR
197- ? < UIDConsumer > { UID => < UnconnectedReactImportedComponent { ...props } streamId = { UID | 0 } /> } </ UIDConsumer >
198- : < UnconnectedReactImportedComponent { ...props } streamId = { 0 } />
197+ ? < UIDConsumer > { UID => < UnconnectedReactImportedComponent { ...props } streamId = { UID | 0 } /> } </ UIDConsumer >
198+ : < UnconnectedReactImportedComponent { ...props } streamId = { 0 } />
199199) ;
200200
201201ReactImportedComponent . propTypes = BaseProps ;
0 commit comments