Skip to content

Commit

Permalink
Merge pull request #31 from basehub-ai/bugfix
Browse files Browse the repository at this point in the history
Fixing bug in code mark when re-renders + fix bug in heading id's
  • Loading branch information
moransantiago authored Nov 20, 2023
2 parents fd7be3d + 554854e commit aa89120
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
7 changes: 7 additions & 0 deletions .changeset/small-crabs-sleep.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"basehub": patch
---

Fixes error when re-rendering the rich text renderer component in the following marks:
- Code
- Heading
12 changes: 6 additions & 6 deletions packages/basehub/src/react/rich-text/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable jsx-a11y/alt-text */
/* eslint-disable @next/next/no-img-element */
import { type ReactNode, type ReactElement, useMemo } from "react";
import { type ReactNode, type ReactElement } from "react";
import { extractTextFromNode, incrementID } from "./util/heading-id";

/**
Expand Down Expand Up @@ -181,7 +181,7 @@ export const RichText = <
props: RichTextProps<CustomBlocks>
) => {
const value = props.children as Node[] | undefined;
const generatedIDs: GeneratedIDsRecord = useMemo(() => ({}), []);
const generatedIDs: GeneratedIDsRecord = [];

return (
<>
Expand Down Expand Up @@ -288,15 +288,15 @@ const Node = ({
break;
case "text":
const forceCodeMark = parent?.type === "codeBlock";
if (forceCodeMark) {
node.marks = node.marks ?? [];
node.marks.push({
const clonedMarks = [...(node.marks ?? [])];
if (forceCodeMark && !clonedMarks.some((mark) => mark.type === "code")) {
clonedMarks.push({
type: "code",
attrs: { isInline: false },
} satisfies Mark);
}
handler = ({ children }: { children?: ReactNode }) => (
<Marks marks={node.marks} components={components}>
<Marks marks={clonedMarks} components={components}>
{children}
</Marks>
);
Expand Down

0 comments on commit aa89120

Please sign in to comment.