-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
Create new page object when running dirty pages #1537
Create new page object when running dirty pages #1537
Conversation
Deploy preview failed. Built with commit 1955bfb https://app.netlify.com/sites/using-styled-components/deploys/5977e3b5a700c42160ddc90e |
Deploy preview ready! Built with commit 5e73963 |
Deploy preview ready! Built with commit 5e73963 |
Deploy preview ready! Built with commit 5e73963 |
Hmm so weird, we shouldn't be mutating the page data anywhere... thanks for the investigation! Can you see anywhere in query-runner.js where there might be a mutation? |
@KyleAMathews So I'm not sure if its the graphql library itself, but here's what I noticed: After the graphql call, |
Hmmm gotcha, very weird. Added this quick PR which could solve it. Want to get a release out tonight so will just roll with that. I appreciate that this PR solves the problem but it feels a bit blunt to me. I'd rather find the root cause and fix that. If #1553 doesn't change anything, let's keep investigating. |
Hey @KyleAMathews this PR does seem blunt to me as well but it might be a better band-aid than #1553. #1553 doesn't fix it because by the time it get's down to that line, the context was already mutated from the Also the spread operator won't deep clone nested objects within I also noticed changing that graphql line to |
Ok, good points. Yeah feel free to revert #1553 then. Won't have time to investigate this issue for the next week or so but would love a PR if you do identify the root cause. |
I may have some time a little later. Can we reopen this PR, I'll add on to it |
Found out its this extractFieldExamples method that is mutating things. Since it's only using So, I tried something for fun. If i default my |
As noted on the lodash docs, this method is mutative https://lodash.com/docs/\#mergeWith
726e4f3
to
57a1cc7
Compare
This reverts commit cb70f6c.
Ok so the problem is that |
Awesome! Nice debugging + fix! We'll want to use something that handles circular references though. Ran into that a few weeks ago on a client site and had to make core safe for that. Lodash's |
@KyleAMathews I'm not sure why but changing that line to use
|
Ah nvm I forgot to spread it. Pushed up the change. |
Deploy preview failed. Built with commit 1955bfb https://app.netlify.com/sites/image-processing/deploys/5977e3b4a700c42160ddc908 |
Deploy preview failed. Built with commit 1955bfb https://app.netlify.com/sites/using-remark/deploys/5977e3b5a700c42160ddc914 |
Deploy preview failed. Built with commit 1955bfb https://app.netlify.com/sites/using-jss/deploys/5977e3b6a700c42160ddc929 |
Deploy preview failed. Built with commit 1955bfb https://app.netlify.com/sites/using-contentful/deploys/5977e3b5a700c42160ddc911 |
Deploy preview failed. Built with commit 1955bfb https://app.netlify.com/sites/using-glamor/deploys/5977e3b4a700c42160ddc90b |
Deploy preview failed. Built with commit 1955bfb https://app.netlify.com/sites/using-postcss-sass/deploys/5977e3b4a700c42160ddc902 |
Thanks for the investigation and fix! This has probably been creating lots of weird bugs in other people's projects as well so great to get it cleaned up. |
So I ran into an issue a while ago related to object mutation within Gatsby. I don't remember exactly what it was other than it was related to
pageContext
. I was able to solve the previous problem by adding a coupleObject.assign()
calls withingatsby-node.js
.On my site, I create 2 different types of pages (using 2 different templates) within the
createPages
function using theallMarkdownRemark
query seen in the blog starter example. Within thecreatePage
action dispatcher call, I'm programmatically sending the next and previous page frontmatter object within the context object. When building the site, I can log outpreviousFrontmatter
andnextFrontmatter
withingatsby-node.js
and everything seems correct until the page is rendered. Logging out thenextFrontmatter
object within the page's render method outputs incorrectly. Oddly enough, I've only seen this only happen for one page of mine.I narrowed down the location of where things seemed to be getting mutated for that page to a graphql call here. Before that line, logging out
page.context.nextFrontmatter
is correct and after that line, it's completely different. I'd imagine this issue has something to do with the spread operator being a shallow extend?I'm not entirely sure of the exact problem here other than this change is working for me. I'm not sure if the other call sites for
queryRunner
might need the same treatment but I didn't wanna go overboard (although I think I only saw 3 call sites for it).