| ... | ... | @@ -1,5 +1,5 @@ |
| 1 | 1 | import { ASSERT, UNWRAP } from "@clo/lib/assert.ts"; |
| 2 | | import { type JSX, type Key, memo, type ReactNode } from "react"; |
| 2 | import { type JSX, type Key, type ReactNode } from "react"; |
| 3 | 3 | import { type Components } from "rehype-react"; |
| 4 | 4 | import remarkRehype from "remark-rehype"; |
| 5 | 5 | import { Fragment, jsx } from "react/jsx-runtime"; |
| ... | ... | @@ -29,10 +29,9 @@ type AstProcessor = Processor<Parent, Parent, Parent, Parent, Parent>; |
| 29 | 29 | */ |
| 30 | 30 | export class Memoizer { |
| 31 | 31 | // options incrementally updated via `reconfigure` |
| 32 | | #baseProcessor: BaseProcessor = defaultProcessor as BaseProcessor; |
| 32 | #baseProcessor: BaseProcessor = defaultProcessor; |
| 33 | 33 | #astProcessor: AstProcessor | null = null; |
| 34 | 34 | #components: Partial<Components> = {}; |
| 35 | | #previousComponents: Partial<Components> = {}; |
| 36 | 35 | |
| 37 | 36 | // incremental parsing graph, structure of arrays |
| 38 | 37 | #predict: Predict | null = null; |
| ... | ... | @@ -50,7 +49,7 @@ export class Memoizer { |
| 50 | 49 | if ( |
| 51 | 50 | this.#astProcessor !== null && |
| 52 | 51 | this.#baseProcessor === processor && |
| 53 | | componentsAreEqual(this.#previousComponents, components) && |
| 52 | componentsAreEqual(this.#components, components) && |
| 54 | 53 | !!this.#predict === predict |
| 55 | 54 | ) { |
| 56 | 55 | return; |
| ... | ... | @@ -64,13 +63,7 @@ export class Memoizer { |
| 64 | 63 | } |
| 65 | 64 | |
| 66 | 65 | this.#astProcessor = processor as unknown as AstProcessor; |
| 67 | | // Memoize every component. We want to ensure that React doesn't re-render |
| 68 | | // components for no reason. Just because the parent renders doesn't mean |
| 69 | | // the children should. |
| 70 | | this.#components = Object.fromEntries( |
| 71 | | Object.entries(components).map(([k, v]) => [k, typeof v === "function" ? memo(v) : v]), |
| 72 | | ) as Partial<Components>; |
| 73 | | this.#previousComponents = components; |
| 66 | this.#components = components; |
| 74 | 67 | this.#content = ""; |
| 75 | 68 | this.#positions = []; |
| 76 | 69 | this.#parsed = []; |