-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Missing images when using relation widget in file collection #2786
Comments
@rusyurchenko Thank you for opening this issue. Do you mind posting a reproduction scenario? (an example repo would be perfect). It will make it easier to pinpoint the exact location of the problem. |
@erezrokah Will try to reproduce this issue with default starter later today, thank you! |
@erezrokah Hey, sorry for the delay. I've reproduced this issue on the default blog starter. Example repo: https://github.com/rusyurchenko/gatsby-netlify-issue. Attached query example into readme. |
Thanks @rusyurchenko I'll try to reproduce with the repo and update here |
Related issues: From what I managed to figure out from the Gatsby issues, this happens when Gatsby fails to treat the image as a File (and treats it as a string instead). I managed to work around the issue by flattening the directory structure for the file collection (https://github.com/rusyurchenko/gatsby-netlify-issue/pull/1). |
@erezrokah Yeah, it works but the issue is still open. In our case, Gatsby exactly treats the image file as a File since we're not getting an error such as |
Hey @rusyurchenko, sorry I forgot to mention it. I was getting Both images are from running We'll need to take a closer look at Gatsby code to understand the issue better |
@erezrokah Exactly! I'm getting the same issue with a broken image resolving time-to-time. But it's another issue related to gatsby build etc. |
It still looks like a Gatsby build issue though (maybe not exactly the same one), since the workaround was just to change the folder structure (nothing related to the CMS). I'll try to look at the Gatsby code to get a better sense of where the frontmatter |
Sorry for the delay, but I think I figured it out. In your code you're putting the path to the relation image under the post node. Specifically for the Another issue is that Gatsby uses an internal map (weak map actually) to map root nodes to specific objects of those nodes. This happens here: Since you linked the exact frontmatter instance the map (which uses reference equality) returned the wrong root node for the relation frontmatter thus again evaluating the path based on the wrong parent node. This is evident by running these queries:
The first one always returns a non null The solution was to deep clone the relation frontmatter object and also fix the @rusyurchenko do you mind testing my PR locally? |
@erezrokah That works, make sense, thank you! Great explanation and clear solution. It can be closed. However, it looks like a pretty simple solution and at the same time as some hack. While solving this problem as a workaround I'm adding a node frontmatter relation value data to the page context and query exact relation object from the following page. Probably do you know another way to do the same (map relation node data to the post node) without doing extra work in |
I agree, it does feel like a hack. Closing for now. |
I have the same issue! here is my code about.md aboute.js config.yml |
Hi @mouhsnimohamed I think https://www.gatsbyjs.org/docs/schema-customization/ is the recommended way to go in your case. |
Describe the bug
Brief: When I'm referencing a collection using relation widget(not a file collection, just basic folder collection) I'm getting all data from this relation except images. It just returns null for image field.
More info:
I have
case-studies
collection and referencing to it through relation widget from both folder and file collections. To access the relation entry I made a node field where I check for the relation string and pass its data to the node. (code below)In case of relation
folder-collection entry -> folder collection
all work as expected and I'm getting all 'case-study' data with images.But in case of relation
file-collection entry -> folder collection
I'm getting only data from 'case-study' with missed images.To Reproduce
https://github.com/rusyurchenko/gatsby-netlify-issue
Expected behavior
A relation like 'file-collection entry -> folder collection reference" should return data with resolved images.
**Screenshots / Examples **
Example of
file-collection entry -> folder collection reference
query.https://gist.github.com/rusyurchenko/1b58c0df547b30069dd155a1dd25c5c5
Example of relation
folder-collection entry -> folder collection
https://gist.github.com/rusyurchenko/289ba43d909355c86cf01c883b860dcf
Applicable Versions:
CMS configuration
case-study
as the base.marketing' folder collection
andloyalty-why-do-need
are referenced to the base.https://gist.github.com/rusyurchenko/cacaaa5fb679e0d79584e514e481e300
onCreateNode: (where queries for collection reference)
https://gist.github.com/rusyurchenko/cff8e95407c7df0b11ca89372313a2e9
gatsby-config.js
https://gist.github.com/rusyurchenko/79396d92bb9340039413787c1ad2452f
Additional context
I think this issue happens because of some issue with image path resolve in file collection.
The text was updated successfully, but these errors were encountered: