TransitionbyDesign / homemaker

GNU Affero General Public License v3.0
0 stars 1 forks source link

hero_image field causing missing images/build problems #85

Open wu-lee opened 2 years ago

wu-lee commented 2 years ago

Difficulties with a technical aspect of Gatsby means that the build can intermittently fail depending on essentially random factors. If the first article Gatsby sees in the build has this field set, it works as expected; if not, it can fail to build and/or there are no hero images (I don't recall the exact behaviour at the time of writing).

This issue has already had some attention but there is no resolution as yet. See

https://github.com/TransitionbyDesign/homemaker/commit/8f2c7304914160a723fd012bd93db658e4715af1 https://github.com/gatsbyjs/gatsby/issues/3344#issuecomment-989213202

wu-lee commented 2 years ago

This is a frustrating one, and is not new - it was a problem when the site was originally being worked on. I did think it was working but I think the recent content uploads have been triggering it again.

I've investigated fixing it, but I have not found a better solution than I did originally. The issue seems to be a known problem and any people are reporting it (see issue link above).

The dilemma is:

So, our case seems to be exacerbated by the fact that the hero_image field is an image file which needs to include functions provided by a Gatsby module gatsby_image to allow resized images to be generated: something is happening behind the scenes to change the way inference works, but I don't yet know what.

The best result seems to be to let Gatsby infer this field's type.

Consequently, until a solution is found - perhaps an explicit type specification which works - I recommend the following workaround:

Some other problems to avoid:

wu-lee commented 2 years ago

I think I may have found a solution, trawling the web and using some cargo-cult magic incantations. So instead of explicitly defining the hero_image field in gatsby-node.js like this (which gets an error "You can't use childImageSharp together with undefined.undefined" and no images):

 hero_image: File

Or leaving it undefined and therefore inferred - unreliably - by Gatsby, define it like this:

 hero_image: File @fileByRelativePath

That seems to do the job, but it's not very well documented!

Clues to this from: https://stackoverflow.com/questions/69738768

Which refers to: https://github.com/gatsbyjs/gatsby/issues/18271#issuecomment-547097964

This is now committed to the code, and seems to be working at the moment, but we should keep an eye on it, especially to check to see if custom_icon now works.