Unlock seamless workflows and faster delivery with our latest releases - Join the deep dive

Issue with adding and using images in Sanity project, resolved by disabling cache in Next.js query.

42 replies
Last updated: Oct 2, 2023
Hey guys, I decided to try out sanity today after seeding some initial items, one image didn't successfully get added, so I added it manually using the studio and it looks like its there however when i map over within my next project and try and use that image i get an error 'Unable to resolve image URL from source', if i exclude that entry everything works fine. why is this?
Oct 2, 2023, 6:17 PM
Can you share your code?
Oct 2, 2023, 6:31 PM
sure which part would you like to see the react components or the sanity inventory? or something else?
Oct 2, 2023, 6:47 PM
i uploaded the project into git at https://github.com/aidycodes/sanity-first-look but you most likely dont want to look though the whole thing so let me know what your looking for and ill past it in a code block
Oct 2, 2023, 6:51 PM
also i noticed from console logging images that the the image i uploaded from image studio has completely different json
Oct 2, 2023, 6:53 PM
Yeah, it looks like the image didn’t complete uploading. Can you share a screenshot of what this field looks like in the Studio?
Oct 2, 2023, 6:57 PM
sure 1 sec
Oct 2, 2023, 7:00 PM
ok so i uploaded another image and checked the logs and it looked better so i removed my conditional which stopped that id being rendered but i stil get the same error
Oct 2, 2023, 7:06 PM
Can you try unsetting the field and re-adding the image? Something about the way you initially added it caused the asset to be malformed.
Oct 2, 2023, 7:08 PM
yes i just noticed that i have 2 images and not 1 on that id so the studio one isnt being used
Oct 2, 2023, 7:09 PM
when you say unset the field you mean delete the content?
Oct 2, 2023, 7:09 PM
Yes. Click the remove option on the item in the array.
Oct 2, 2023, 7:10 PM
ok so i removed everything from images and within my project they are still showing
Oct 2, 2023, 7:13 PM
so im gonna delete the cache from localhost
Oct 2, 2023, 7:14 PM
Did you also publish the changes?
Oct 2, 2023, 7:14 PM
yes
Oct 2, 2023, 7:14 PM
no lol
Oct 2, 2023, 7:15 PM
i thought i did
Oct 2, 2023, 7:15 PM
ok i deff have now and 2images are still showing so im just gonna remember how 2 delete the cache of a single website
Oct 2, 2023, 7:18 PM
ok so i cleared all site data and this is still showing up
Oct 2, 2023, 7:23 PM
i will test in another browser
Oct 2, 2023, 7:23 PM
Oh, just FYI you’ve pushed your token up with your repository. That’s something you should keep secret.
Oct 2, 2023, 7:26 PM
i only pushed it up quickly for you normally my next build wouldnt be so simple and its all protectedd
Oct 2, 2023, 7:27 PM
OK, cool cool.
Oct 2, 2023, 7:27 PM
Can you DM me your project ID and dataset name? I’m going to query your data to see what it looks like in the full context of the document.
Oct 2, 2023, 7:31 PM
NEXT_PUBLIC_SANITY_PROJECT_ID=kuq38qyv
Oct 2, 2023, 7:32 PM
how would i know my dataset name
Oct 2, 2023, 7:33 PM
is it products?
Oct 2, 2023, 7:33 PM
it would be the name you selected when you created the project via the CLI. The default is ‘production’. It’s probably in your .env as well.
Oct 2, 2023, 7:37 PM
lol yes it was next to it im dumb
Oct 2, 2023, 7:37 PM
NEXT_PUBLIC_SANITY_DATASET=production
Oct 2, 2023, 7:37 PM
Ok, the braided belt product is showing images as null on my end:
{
    "_createdAt": "2023-10-02T16:24:29Z",
    "name": "Braided Leather Belt",
    "sky": null,
    "description": "These handsome leather belts are guaranteed to pull together any outfit. They're made of vegetable-tanned Italian leather, which means they have natural highs and lows of color and will look even better over time.",
    "slug": null,
    "_id": "e882fe48-253c-40fb-8155-51b47b063c1a",
    "price": 4999,
    "currency": "USD",
    "images": null
  }
Oct 2, 2023, 7:48 PM
huh
Oct 2, 2023, 7:49 PM
So it looks like you have successfully removed the images. Can you try adding the images back in now?
Oct 2, 2023, 7:49 PM
okay ill do that i have a feeling it may not work tho
Oct 2, 2023, 7:50 PM
If the asset does not work, you’ll need to delete it and reupload\
Oct 2, 2023, 7:50 PM
ok so i put another image in
Oct 2, 2023, 7:52 PM
but im still getting the same error
Oct 2, 2023, 7:52 PM
if you query it however i think on your side it will look correct
Oct 2, 2023, 7:52 PM
i think next 13 is fetching stale data
Oct 2, 2023, 7:54 PM
ok so i fixed it by disabling next 13s cache on that query
Oct 2, 2023, 7:59 PM
thanks very much for taking the time to go though this with me ❤️
Oct 2, 2023, 8:00 PM
Oh great! I’m glad you found a solution 😮‍💨
Oct 2, 2023, 8:13 PM

Sanity– build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?