feat: add jsonToHtmlAsync for async customElementTypes support#100
Draft
glassdimlygr wants to merge 1 commit intocontentstack:masterfrom
Draft
feat: add jsonToHtmlAsync for async customElementTypes support#100glassdimlygr wants to merge 1 commit intocontentstack:masterfrom
glassdimlygr wants to merge 1 commit intocontentstack:masterfrom
Conversation
6cbbd2d to
c2200a4
Compare
Add toRedactorAsync (exported as jsonToHtmlAsync) that supports customElementTypes handlers returning string | Promise<string>. Enables dynamic component resolution (e.g. await import()) before serialization. Children are resolved via Promise.all concurrently. Refactors shared logic (text processing, attr building, element node processing) into toRedactorHelpers.ts so both sync and async versions are thin recursive shells with no duplicated code. The existing sync jsonToHtml behavior is unchanged. New types: IJsonToHtmlAsyncElementTags, IJsonToHtmlAsyncOptions.
c2200a4 to
44da5fa
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
jsonToHtmlAsync— an async variant ofjsonToHtmlthat allowscustomElementTypeshandlers to returnPromise<string>in addition tostring.Motivation
Frameworks like Next.js use dynamic imports (
next/dynamic,React.lazy) for code-splitting. When rendering JSON RTE content that contains embedded component references, the component modules may not be available synchronously. Currently,jsonToHtmlrequires all handlers to return strings synchronously, making it impossible toawait import()a component before rendering it.This is a common issue for any consumer that:
Changes
toRedactorAsync(exported asjsonToHtmlAsync): Async version oftoRedactor. Children are resolved concurrently viaPromise.all. Handler results areawaited, so both sync (string) and async (Promise<string>) return values work.IJsonToHtmlAsyncElementTags: Handler signature where return type isstring | Promise<string>IJsonToHtmlAsyncOptions: Options interface using the async element tags typejsonToHtml/toRedactorare completely untouched. This is purely additive.Usage
Tests
toRedactorAsyncproduces identical output totoRedactorfor all existing test cases (headings, tables, formatting, lists, links, custom handlers, text wrappers)