Skip to content

fix(visx): type SVG props with octane's attribute bag - #755

Merged
trueadm merged 4 commits into
octanejs:mainfrom
dudusotero:fix/visx-consumer-types
Aug 14, 2026
Merged

trueadm merged 4 commits into
octanejs:mainfrom
dudusotero:fix/visx-consumer-types

Conversation

@dudusotero

@dudusotero dudusotero commented Aug 13, 2026 •

Copy link
Copy Markdown
Contributor

Summary

@octanejs/visx ships raw source and points its exports at it, so a consumer's TypeScript program compiles every reachable module. React's SVGProps is not assignable to octane's intrinsic element bag — handlers receive native DOM events, className composes clsx-style, class/for are accepted natively, and children is a renderable — so every component that spread it produced errors in a consumer's program.

Forty-two modules move to Octane.SVGProps, following the pattern already established in grid/, group/, responsive/, and shape/. In-src diagnostics under tsrx-tsc -p packages/visx/tsconfig.json drop from 158 to 90.

This is partial progress on #721, not its completion — see Risk / follow-ups.

Why the parity suite needed real work, not an exemption

The conversion left 24 parity assertions failing. Probing every module export found 55 diverging components, and the existing flat attribute-bag carve-out covers only 20 of them.

The reason the rest fell through is that an attribute bag reaches a component's surface in three shapes, and the normalization only handled the first:

  1. spread flat into the props;
  2. held by an object-typed member (tickLabelProps, backgroundProps, lineProps, glyphStyle);
  3. carried by a render prop's argument — Axis passes AxisRendererProps to children, and the normalization kept a function's argument exact while collapsing only its return.

It now recurses through all three, treating a member as a bag when it has a className key. Recursion only ever collapses more of the same divergence on both sides, so it cannot turn a passing comparison into a failing one.

That matters because the alternative was pinning those surfaces by key name only, which checks no types at all. The reach is regression-tested: retyping AxisRendererProps.horizontal from boolean to string fails nine assertions that a key-for-key pin would not have noticed.

Resulting assertion tiers:

Tier Count
Equal — member-by-member 77
Extends — one-directional 23
key-for-key 4

The four key-for-key surfaces each have a concrete reason: SplitLinePath keeps styles.className a plain string so it can forward to LinePath; the two area stacks take children as ReactElement<AreaSeriesProps>, putting the bag inside a React element type rather than a renderable hole; and Drag diverges on the native event union rather than a bag.

Twenty-three surfaces (clip-paths, gradients, markers, Threshold) additionally take an optional id where upstream requires one, because they generate a fallback with useStableId. That predates this branch and is exactly the one-directional relationship the module-level Extends asserts already describe, so they keep that direction with the bag divergences collapsed.

_Network drops from Equal to Extends like its peers. It held as Equal only because tsgo reads the generated .tsrx.d.ts, which annotates returns as React's JSX.Element; compiling the published .tsrx sources — what a consumer's program actually does — shows Graph, Links, and Nodes returning octane's nominal element type.

