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: check for dirty pages when nodes are deleted (so queries are ru-run and data is removed from pages) #11831

Merged
merged 11 commits into from Feb 20, 2019
3 changes: 2 additions & 1 deletion packages/gatsby/src/bootstrap/page-hot-reloader.js
Expand Up @@ -16,6 +16,7 @@ emitter.on(`CREATE_NODE`, action => {
emitter.on(`DELETE_NODE`, action => {
if (action.payload.internal.type !== `SitePage`) {
pagesDirty = true
apiRunnerNode(`FAKE_API_CALL`)
}
})

Expand Down Expand Up @@ -45,7 +46,7 @@ const runCreatePages = async () => {
})
.map(p => p.id)

const timestamp = new Date().toJSON()
const timestamp = Date.now()
Copy link
Contributor

Choose a reason for hiding this comment

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

new Date().toJSON() => "2019-02-20T10:47:41.468Z"
Date.now() => 1550659670910

I don't know how page.updatedAt looks so no idea if this is good or bad 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah... for some reason I made a few types (like page) use unix timestamps instead of iso8601 :-(

So this check was failing before.


await apiRunnerNode(`createPages`, {
graphql,
Expand Down
Expand Up @@ -93,6 +93,15 @@ exports.runQueuedActions = runQueuedActions
emitter.on(`API_RUNNING_QUEUE_EMPTY`, runQueuedActions)

let seenIdsWithoutDataDependencies = []

// Remove pages from seenIdsWithoutDataDependencies when they're deleted
// so their query will be run again if they're created again.
emitter.on(`DELETE_PAGE`, action => {
seenIdsWithoutDataDependencies = seenIdsWithoutDataDependencies.filter(
p => p !== action.payload.path
)
})

const findIdsWithoutDataDependencies = () => {
const state = store.getState()
const allTrackedIds = _.uniq(
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby/src/utils/api-runner-node.js
Expand Up @@ -157,7 +157,7 @@ module.exports = async (api, args = {}, pluginSource) =>
})

// Check that the API is documented.
if (!apiList[api]) {
if (!apiList[api] && api !== `FAKE_API_CALL`) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I can't see FAKE_API_CALL if you could point me in the right direction that would be awesome

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh lemme add a comment on this. It's a bit weird :-D

Copy link
Contributor

Choose a reason for hiding this comment

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

reporter.panic(`api: "${api}" is not a valid Gatsby api`)
}

Expand Down