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