Closed surjithctly closed 2 years ago
Could you perhaps clarify in which scenario this occurs, preferably with a code example of how you retrieve the image from Sanity?
Closing due to inactivity, issue can be reopened if we can get a reproducible case.
Hey,
Sorry, missed your comment. It happens when "image
" exists but not "image.asset
". I had this issue when I added an image caption without adding image.
To Reproduce:
image
field with caption / altimage
does not have asset
. Now, I tried to add an exception in my code for this scenario.
if (!image.asset) {
return null;
}
But now there is another error called: hooks cannot call conditionally.
So, I can't do this error exception in my code. So checking the possibility to check this in the plugin itself.
Just checked this in the Sanity studio which i use for testing purposes. It looks like i have to select/upload an image before the "Edit details" button becomes visible and i can specify a caption/alt. What does the configuration of your Sanity image field look like?
I have isHighlighted
true
as per https://www.sanity.io/docs/image-type
So it will be visible all time.
fields: [
{
name: 'caption',
type: 'string',
title: 'Caption',
options: {
isHighlighted: true // <-- make this field easily accessible
}
},
Thanks for the extensive example. I've just released version 3.1.7 which includes a check for the existence of the image id in order to fix this issue.
I'm getting the following error when we pass
image.alt
but notimage.asset
. This plugin should send appropriate error whenimage.asset
is not found.In my code, I cannot do the following because hooks cannot call conditionally.