-
Notifications
You must be signed in to change notification settings - Fork 4
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
Support image block in shared richtext #699
Comments
A simple solution would be to attempt to fetch with both studio and shared client, and pick whichever resolves to an actual image. This assumes that the asset ids are globally unique. A solution would look something like this: const useNextSanityGlobalImage = (image: IImage) => {
const studioImage = useNextSanityImage(client, image);
const sharedImage = useNextSanityImage(sharedClient, image);
const [globalImage, setGlobalImage] =
useState<UseNextSanityImageProps | null>(null);
useEffect(() => {
fetch(studioImage.src).then((r) => r.ok && setGlobalImage(studioImage));
fetch(sharedImage.src).then((r) => r.ok && setGlobalImage(sharedImage));
}, [studioImage, sharedImage]);
return globalImage;
}; A more involved, but possibly safer, approach is to pass either a client identifier or the client config itself through the RichText hierarchy. This would require some prop drilling though 👷 |
How many layers of prop drilling are we looking at? 🫠 |
This assumes that all images within the blocks given to RichText come from the same known project (e.g. no mixing of shared and studio content). |
Hm, could perhpas the RichText component in and of itself be optimized? 🤔 there are also cases where we have myPortableTextComponents because RichText doesnt support normal as any other styles than body, so for cases where we want portable text but with normal as say bodySuperLarge or bodyLarge.. 🤔 |
Closed by #702 |
Images in rich text from shared are not rendered. This is becuase the image assets are fetched with the studio client, not the shared client.
The text was updated successfully, but these errors were encountered: