Skip to content
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

Closed
mathiazom opened this issue Sep 20, 2024 · 5 comments
Closed

Support image block in shared richtext #699

mathiazom opened this issue Sep 20, 2024 · 5 comments
Assignees

Comments

@mathiazom
Copy link
Contributor

mathiazom commented Sep 20, 2024

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.

@mathiazom mathiazom converted this from a draft issue Sep 20, 2024
@mathiazom mathiazom changed the title Support image block in richtext Support image block in shared richtext Sep 23, 2024
@mathiazom
Copy link
Contributor Author

mathiazom commented Sep 23, 2024

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 👷

@mathiazom mathiazom self-assigned this Sep 23, 2024
@mathiazom mathiazom moved this from Ready for development to In progress in Nye nettsider Sep 23, 2024
@christinaroise
Copy link
Contributor

How many layers of prop drilling are we looking at? 🫠

@mathiazom
Copy link
Contributor Author

mathiazom commented Sep 23, 2024

How many layers of prop drilling are we looking at? 🫠

  • RichText
    • GroupedBlogText
      • myPortableTextComponents (convert to function)
        • SanityImage
          • useConvertSanityImageToNextImage
            • SanityImage

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).

@christinaroise
Copy link
Contributor

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.. 🤔

@mathiazom
Copy link
Contributor Author

Closed by #702

@github-project-automation github-project-automation bot moved this from In progress to Done in Nye nettsider Oct 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

No branches or pull requests

2 participants