Path representation and API ergonomics for gap rendering and beyond
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 30/100
- Issue type
- Refactor
- Clarity
- Needs clarification
- Activity status
- Quiet
- Tech stack
- typescript
- Domain
- frontend
Research direction
Start by tracing gap computation, collect_nested_array_gaps, PathGapData, NodeGapMarkers, and the session.doc access described in the issue. Establish which proposal is in scope, then measure current serialization, recomputation, and child-count behavior before defining tests or benchmarks; done means an agreed, scoped API and acceptance criteria.
Written by the indexing model from the issue text.
Description
The node gap implementation surfaced several related friction points. Most trace back to the same root cause: paths are bare Array<string|number> values with no caching, no structural API, and redundant serialization at every use site.
The problem
Paths are created, serialized, and compared constantly:
- Gap computation converts paths to
.join('.')strings (for Map keys),.join('-')strings (for CSS anchor names), and back via.split('.'). In a 500-node document this is thousands of small string allocations per render cycle. - CSS anchor names like
--g-page_abc123-body-42-buttons-0-gap-beforeare long. These are emitted as inlinestyleattributes on every node gap and gap marker, and referenced inanchor()calls inside CSS formulas. Long custom-property names increase memory for inline styles and make DevTools inspection harder (though they also aid debuggability:page_abc123-body-42is self-describing in a way that a short hash wouldn't be). - Structural queries require ad-hoc string parsing: "is this a root-level child?" means counting dots; "get the parent path" means
slice(0, -1)(new allocation); "get the child index" meansparseInt(path.at(-1)). - Schema traversal requires materializing nodes just to find their type and properties.
collect_nested_array_gapscallssession.get()+doc.nodes[]lookups + schema property iteration just to enumerate which child properties arenode_arraytyped. - Coarse reactivity granularity:
session.docis$state.raw(), so reading it (viasession.get(),session.inspect(), orsession.doc.nodes[...]) subscribes to doc-level reference changes — i.e., any transaction triggers a re-run. There are no per-path or per-property subscriptions (that's the whole point of$state.raw), but code inside$effectthat only cares about one array's child count still re-evaluates on every unrelated edit elsewhere in the document.
Suggested improvements
1. First-class Path type
An immutable value type with cached serializations:
class Path {
get str() // "page_1.body.3" → cached
get css_name() // "page_1-body-3" → cached
get depth() // 3
get index() // last segment as number, or null
child(segment) // Path → Path (could intern common children)
get parent() // cached, zero allocation
equals(other)
starts_with(other)
toString() // returns str, so it works as Map key
}
This would eliminate the hot-path .join() / .split() churn. The trade-off is an extra abstraction.
The current path arrays are transparent and easy to inspect. A Path class would need to be debugger-friendly (good toString(), maybe a custom Chrome DevTools formatter).
2. Selective re-computation
Since doc is $state.raw(), there's no fine-grained reactivity to exploit — every transaction swaps the entire doc reference. Gap computation already mitigates this with per-path PathGapData signals that only notify subscribers (the NodeGapMarkers components) when a specific path's gaps actually change.
Further improvements could include:
- A lightweight diff between old and new doc after a transaction, to skip recomputing gaps for arrays that didn't change.
- A
session.child_count(array_path)that returns just the length and can be compared cheaply, so the gap computation can bail out early when the count (not the contents) is unchanged.
3. Schema queries without live nodes
Something like session.schema_for(node_type) or session.property_defs(node_type) so code can enumerate a node type's node_array properties from the schema alone, without first fetching a live node instance.
4. Efficient child count
session.child_count(array_path) returns just the length, with a dependency only on the count, not the array contents. Useful when code needs N+1 gaps for N children and shouldn't re-run when children reorder but count stays the same.
On CSS anchor name length
The long anchor names deserve nuance. They encode the full document path (--g-page_abc-body-42-buttons-0-gap-before) which:
- Pro: self-describing, invaluable when debugging CSS anchor positioning in DevTools
- Pro: globally unique without extra bookkeeping
- Con: emitted twice per element (once in
anchor-name:, once in eachanchor()reference), so memory for inline styles scales with both document size and path depth - Con: long custom-property names may affect affect memory usage, though this needs to be tested
A possible middle ground: keep human-readable names in dev mode, switch to shorter hashed names in production builds or just accept the verbosity as a reasonable trade-off for debuggability.
- Dominant language
- TypeScript
- Stars
- 691
- Forks
- 20
- PR merge metrics
- No merged PRs in 30d
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from michael/svedit
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Similar issues
-
bug data-types
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
ClickHouse/clickhouse-js#1293 ·
Maintainers usually reply within 1 day
-
area: middleware enhancement good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
agent/quality testing
Difficulty 1/5 Under an hour Newbie friendliness 95/100
Maintainers usually reply within 1 day
-
GitHub registry install via `gh` credentials rewrites `\u0000`–`\u001f` escapes in source files to `^@`–`^_`Possibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 92/100
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
juspay/agent-distro#203 ·
Maintainers usually reply within 1 day