backend: Fix appendChildren TypeError #136

Merged
norm merged 1 commit from fix/backend-to-html-typeerror into main 2022-09-11 18:31:26 +00:00
Owner

In #134, the mention MfmNode handler was made async to allow the
mentionedUsers query to be used there. This however changed the return
type of that handler to be a Promise, causing a TypeError in
appendChildren.

This fixes the TypeError by making every handler and the appendChildren
function also async and awaiting on the processed children.

This also attempts to fix the types issue with handlers by casting to
the newly defined HandlerFunc type instead of to any.

In #134, the mention `MfmNode` handler was made async to allow the mentionedUsers query to be used there. This however changed the return type of that handler to be a `Promise`, causing a `TypeError` in `appendChildren`. This fixes the `TypeError` by making every handler and the `appendChildren` function also async and awaiting on the processed children. This also attempts to fix the types issue with handlers by casting to the newly defined `HandlerFunc` type instead of to `any`.
norm force-pushed fix/backend-to-html-typeerror from 19b4360e1c to 319ec40bd3 2022-09-10 01:21:34 +00:00 Compare
Johann150 approved these changes 2022-09-11 18:10:24 +00:00
Johann150 left a comment
Owner

seems a quite important fix and also working. just one minor nitpick

seems a quite important fix and also working. just one minor nitpick
@ -170,0 +167,4 @@
async function appendChildren(children: mfm.MfmNode[], targetElement: HTMLElement): Promise<void> {
type HandlerFunc = (node: mfm.MfmNode) => Promise<Node>;
const htmlChildren = await Promise.all(children.map(x => (handlers[x.type] as HandlerFunc)(x)));
Owner
$ git diff --check
packages/backend/src/mfm/to-html.ts:170: trailing whitespace.
``` $ git diff --check packages/backend/src/mfm/to-html.ts:170: trailing whitespace. ```
Author
Owner

fixed.

fixed.
norm marked this conversation as resolved
norm force-pushed fix/backend-to-html-typeerror from e709902540 to ffa1954fb1 2022-09-11 18:28:01 +00:00 Compare
norm force-pushed fix/backend-to-html-typeerror from ffa1954fb1 to 9bcc247421 2022-09-11 18:29:47 +00:00 Compare
norm merged commit c926b4fbcc into main 2022-09-11 18:31:25 +00:00
norm deleted branch fix/backend-to-html-typeerror 2022-09-11 18:31:27 +00:00
norm referenced this pull request from a commit 2022-09-12 20:30:38 +00:00
norm referenced this pull request from a commit 2022-09-12 20:38:28 +00:00
norm referenced this pull request from a commit 2022-09-13 15:20:06 +00:00
norm referenced this pull request from a commit 2022-09-13 15:20:27 +00:00
Sign in to join this conversation.
No reviewers
No labels
feature
fix
upkeep
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: FoundKeyGang/FoundKey#136
No description provided.