Skip to content

Commit

Permalink
fix: replace isNode to isBrowser check
Browse files Browse the repository at this point in the history
  • Loading branch information
tbvjaos510 committed Aug 9, 2019
1 parent f91cc0e commit 426d49c
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 24 deletions.
1 change: 0 additions & 1 deletion package.json
Expand Up @@ -82,7 +82,6 @@
"dependencies": {
"@babel/runtime": "^7.3.1",
"crc-32": "^1.2.0",
"detect-node": "^2.0.3",
"prop-types": "15.6.2",
"scan-directory": "^1.0.0"
},
Expand Down
24 changes: 12 additions & 12 deletions src/Component.js
@@ -1,22 +1,22 @@
import React, {Component} from 'react';
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import isNode from 'detect-node';
import {useMark} from './marks';
import { useMark } from './marks';
import toLoadable from "./loadable";
import {UIDConsumer} from "./context";
import { UIDConsumer } from "./context";

const isBrowser = (typeof window !== 'undefined');
const STATE_LOADING = 'loading';
const STATE_ERROR = 'error';
const STATE_DONE = 'done';

const FragmentNode = ({children}) => <div>{children}</div>;
const FragmentNode = ({ children }) => <div>{children}</div>;
FragmentNode.propTypes = {
children: PropTypes.any
};

export const settings = {
hot: !!module.hot,
SSR: isNode
SSR: !isBrowser
};

const getLoadable = importFunction => {
Expand All @@ -38,7 +38,7 @@ export class UnconnectedReactImportedComponent extends Component {
loadable.load().catch(() => ({}));
this.state.mark = loadable.mark;

if (isNode && settings.SSR && typeof this.props.streamId !== 'undefined') {
if (!isBrowser && settings.SSR && typeof this.props.streamId !== 'undefined') {
useMark(this.props.streamId, loadable.mark);
if (this.state.state !== STATE_DONE) {
this.state.state = STATE_LOADING;
Expand Down Expand Up @@ -127,8 +127,8 @@ export class UnconnectedReactImportedComponent extends Component {
};

render() {
const {AsyncComponent, state} = this.state;
const {LoadingComponent, ErrorComponent} = this.props;
const { AsyncComponent, state } = this.state;
const { LoadingComponent, ErrorComponent } = this.props;

if (state === STATE_LOADING && this.props.async) {
throw this.loadingPromise;
Expand All @@ -139,7 +139,7 @@ export class UnconnectedReactImportedComponent extends Component {
}

if (AsyncComponent) {
return <AsyncComponent {...this.props.forwardProps} ref={this.props.forwardRef}/>
return <AsyncComponent {...this.props.forwardProps} ref={this.props.forwardRef} />
}

switch (state) {
Expand Down Expand Up @@ -194,8 +194,8 @@ UnconnectedReactImportedComponent.defaultProps = {

const ReactImportedComponent = (props) => (
settings.SSR
? <UIDConsumer>{UID => <UnconnectedReactImportedComponent {...props} streamId={UID | 0}/>}</UIDConsumer>
: <UnconnectedReactImportedComponent {...props} streamId={0}/>
? <UIDConsumer>{UID => <UnconnectedReactImportedComponent {...props} streamId={UID | 0} />}</UIDConsumer>
: <UnconnectedReactImportedComponent {...props} streamId={0} />
);

ReactImportedComponent.propTypes = BaseProps;
Expand Down
6 changes: 3 additions & 3 deletions src/LazyBoundary.js
@@ -1,10 +1,10 @@
import React from 'react';
import PropTypes from 'prop-types';
import isNode from 'detect-node';
const isBrowser = (typeof window !== 'undefined');

const LazyBoundary = ({children}) => <React.Fragment>{children}</React.Fragment>;
const LazyBoundary = ({ children }) => <React.Fragment>{children}</React.Fragment>;
LazyBoundary.propTypes = {
children: PropTypes.node,
};

export default isNode ? LazyBoundary : React.Suspense;
export default !isBrowser ? LazyBoundary : React.Suspense;
6 changes: 3 additions & 3 deletions src/loadable.js
@@ -1,5 +1,5 @@
import isNode from 'detect-node';
import {loadMark} from './marks';
import { loadMark } from './marks';
const isBrowser = (typeof window !== 'undefined');

let pending = [];

Expand Down Expand Up @@ -66,7 +66,7 @@ const toLoadable = (importFunction, autoImport = true) => {
mark.forEach(subMark => loadMark(subMark, loadable))
}

if (isNode && autoImport) {
if (!isBrowser && autoImport) {
loadable.load();
}
return loadable;
Expand Down
5 changes: 0 additions & 5 deletions yarn.lock
Expand Up @@ -2635,11 +2635,6 @@ detect-libc@^1.0.2:
resolved "https://registry.yarnpkg.com/detect-libc/-/detect-libc-1.0.3.tgz#fa137c4bd698edf55cd5cd02ac559f91a4c4ba9b"
integrity sha1-+hN8S9aY7fVc1c0CrFWfkaTEups=

detect-node@^2.0.3:
version "2.0.3"
resolved "https://registry.yarnpkg.com/detect-node/-/detect-node-2.0.3.tgz#a2033c09cc8e158d37748fbde7507832bd6ce127"
integrity sha1-ogM8CcyOFY03dI+951B4Mr1s4Sc=

diff@3.5.0, diff@^3.5.0:
version "3.5.0"
resolved "https://registry.yarnpkg.com/diff/-/diff-3.5.0.tgz#800c0dd1e0a8bfbc95835c202ad220fe317e5a12"
Expand Down

0 comments on commit 426d49c

Please sign in to comment.