Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(gatsby): leak less in chokidar listeners #27685

Merged
merged 2 commits into from
Oct 27, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ const createPageId = path => `SitePage ${path}`

exports.sourceNodes = ({ createContentDigest, actions, store }) => {
const { createNode } = actions
const state = store.getState()
const { program } = state
const { flattenedPlugins } = state
const { program, flattenedPlugins, config } = store.getState()

// Add our default development page since we know it's going to
// exist and we need a node to exist so its query works :-)
Expand Down Expand Up @@ -87,8 +85,8 @@ exports.sourceNodes = ({ createContentDigest, actions, store }) => {
siteMetadata: {
...configCopy.siteMetadata,
},
port: state.program.proxyPort,
host: state.program.host,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we retain the state

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, we could call store.getState() here, but because program can't change this is fine (program does get retained in memory either way)

port: program.proxyPort,
host: program.host,
...configCopy,
}
createNode({
Expand All @@ -103,7 +101,7 @@ exports.sourceNodes = ({ createContentDigest, actions, store }) => {
})
}

createGatsbyConfigNode(state.config)
createGatsbyConfigNode(config)

const buildTime = moment()
.subtract(process.uptime(), `seconds`)
Expand All @@ -127,6 +125,10 @@ exports.sourceNodes = ({ createContentDigest, actions, store }) => {
program.directory,
`gatsby-config.js`
)
watchConfig(pathToGatsbyConfig, createGatsbyConfigNode)
}

function watchConfig(pathToGatsbyConfig, createGatsbyConfigNode) {
chokidar.watch(pathToGatsbyConfig).on(`change`, () => {
const oldCache = require.cache[require.resolve(pathToGatsbyConfig)]
try {
Expand Down