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-plugin-gatsby-cloud): emit file nodes after source updates #33548

Merged
merged 2 commits into from
Oct 18, 2021

Conversation

pieh
Copy link
Contributor

@pieh pieh commented Oct 15, 2021

Description

This moves emitting file nodes earlier and also fixes incremental builds not emitting updates.

Related Issues

[ch39979]

Co-authored-by: Vladimir Razuvaev <vladimir.razuvaev@gmail.com>
@gatsbot gatsbot bot added the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Oct 15, 2021
@@ -113,6 +113,7 @@ exports.onPostBuild = async (
}

await Promise.all([
maybeFileNodesEmittedPromise,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's here so we actually wait on it somewhere to make sure we don't "finish the build" before ipc messages were actually sent.

Copy link
Contributor

@wardpeet wardpeet Oct 15, 2021

Choose a reason for hiding this comment

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

Question here, couldn't this have a race condition? What if the promise your listening to isn't the last one? Shouldn't we ad a global promise over the for each? that resolves when the whole foreach is done?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This part need to change. This is not promise anymore (since we do maybeFileNodesEmittedPromise = await X below.

I think instead we should create single promise in API_FINISHED handler and only resolve it after each file was emitted (and awaited on) - then this check that should make sure that we don't exit before this is done would be actually correct?

Comment on lines 165 to 166
exports.onPreBootstrap = ({ emitter, getNodesByType }) => {
emitter.on(`API_FINISHED`, async action => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

onPreBuild in incremental updates is triggered before data update is applied, so that isn't an option (changing incremental updates so onPreBuild happen after data update is ... not straightforward, due to constant polling wether it should sourceNodes again we never know when would be "finalsourceNodes to triggeronPreBuild` then).

onPostBuild, while it would work, would be way too late - we do want to start file related work ASAP.

Hence adding this hacky "After sourceNodes" lifecycle (maybe it should be actual life cycle, I didn't want to create new one just for this purpose right now).

Comment on lines 175 to 177
maybeFileNodesEmittedPromise = await emitFileNodes({
path: file.absolutePath,
})
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't we remove the await here?

Copy link
Contributor

Choose a reason for hiding this comment

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

await here is necessary for IPC backpressure. emitFileNodes will return true in most cases (in this case await will be a no-op) or promise when Node reports us that IPC needs back-pressure.

Copy link
Contributor

Choose a reason for hiding this comment

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

okay, thought the queue was done all by emitFileNodes

Copy link
Contributor

@vladar vladar Oct 15, 2021

Choose a reason for hiding this comment

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

A queue is done by the Node itself, it lets us know when it is ready to resume sending IPCs via the callback (which we translate to a promise under the hood).

@vladar vladar removed the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Oct 15, 2021
@pieh pieh merged commit 5110074 into master Oct 18, 2021
@pieh pieh deleted the fix/cloud-file-nodes-inc-builds branch October 18, 2021 08:49
wardpeet pushed a commit that referenced this pull request Oct 18, 2021
…#33548)

* fix(gatsby-plugin-gatsby-cloud): emit file nodes after source updates

Co-authored-by: Vladimir Razuvaev <vladimir.razuvaev@gmail.com>

* promise awaited on in onPostBuild should resolve after all file nodes were emitted

Co-authored-by: Vladimir Razuvaev <vladimir.razuvaev@gmail.com>
wardpeet pushed a commit to herecydev/gatsby that referenced this pull request Oct 29, 2021
…gatsbyjs#33548)

* fix(gatsby-plugin-gatsby-cloud): emit file nodes after source updates

Co-authored-by: Vladimir Razuvaev <vladimir.razuvaev@gmail.com>

* promise awaited on in onPostBuild should resolve after all file nodes were emitted

Co-authored-by: Vladimir Razuvaev <vladimir.razuvaev@gmail.com>
axe312ger pushed a commit that referenced this pull request Nov 9, 2021
…#33548)

* fix(gatsby-plugin-gatsby-cloud): emit file nodes after source updates

Co-authored-by: Vladimir Razuvaev <vladimir.razuvaev@gmail.com>

* promise awaited on in onPostBuild should resolve after all file nodes were emitted

Co-authored-by: Vladimir Razuvaev <vladimir.razuvaev@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants