storyblok-rich-text-react-renderer icon indicating copy to clipboard operation
storyblok-rich-text-react-renderer copied to clipboard

Return promise within markResolvers

Open Jdruwe opened this issue 1 year ago • 4 comments

Hey!

I wonder if there is a way to return a promise with a custom markResolvers? In my case I would need to make an async within my [MARK_LINK] resolver but it seems like it's not possible right now?

Jdruwe avatar Mar 07 '24 19:03 Jdruwe

Right now that's not possible i'm afraid, the API is designed to be synchronous. May i ask what your use case is?

claus avatar Mar 07 '24 19:03 claus

Our Storyblok setup is a bit exotic which means that without using resolve_links=story (which I don't want to use right now) I am not able to find a localized version of the internal link within a rich text component. I have written a separate util function which makes a async call to fetch all details necessary but I can't use it within a markResolver as you just mentioned. I saw someone asking something similar on the Contentful alternative: https://github.com/contentful/rich-text/issues/83. I think I am going to use the same approach: process the document data before passing it to storyblok-rich-text-react-renderer

Jdruwe avatar Mar 07 '24 20:03 Jdruwe

Yeah that'd be a solve. Otherwise, i guess i can make it work but that would require some significant changes and i'm not sure i'm prepared to do that, as i think most people are fine with it being sync

claus avatar Mar 07 '24 20:03 claus

Yea I can imagine, for now it's fine. I asked copilot to generate me a transform function and it worked first time :D Now I can just pass my transformed document to the library.

Jdruwe avatar Mar 07 '24 20:03 Jdruwe