Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(www): revert amend pass context code snippet (#12084)
Reverts #12012 as it's actually not needed. As per Slack discussion with @sidharthachatterjee
- Loading branch information
52cb180
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey, @LekoArts and @DSchau, why is
...page.context
not needed? Willcontext: { house: Gryffindor }
on its own not overwrite thecontext
field? Will the previous spread of...page
merge the old and newcontext
objects?I actually proposed #12012 because I run into that problem when using the snippet on a project and I think
...page.context
was the solution (I can fish out the details if that'd be helpful)Unrelated but now that I'm at it: shouldn't
Gryffindor
be quoted for the snippet to work? It's seems the snippet intended that to be a string literal.52cb180
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no previous context :) Using the createPage function it’s the first time you pass context to that page.
Yeah, it should be in quotes. Mind opening a PR?
52cb180
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if a different plugin is adding something to context? I think I ran into this problem on a site that was using gatsby-mdx. I've checked that codebase right now and I found they're merging frontmatter into context. Interesting 🤔 , what do you think?
I understand the docs snippet should be as simple as possible so as not to confuse people, but if this overwriting scenario is a possibility, it could create some confusion and frustration for noobs like me that aren't aware that they're overwriting.
Will do! 👍
52cb180
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gatsby-mdx doesn't overwrite your context values as it uses lodash's merge. It only adds
frontmatter
to the context with the contents of the frontmatter (due to the spread operator) :)52cb180
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My point is that I was overwriting what gatsby-mdx had placed in context by using this code snippet from the docs. I was loosing frontmatter. It took me a while to figure out and was a bit confused and frustrated at the time. That's why I suggested #12012.
It seems safer to merge the previous context with the new one (using lodash's merge or spreading the old context into the new one) than to assume that context is empty.
Just my two cents, by the way, not trying to antagonize 🙂