Skip to content

Commit 3ca0478

Browse files
authored
Move remotedev server to npm script instead of always starting (#849)
Most people aren't going to use this so don't ship it to everyone. Also, more pressing, the remotedev server spits out a big error on startup right now which is very confusing.
1 parent ba62b14 commit 3ca0478

File tree

11 files changed

+669
-35
lines changed

11 files changed

+669
-35
lines changed

CONTRIBUTING.md

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,45 @@ The usual contributing steps are:
3535
* Commit and push to your fork.
3636
* Create an pull request from your branch.
3737

38-
This project uses [FlowType](https://flowtype.org/) for static type checking.
38+
## Development tools
39+
40+
### Redux devtools
41+
42+
Gatsby uses Redux for managing state during development and building. It's
43+
often helpful to see the flow of actions and builtup state for a site you're
44+
working on or if adding new functionality to core. We leverage
45+
https://github.com/zalmoxisus/remote-redux-devtools and
46+
https://github.com/zalmoxisus/remotedev-server to give you use the Redux
47+
devtools extension for debugging Gatsby.
48+
49+
To use this, first install
50+
[redux-devtools-extension](https://github.com/zalmoxisus/redux-devtools-extension)
51+
in your browser. Then in your Gatsby repo, run `npm run remotedev`. Then
52+
in your site directory run `gatsby develop`.
53+
54+
At this point, your site will be sending Redux actions and state to the remote server.
55+
56+
To connect to this, you need to setup the devtools extension to talk to the remote
57+
server.
58+
59+
First open the remote devtools.
60+
61+
![how to open the redux remote devtools extension](./images/open-remote-dev-tools.png)
62+
63+
Then click settings along the bottom menu and set the host and port.
64+
65+
![how to set the host/port for the remote devtools extension to connect to Gatsby](./images/remote-dev-settings.png)
66+
67+
After this, the devtools extension *should* connect to the remote server and you'll
68+
see actions start showing up.
69+
70+
![gatsby redux remote devtools](./images/running-redux-devtools.png)
71+
72+
**Warning!! Lots of buginess**. While having this available is extreamly
73+
helpful, this setup is very buggy and fragile. There is a memory leak in the
74+
extension that's triggered it seems every time you restart the Gatsby
75+
development server. Also the extension often, for no apparent reason, just
76+
won't show any actions from the remote server. It'll also often freeze up. The
77+
best solution seems to just be turning everything off and on again. Fixing up
78+
these tools would be very helpful for us and many others using these tools if
79+
someone wants to take this on!
117 KB
Loading
104 KB
Loading
268 KB
Loading

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"lerna": "^2.0.0-rc.3",
3232
"prettier": "^1.2.2",
3333
"purdy": "^2.2.1",
34+
"remotedev-server": "^0.2.2",
3435
"rimraf": "^2.6.1"
3536
},
3637
"jest": {
@@ -61,6 +62,7 @@
6162
"format": "npm run format-packages && npm run format-gatsby && npm run format-www && npm run format-examples",
6263
"publish-canary": "lerna run build; lerna publish --canary --yes",
6364
"publish-next": "lerna run build; lerna publish --npm-tag=next",
65+
"remotedev": "remotedev --hostname=localhost --port=19999",
6466
"test": "jest",
6567
"test:watch": "jest --watch",
6668
"test_bkup": "npm run lint && npm run test-node && npm run test-integration",

packages/gatsby/lib/redux/index.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@ try {
1717
// ignore errors.
1818
}
1919

20+
const sitePackageJSON = require(`${process.cwd()}/package.json`)
2021
const composeEnhancers = composeWithDevTools({
2122
realtime: true,
2223
port: 19999,
23-
name: `gatsby-redux`,
24+
name: sitePackageJSON.name,
2425
})
2526

2627
let store
@@ -67,7 +68,11 @@ const getNode = id => {
6768
exports.getNode = getNode
6869
exports.hasNodeChanged = (id, digest) => {
6970
const node = store.getState().nodes[id]
70-
return node.contentDigest !== digest
71+
if (!node) {
72+
return true
73+
} else {
74+
return node.contentDigest !== digest
75+
}
7176
}
7277

7378
exports.loadNodeContent = node => {

packages/gatsby/lib/utils/develop.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,8 @@ const ReactDOMServer = require("react-dom/server")
1111
const rl = require("readline")
1212
const parsePath = require("parse-filepath")
1313
const _ = require("lodash")
14-
const remotedev = require("remotedev-server")
1514
const { store } = require("../redux")
1615

17-
// Start the dev server for Redux.
18-
remotedev({ hostname: "localhost", port: 19999 })
19-
2016
const rlInterface = rl.createInterface({
2117
input: process.stdin,
2218
output: process.stdout,

packages/gatsby/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@
100100
"remark-html": "^5.0.1",
101101
"remark-parse": "^2.2.0",
102102
"remote-redux-devtools": "^0.5.7",
103-
"remotedev-server": "^0.3.0-beta-3",
104103
"sanitize-html": "^1.13.0",
105104
"sift": "^3.2.6",
106105
"slash": "^1.0.0",

packages/graphql-skip-limit/src/connection/arrayconnection.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
/* @flow */
22

3-
import type { Connection, ConnectionArguments, Edge } from "./connectiontypes"
3+
import type {
4+
Connection,
5+
ConnectionArguments,
6+
} from './connectiontypes'
47

58
/**
69
* A simple function that accepts an array and connection arguments, and returns
710
* a connection object for use in GraphQL. It uses array offsets as pagination,
811
* so pagination will only work if the array is static.
912
*/
10-
export function connectionFromArray<T>(
13+
export function connectionFromArray<T> (
1114
data: Array<T>,
1215
args: ConnectionArguments
1316
): Connection<T> {
@@ -27,11 +30,11 @@ export function connectionFromArray<T>(
2730
throw new Error(`Argument "limit" must be a non-negative integer`)
2831
}
2932

30-
endSlice = startSlice + limit
33+
endSlice = (startSlice + limit)
3134
}
3235

3336
const slice = data.slice(startSlice, endSlice)
34-
const edges = slice.map((value: any, index: number) => {
37+
const edges = slice.map((value, index) => {
3538
const orgIndex = startSlice + index
3639
let next
3740
let previous
@@ -48,12 +51,12 @@ export function connectionFromArray<T>(
4851
}
4952
})
5053

54+
5155
return {
5256
edges,
5357
pageInfo: {
54-
hasNextPage: typeof limit === `number`
55-
? limit + startSlice - 1 < data.length
56-
: false,
58+
hasNextPage:
59+
typeof limit === `number` ? (limit + startSlice) - 1 < data.length : false,
5760
},
5861
}
5962
}
@@ -62,7 +65,7 @@ export function connectionFromArray<T>(
6265
* A version of `connectionFromArray` that takes a promised array, and returns a
6366
* promised connection.
6467
*/
65-
export function connectionFromPromisedArray<T>(
68+
export function connectionFromPromisedArray<T> (
6669
dataPromise: Promise<Array<T>>,
6770
args: ConnectionArguments
6871
): Promise<Connection<T>> {

packages/graphql-skip-limit/src/connection/connectiontypes.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,30 @@
55
*/
66
export type PageInfo = {
77
hasPreviousPage: ?boolean,
8-
hasNextPage: ?boolean,
8+
hasNextPage: ?boolean
99
};
1010

1111
/**
1212
* A flow type designed to be exposed as a `Connection` over GraphQL.
1313
*/
1414
export type Connection<T> = {
15-
edges: Array<Edge<T>>,
16-
pageInfo: PageInfo,
15+
edges: Array<Edge<T>>;
16+
pageInfo: PageInfo;
1717
};
1818

1919
/**
2020
* A flow type designed to be exposed as a `Edge` over GraphQL.
2121
*/
2222
export type Edge<T> = {
23-
node: T,
24-
next: T,
25-
previous: T,
23+
node: T;
24+
next: T;
25+
previous: T;
2626
};
2727

2828
/**
2929
* A flow type describing the arguments a connection field receives in GraphQL.
3030
*/
3131
export type ConnectionArguments = {
32-
skip?: ?number,
33-
limit?: ?number,
32+
skip?: ?number;
33+
limit?: ?number;
3434
};

0 commit comments

Comments
 (0)