Skip to content

[Suggestion]: reactivity in node-level diffing for createParse() #135

@arashsheyda

Description

@arashsheyda

Description

when rendering Comark in a framework (Vue, React, Svelte), every call to parse() produces an entirely new AST. framework renderers see all-new object references and re-render the entire document tree, even if only a single character changed in one paragraph

This is costly for:

  • Streaming/AI chat: tokens arrive rapidly but only the last node is actively changing
  • Live editors: users edit one section while the rest is static
  • Expensive plugins: syntax highlighting and math rendering run on every node, every time

Proposal

add automatic node-level diffing to createParse() when the returned parser is called multiple times, it compares the new AST against the previous result and preserves === object references for structurally unchanged nodes

const parse = createParse()

const tree1 = await parse('# Hello\n\nWorld')
const tree2 = await parse('# Hello\n\nWorld!!')

tree2.nodes[0] === tree1.nodes[0]  // true — heading unchanged
tree2.nodes[1] === tree1.nodes[1]  // false — paragraph changed

framework renderers can then skip re-rendering nodes whose reference didn't change with zero API changes for consumers. here's a video of react example with react-scan (look at the AST section)

Before

Screen.Recording.2026-04-16.at.8.50.44.PM.mov

After

Screen.Recording.2026-04-16.at.8.57.31.PM.mov

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions