docs(gatsby-source-filesystem): add warning about parentNodeId
for util functions like createFileNodeFromBuffer
#34313
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
We wanted to implement a social card that is generated on the fly for our pages.
createFileNodeFromBuffer
was our obvious choice. We followed the playbook given by Gatsby, here the relevant docs:createRemoteFileNode
&createFileNodeFromBuffer
are defined.Steps:
createFileNodeFromBuffer
createNodeField
createSchemaCustomization
&@link
Everything worked, but only on the first start. Repeated starts showed the file being null. Clearly something was going on when loaded from cache. We studied the documentation and searched for examples on github through the code search. We didn't found obvious solutions only a few issues describing similar issues in other contexts.
When I compared the two function's parameter signature I noted a small difference that technically did not make a difference but semantically. Inside
createFileNodeFromBuffer
parentNodeId
receives a default value ofnull
and that value is not mentioned in the documentation.On the other hand the documentation for createRemoteFileNode mentions that value and the source code shows now default
null
assignment forparentNodeId
.When I thought about the cache and dangling file nodes I guessed this is the problem and in the end this was exactly the issue. @KyleAMathews himself created an issue (#11942) almost 3 years ago to handle this problem but it was closed by the stale bot and forgotten I guess? The related PR which introduced the
parentNodeId
and where Kyle commented the problem can be found here #11795 (comment).Documentation
This PR brings the necessary changes in the documentation and I chose to print a warning for
createFileNodeFromBuffer
&createRemoteFileNode
which reads like this forcreateFileNodeFromBuffer
:The documentation was adapted for the following parts:
parentNodeId
issues.createFileNodeFromBuffer
. Right now it's some outdated example picked from https://github.com/malcolm-kee/gatsby-source-mysql. It's outdated, because it's not using theparentNodeId
while the current sources do use them and switched tocreateRemoteFileNode
anyway in the meantime. I chose to extract the important bits from our working social image generation which is a much more simpler example that might be relevant to other folks in addition.Note: I copied and adapted large positions from Kyle's feedback to this issue but I had no idea to give proper credit, so I'm doing it here instead. Thanks.
Remarks
I actually would like to make
parentNodeId
a mandatory field and throw an exception like it's done for other inputs. That would be a breaking change I fear so I chose to only warn about the issue. Does some maintainer have an opinion on this?Preview
The rendered documentation files change in those aspects. Red highlights only to highlight the screenshots.
Warning for
createFileNodeFromBuffer
Warning for
createRemoteFileNode
Updated Example
Troubleshooting Addition
Related Issues