Changes

  • 42 modules move from React's SVGProps to Octane.SVGProps.
  • Capitalized JSX aliases replace createElement where a React FunctionComponent | ComponentClass union reached octane's createElement, which takes a ComponentBody and cannot call a constructor.
  • A real declaration for d3-interpolate-path.
  • A render-prop implementation of TooltipPositionContext.Consumer, which octane deliberately lacks.
  • tests/types/parity.test-d.ts: recursive bag normalization, per-component carve-outs with the reason recorded for each, and OctaneOnlyAttributeKeys completed to class/for/hidden/tabindex (measured: octane's bags add exactly those and drop nothing).

Validation

  • pnpm format:check
  • pnpm typecheck
  • pnpm test — see below
  • targeted tests: pnpm vitest run --project visx --project visx-ssr --project visx-differential (13 files, 40 tests)
  • pnpm packages:source:check, pnpm sync (no drift), pnpm exec changeset status
  • tsgo --noEmit -p packages/visx/tsconfig.json: 24 errors → 0

pnpm test was run in full and came back red: 12 tests in packages/octane/tests/browser/native-change/native-change.test.ts failed on 30 s Playwright timeouts. The same file passes 12/12 in isolation, and this diff touches nothing outside packages/visx, so this reads as resource contention in a 2 181-file local run rather than a regression — but it is recorded here rather than ticked.

All counts were measured by redirecting to a file. Piping tsrx-tsc truncates its output and undercounts.

Risk / follow-ups

  • Partial, by design. 90 in-src diagnostics remain, so packages/visx/tsconfig.json keeps its SOURCE_PUBLICATION_DEBT entry and continues to validate through tsgo. Not closing Several published TSRX source bindings fail strict consumer tsrx-tsc typechecking #721.
  • 7 of the 90 are not visx bugs: the dropped let __spread_props declaration tracked in Virtual TSX drops the let __spread_props declaration for a host element with ref plus a spread outside a direct return, producing TS2304 #737 (text/Text.tsrx, tooltip/tooltips/Tooltip.tsrx, geo/projections/Projection.tsrx). They also own the 2 assertions still failing in parity.test-d.ts under tsrx-tsc (_Text, _TooltipWithBounds), which failed before this branch too. Working around them inside visx would hide a framework defect behind an app workaround.
  • The remaining 83 are genuine visx work, concentrated in xychart/components/series/private (19), tooltip/floating (15), brush (11), zoom (10).
  • Unrelated observation: the SOURCE_PUBLICATION_DEBT comment records visx at // 57 errors. Measured on main under the current toolchain it is 158. The recorded counts look like they were taken through a pipe, which truncates. Not touched here, since entries are deleted rather than edited.

Provenance

  • An agent produced this diff (agent-authored)

Note

Medium Risk
Broad public TypeScript surface change in visx (handlers and className semantics) with no runtime change; consumers on strict checking may need prop/handler updates. SWR changes are test-harness only.

Overview
@octanejs/visx moves forty-two modules from React SVGProps to Octane.SVGProps so consumers compiling published source stop hitting assignability errors (native DOM handlers, clsx-style className, optional id where useStableId applies). Runtime behavior and export names stay the same; public prop types change for SVG rest props and nested bags (tickLabelProps, glyphStyle, etc.).

Supporting fixes: hierarchy/network dynamic components use capitalized JSX instead of createElement; TooltipPositionConsumer is a small render-prop wrapper over useContext; d3-interpolate-path gets a module declaration; AnimatedPath drops a stale @ts-expect-error.

tests/types/parity.test-d.ts gains recursive normalization for attribute bags (flat spreads, nested members, render-prop arguments) plus per-component carve-outs so upstream parity checks still pass without key-only pins for most surfaces.

SWR pristine Jest harness now gates a second useSWR race (local mutation / isValidating:true) the same way as the existing remote-mutation case, with docs, manifest hashes, and a unit test for the timer gate.

Reviewed by Cursor Bugbot for commit 64fbb78. Bugbot is set up for automated code reviews on this repo. Configure here.

@octanejs/visx ships raw source and points its exports at it, so a
consumer's TypeScript program compiles every reachable module. React's
SVGProps is not assignable to octane's intrinsic element bag — handlers
receive native DOM events, className composes clsx-style, class/for are
accepted natively, and children is a renderable — so every component that
spread it produced errors in a consumer's program.

Forty-two modules move from React's SVGProps to Octane.SVGProps,
following the pattern already established in grid/, group/, responsive/,
and shape/. Alongside that: capitalized JSX aliases replace createElement
where a React FunctionComponent | ComponentClass union reached octane's
createElement, which takes a ComponentBody and cannot call a constructor;
a real declaration for d3-interpolate-path; and a render-prop
implementation of TooltipPositionContext.Consumer, which octane
deliberately lacks.

In-src diagnostics under `tsrx-tsc -p packages/visx/tsconfig.json` drop
from 158 to 90, measured by redirecting to a file: piping that command
truncates its output and undercounts.

The conversion left 24 parity assertions failing. Probing every module
export found 55 diverging components, in categories the existing flat
attribute-bag carve-out covers only 20 of.

The reason the rest fell through is that an attribute bag reaches a
component's surface in three shapes, and the normalization only handled
the first: spread flat into the props, held by an object-typed member
(tickLabelProps, backgroundProps, lineProps, glyphStyle), or carried by a
RENDER PROP'S ARGUMENT — Axis passes AxisRendererProps to children, and
the normalization kept a function's argument exact while collapsing only
its return. It now recurses through all three, treating a member as a bag
when it has a className key. Recursion only ever collapses more of the
same divergence on both sides, so it cannot turn a passing comparison
into a failing one.

That keeps real member-by-member checking where a key-only pin would
otherwise have been the fallback. A regression test confirms the reach:
retyping AxisRendererProps.horizontal fails nine assertions that a
key-for-key pin would not have noticed at all. Only four surfaces stay
pinned key-for-key — SplitLinePath, whose styles members keep className a
plain string so it can forward to LinePath; the two area stacks, whose
children are ReactElement<AreaSeriesProps>, putting the bag inside a
React element type rather than a renderable hole; and Drag, whose
divergence is the native event union rather than a bag.

Twenty-three surfaces (the clip-paths, gradients, markers, and Threshold)
additionally take an optional id where upstream requires one, because
they generate a fallback with useStableId. That predates this work and is
exactly the one-directional relationship the module-level Extends asserts
already describe, so a new AttributeBagNormalizedPropsExtends keeps that
direction with the bag divergences collapsed.
BrushProps.selectedBoxStyle holds a bag rather than spreading one, and is
spelled out on the upstream side like renderBrushHandle already was.

OctaneOnlyAttributeKeys was also incomplete: octane's bags add exactly
class, for, hidden, and tabindex, and drop nothing. Those extras are
optional, so the member-by-member comparisons tolerate them, but a
key-for-key pin cannot, so PropsShapeEqual excludes the full set.

_Network drops from Equal to Extends like its peers. It held as Equal
only because tsgo reads the generated .tsrx.d.ts, which annotates returns
as React's JSX.Element; compiling the published .tsrx sources, which is
what a consumer's program does, shows Graph, Links, and Nodes returning
octane's nominal element type. RenderableNormalizedPropsEqual is now
unused and is removed.

This is partial progress on strict consumer type-checking for visx, not
its completion. 90 in-src diagnostics remain, 7 of them the dropped
`let __spread_props` compiler defect tracked as octane issue 737, so the
package keeps its SOURCE_PUBLICATION_DEBT entry and continues to validate
through tsgo.

Co-authored-by: Claude Opus 5 <[email protected]>
@github-actions github-actions Bot added agent-authored Diff or issue body substantially produced by an AI agent fix PR: bug fix labels Aug 13, 2026
@trueadm
trueadm marked this pull request as ready for review August 14, 2026 09:23

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix is ON, but it could not run because the branch was deleted or merged before autofix could start.

Reviewed by Cursor Bugbot for commit b221618. Configure here.

@trueadm
trueadm merged commit 7a39ed5 into octanejs:main Aug 14, 2026
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-authored Diff or issue body substantially produced by an AI agent fix PR: bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants