Skip to content

Commit 426d49c

Browse files
committed
fix: replace isNode to isBrowser check
1 parent f91cc0e commit 426d49c

File tree

5 files changed

+18
-24
lines changed

5 files changed

+18
-24
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@
8282
"dependencies": {
8383
"@babel/runtime": "^7.3.1",
8484
"crc-32": "^1.2.0",
85-
"detect-node": "^2.0.3",
8685
"prop-types": "15.6.2",
8786
"scan-directory": "^1.0.0"
8887
},

src/Component.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
import React, {Component} from 'react';
1+
import React, { Component } from 'react';
22
import PropTypes from 'prop-types';
3-
import isNode from 'detect-node';
4-
import {useMark} from './marks';
3+
import { useMark } from './marks';
54
import toLoadable from "./loadable";
6-
import {UIDConsumer} from "./context";
5+
import { UIDConsumer } from "./context";
76

7+
const isBrowser = (typeof window !== 'undefined');
88
const STATE_LOADING = 'loading';
99
const STATE_ERROR = 'error';
1010
const STATE_DONE = 'done';
1111

12-
const FragmentNode = ({children}) => <div>{children}</div>;
12+
const FragmentNode = ({ children }) => <div>{children}</div>;
1313
FragmentNode.propTypes = {
1414
children: PropTypes.any
1515
};
1616

1717
export const settings = {
1818
hot: !!module.hot,
19-
SSR: isNode
19+
SSR: !isBrowser
2020
};
2121

2222
const 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

195195
const 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

201201
ReactImportedComponent.propTypes = BaseProps;

src/LazyBoundary.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
3-
import isNode from 'detect-node';
3+
const isBrowser = (typeof window !== 'undefined');
44

5-
const LazyBoundary = ({children}) => <React.Fragment>{children}</React.Fragment>;
5+
const LazyBoundary = ({ children }) => <React.Fragment>{children}</React.Fragment>;
66
LazyBoundary.propTypes = {
77
children: PropTypes.node,
88
};
99

10-
export default isNode ? LazyBoundary : React.Suspense;
10+
export default !isBrowser ? LazyBoundary : React.Suspense;

src/loadable.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import isNode from 'detect-node';
2-
import {loadMark} from './marks';
1+
import { loadMark } from './marks';
2+
const isBrowser = (typeof window !== 'undefined');
33

44
let pending = [];
55

@@ -66,7 +66,7 @@ const toLoadable = (importFunction, autoImport = true) => {
6666
mark.forEach(subMark => loadMark(subMark, loadable))
6767
}
6868

69-
if (isNode && autoImport) {
69+
if (!isBrowser && autoImport) {
7070
loadable.load();
7171
}
7272
return loadable;

yarn.lock

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2635,11 +2635,6 @@ detect-libc@^1.0.2:
26352635
resolved "https://registry.yarnpkg.com/detect-libc/-/detect-libc-1.0.3.tgz#fa137c4bd698edf55cd5cd02ac559f91a4c4ba9b"
26362636
integrity sha1-+hN8S9aY7fVc1c0CrFWfkaTEups=
26372637

2638-
detect-node@^2.0.3:
2639-
version "2.0.3"
2640-
resolved "https://registry.yarnpkg.com/detect-node/-/detect-node-2.0.3.tgz#a2033c09cc8e158d37748fbde7507832bd6ce127"
2641-
integrity sha1-ogM8CcyOFY03dI+951B4Mr1s4Sc=
2642-
26432638
diff@3.5.0, diff@^3.5.0:
26442639
version "3.5.0"
26452640
resolved "https://registry.yarnpkg.com/diff/-/diff-3.5.0.tgz#800c0dd1e0a8bfbc95835c202ad220fe317e5a12"

0 commit comments

Comments
 (0)