Skip to content

Commit 3005954

Browse files
authored
Revert json-stream-stringify to serialize redux state (#9896)
current implementation of using `json-stream-stringify` is causing a lot of problems and I think this should be reverted - see #9370 (comment) shortly put - this does help with not getting OOM, but it essentially make `.cache/redux-state.json` to not work at all
1 parent 3fe6287 commit 3005954

File tree

3 files changed

+15
-21
lines changed

3 files changed

+15
-21
lines changed

packages/gatsby/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
"jest-worker": "^23.2.0",
7676
"joi": "12.x.x",
7777
"json-loader": "^0.5.7",
78-
"json-stream-stringify": "^2.0.1",
78+
"json-stringify-safe": "^5.0.1",
7979
"kebab-hash": "^0.1.2",
8080
"lodash": "^4.17.10",
8181
"md5": "^2.2.1",

packages/gatsby/src/redux/index.js

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const Redux = require(`redux`)
22
const _ = require(`lodash`)
33
const fs = require(`fs`)
44
const mitt = require(`mitt`)
5-
const stringify = require(`json-stream-stringify`)
5+
const stringify = require(`json-stringify-safe`)
66

77
// Create event emitter for actions
88
const emitter = mitt()
@@ -78,21 +78,12 @@ const saveState = state => {
7878
)
7979
pickedState.components = mapToObject(pickedState.components)
8080
pickedState.nodes = mapToObject(pickedState.nodes)
81-
82-
const writeStream = fs.createWriteStream(
83-
`${process.cwd()}/.cache/redux-state.json`
81+
const stringified = stringify(pickedState, null, 2)
82+
fs.writeFile(
83+
`${process.cwd()}/.cache/redux-state.json`,
84+
stringified,
85+
() => {}
8486
)
85-
86-
new stringify(pickedState, null, 2, true)
87-
.pipe(writeStream)
88-
.on(`finish`, () => {
89-
writeStream.destroy()
90-
writeStream.end()
91-
})
92-
.on(`error`, () => {
93-
writeStream.destroy()
94-
writeStream.end()
95-
})
9687
}
9788
const saveStateDebounced = _.debounce(saveState, 1000)
9889

yarn.lock

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2965,6 +2965,14 @@ babel-plugin-macros@^2.4.2:
29652965
cosmiconfig "^5.0.5"
29662966
resolve "^1.8.1"
29672967

2968+
babel-plugin-macros@^2.4.2:
2969+
version "2.4.2"
2970+
resolved "https://registry.yarnpkg.com/babel-plugin-macros/-/babel-plugin-macros-2.4.2.tgz#21b1a2e82e2130403c5ff785cba6548e9b644b28"
2971+
integrity sha512-NBVpEWN4OQ/bHnu1fyDaAaTPAjnhXCEPqr1RwqxrU7b6tZ2hypp+zX4hlNfmVGfClD5c3Sl6Hfj5TJNF5VG5aA==
2972+
dependencies:
2973+
cosmiconfig "^5.0.5"
2974+
resolve "^1.8.1"
2975+
29682976
babel-plugin-react-css-modules@^3.2.1:
29692977
version "3.4.2"
29702978
resolved "https://registry.yarnpkg.com/babel-plugin-react-css-modules/-/babel-plugin-react-css-modules-3.4.2.tgz#4c1db8d4bc8b2973f6c689da7dbd56b0cb8f099c"
@@ -11502,11 +11510,6 @@ json-stable-stringify@^1.0.0:
1150211510
dependencies:
1150311511
jsonify "~0.0.0"
1150411512

11505-
json-stream-stringify@^2.0.1:
11506-
version "2.0.1"
11507-
resolved "https://registry.yarnpkg.com/json-stream-stringify/-/json-stream-stringify-2.0.1.tgz#8bc0e65ff94567d9010e14c27c043a951cb14939"
11508-
integrity sha512-5XymtJXPmzRWZ1UdLQQQXbjHV/E7NAanSClikEqORbkZKOYLSYLNHqRuooyju9W90kJUzknFhX2xvWn4cHluHQ==
11509-
1151011513
json-stringify-safe@^5.0.1, json-stringify-safe@~5.0.1:
1151111514
version "5.0.1"
1151211515
resolved "https://registry.yarnpkg.com/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz#1296a2d58fd45f19a0f6ce01d65701e2c735b6eb"

0 commit comments

Comments
 (0)