datocms / gatsby-source-datocms

Official GatsbyJS source plugin to pull content from DatoCMS
MIT License
140 stars 50 forks source link

v3.0.11 and Deferred Static Generation with GatsbyJs #187

Closed jorge-mattress closed 2 years ago

jorge-mattress commented 2 years ago

I'm using gatsby v4 and a flag defer = true on certain pages with the createPage function inside gatsby-node.js

And the returned data from the dato-cms-source plugin contains certain items with empty or null values.

A sample of the returned data looks like this: { "promotions": [], "brand": null, "name": "Ecosa", }

You can see a test website here with the defer flag set to true: https://nzfeaturedsg.gatsbyjs.io/comparer/ecosa-mattress-vs-emma-original-mattress-vs-napp-mattress-vs-peacelily-mattress

And defer flag set to false: https://nzfeaturedsg.gatsbyjs.io/comparer/ecosa-mattress-vs-emma-original-mattress

Many thanks in advance for any feedback.

stefanoverna commented 2 years ago

Hi! Any chance we can take a look at the code?

jorge-mattress commented 2 years ago

Oh forgot to provide more details, please check the gatsny-node.js here: https://gist.github.com/jorge-mattress/4248c423e7b5e76927a01160a7e238a0

And the template that renders the pages https://gist.github.com/jorge-mattress/bed4a39c6b8f9acd5d43b440250fe39f

The bits that matter the more for us inside the graphql are "promotions" and "brand" and both return null or empty array, hope this helps: promotions { startDate endDate description affiliateLinkCta altTitle affiliateLinkPromotion { affiliateLink shortenedAffiliateLink } } brand { meta { updatedAt } brandName discountFlat discountPercentage promotions { startDate endDate description affiliateLinkCta altTitle affiliateLinkPromotion { affiliateLink shortenedAffiliateLink } } }

           Please let me know if you need more info, many thanks in advance!
stefanoverna commented 2 years ago

Yes, please can you send us the complete Gatsby project + the name of your DatoCMS project at support@datocms.com? If the Gatsby project is on Github, you can share it with me!

Thanks

jorge-mattress commented 2 years ago

Thanks! already sent the info to the provided email

stefanoverna commented 2 years ago

@jorge-mattress I've been able to reproduce the issue, thank you.

Honestly, I haven't the slightest idea why it does that. I assume it's a bug in Gatsby, as we're we're simply generating the nodes.. and everything else is in Gatsby's hands. So if the nodes we generate work in one context, they should also work in other.

I've used our internal Slack channel with Gatsby to ask for help, hope to give you some updates soon 😢

jorge-mattress commented 2 years ago

Thanks a lot for your help @stefanoverna, I hope we can solve this issue soon.

pieh commented 2 years ago

We've been looking at differences when running queries in develop vs in engine and in internals of link resolver we saw differences in both.

In particular in https://github.com/datocms/gatsby-source-datocms/blob/741119e9d9250bffdffdded07b335de106eb53ad/src/hooks/sourceNodes/createTypes/item/fields/link.js#L28

In engines we get undefined vs A proxy in gatsby develop. We also see that entitiesRepo seems much smaller in engines - it lacks some keys at very least

Left is engines (dsg/ssr case), right is gatsby develop: Screenshot 2022-02-17 at 14 58 45

Because left is returning undefined I assume that's why links resolve to empty array. Does entitiesRepo need to be "populated" somehow?

pieh commented 2 years ago

Update on my previous comment - in PQR mode seems like entitiesRepo is populated from "cache" - https://github.com/datocms/gatsby-source-datocms/blob/741119e9d9250bffdffdded07b335de106eb53ad/src/hooks/createSchemaCustomization/index.js#L51

In DSG this condition is falsy, but even then when I forced this to load - it would work locally (for gatsby serve as cache is just there), but it still wouldn't work on Gatsby Cloud (or others) as cache is not transported over (cache was supposed to be used as persisted memoization - not as source of truth).

Is there a chance to adjust what resolvers are using to NOT rely on entitiesRepo?

dw-srohrlack commented 2 years ago

fyi: we've seen this behaviour using gatsby-source-datocms 3.0.8

running the latest versions of gatsby (4.7.2) and gatsby-source-datocms (3.0.15) doesn't seem to solve the issue

stefanoverna commented 2 years ago

Hey @pieh, thanks for investigating.

Please @jorge-mattress && @dw-srohrlack try gatsby-source-datocms v3.0.18-0 and let us know if it fixes the issue!

jorge-mattress commented 2 years ago

Excellent news! Going to post the results in short. But thanks beforehand for all the help!

matjack1 commented 2 years ago

hey @jorge-mattress and @dw-srohrlack we have a preview version v3.0.18-0 that should fix this issue, can you please upgrade and let us know? Thanks!

jorge-mattress commented 2 years ago

Hi Matteo, I tested the preview version and I can confirm the DSG its working! All the issues specially with the affiliate links have been fixed. Please let me know if you need more in deep feedback..

And a big thanks for you and your team for fixing the issue

matjack1 commented 2 years ago

excellent! Thank you very much for the feedback!

Nothing else to do on your end, we'll soon release the version to everyone, but you shouldn't need to upgrade. Thank you again!

dw-srohrlack commented 2 years ago

I can confirm that it's working marvelous 👌

stefanoverna commented 2 years ago

Released as 3.0.18! Thanks everyone!