Async decoration #4270
Unanswered
JonasKruckenberg
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
To give a bit of context, I want to implement syntax highlighting using shiki. This however requires me do load the wasm, theme & language files beforehand which of course is an async operation.
Parsing the text and generating tokens is from what I can what the decorate hook is for right?
Because here is my problem:
Having async work in the renderElement, renderLeaf & renderPlaceholder hooks is fine since you can return a Suspense element, something that doesn't work for the decorate hook.
So my idea was to attach the promise returned by shiki to the code element (since the highlighter instance is specific to the code block because of languages), and await that promise in my renderElement hook via Suspense.
However, the decorate hook does not get triggered after the rerender of the Suspense (how would it anyway) so my decorate hook has no idea how to tokenize the text.
The only was this DOES work is by wrapping the whole slate editor in a Suspense element. This causes the rendering of the whole document to be deferred however, which seems stupid for just some fancy colors.
Is there some way to manually trigger the decoration after my promise has resolved? Or is there some other way to do what I want to do?
Beta Was this translation helpful? Give feedback.
All reactions