From f5276fc91637be92c1f3a8ef60370509d59004a7 Mon Sep 17 00:00:00 2001 From: Tanner Linsley Date: Fri, 16 Oct 2026 17:47:25 -0600 Subject: [PATCH 01/10] fix: preserve newest render during presentation re-entry --- .changeset/presentation-subscriber-reentry.md | 5 + benchmarks/comparison/bundle-baseline.json | 4 +- benchmarks/conformance/previews/manifest.json | 2 +- docs/comparison.md | 4 +- packages/charts-core/docs/comparison.md | 4 +- packages/charts-core/src/motion.test.ts | 77 +++++++ packages/charts-core/src/motion.ts | 205 ++++++++++-------- scripts/measure-bundles.mjs | 2 +- 8 files changed, 202 insertions(+), 101 deletions(-) create mode 100644 .changeset/presentation-subscriber-reentry.md diff --git a/.changeset/presentation-subscriber-reentry.md b/.changeset/presentation-subscriber-reentry.md new file mode 100644 index 00000000..39cdc140 --- /dev/null +++ b/.changeset/presentation-subscriber-reentry.md @@ -0,0 +1,5 @@ +--- +'@tanstack/charts': patch +--- + +Keep presentation subscribers and animation completion on the newest scene when a subscriber renders another scene. diff --git a/benchmarks/comparison/bundle-baseline.json b/benchmarks/comparison/bundle-baseline.json index bc22e4f0..ef1b050a 100644 --- a/benchmarks/comparison/bundle-baseline.json +++ b/benchmarks/comparison/bundle-baseline.json @@ -11,8 +11,8 @@ "sources": { "tanstack": { "kind": "workspace", - "revision": "69d70960dd6b29f3706a173d348f2fc8271b0dcc", - "inputDigest": "sha256:80f5c5447f39757715be5def33eed28b12869946936369671243436701fb7964" + "revision": "9d806998e0140b87cce44e53e665a4115270c37e", + "inputDigest": "sha256:df88fde6d476b4ebe294c688d0cf692234d8d5aa441f583c6a36c40f5465725c" }, "chartjs": { "kind": "package", diff --git a/benchmarks/conformance/previews/manifest.json b/benchmarks/conformance/previews/manifest.json index 184adbcd..3bd1e964 100644 --- a/benchmarks/conformance/previews/manifest.json +++ b/benchmarks/conformance/previews/manifest.json @@ -2,7 +2,7 @@ "schemaVersion": 1, "width": 288, "height": 192, - "sourceHash": "e62990d1bc2ce6a38a60f900c2f8c32d8048c57ccd11c5be4f8d673ec9fcb9ad", + "sourceHash": "901349e0d4c70f85ace00303b88ca3e643cc2d3d39a14fab7c54b2da6a4be966", "assets": [ { "id": "01-line-gaps", diff --git a/docs/comparison.md b/docs/comparison.md index 61c55ce6..8a3107ac 100644 --- a/docs/comparison.md +++ b/docs/comparison.md @@ -12,14 +12,14 @@ turning untested behavior into a checkmark. | Library | Package | Measured source | | -------------------------------------------------------------------------------------- | -------------------- | ------------------- | -| [TanStack Charts](./overview.md) | `@tanstack/charts` | workspace `69d7096` | +| [TanStack Charts](./overview.md) | `@tanstack/charts` | workspace `9d80699` | | [Chart.js](https://www.chartjs.org/docs/latest/) | `chart.js` | npm `4.5.1` | | [Apache ECharts](https://echarts.apache.org/handbook/en/best-practices/canvas-vs-svg/) | `echarts` | npm `6.1.0` | | [Recharts](https://recharts.github.io/en-US/) | `recharts` | npm `3.10.1` | | [Observable Plot](https://observablehq.com/plot/features/plots) | `@observablehq/plot` | npm `0.6.17` | The competitor versions are exact package pins, not latest versions inferred -at page render time. The measured TanStack workspace revision is `69d7096`. +at page render time. The measured TanStack workspace revision is `9d80699`. ## Capability matrix diff --git a/packages/charts-core/docs/comparison.md b/packages/charts-core/docs/comparison.md index 61c55ce6..8a3107ac 100644 --- a/packages/charts-core/docs/comparison.md +++ b/packages/charts-core/docs/comparison.md @@ -12,14 +12,14 @@ turning untested behavior into a checkmark. | Library | Package | Measured source | | -------------------------------------------------------------------------------------- | -------------------- | ------------------- | -| [TanStack Charts](./overview.md) | `@tanstack/charts` | workspace `69d7096` | +| [TanStack Charts](./overview.md) | `@tanstack/charts` | workspace `9d80699` | | [Chart.js](https://www.chartjs.org/docs/latest/) | `chart.js` | npm `4.5.1` | | [Apache ECharts](https://echarts.apache.org/handbook/en/best-practices/canvas-vs-svg/) | `echarts` | npm `6.1.0` | | [Recharts](https://recharts.github.io/en-US/) | `recharts` | npm `3.10.1` | | [Observable Plot](https://observablehq.com/plot/features/plots) | `@observablehq/plot` | npm `0.6.17` | The competitor versions are exact package pins, not latest versions inferred -at page render time. The measured TanStack workspace revision is `69d7096`. +at page render time. The measured TanStack workspace revision is `9d80699`. ## Capability matrix diff --git a/packages/charts-core/src/motion.test.ts b/packages/charts-core/src/motion.test.ts index ef4049b0..519a5a40 100644 --- a/packages/charts-core/src/motion.test.ts +++ b/packages/charts-core/src/motion.test.ts @@ -31,6 +31,83 @@ const rows = [ { id: 'b', category: 'B', value: 80 }, ] +describe('presentation subscriber re-entry', () => { + it.each(['snap', 'initial', 'mid', 'finish', 'cancel'])( + 'keeps the newest render after %s notification re-entry', + (phase) => { + const frames = installManagedFrames() + const makeScene = (revision: number) => + createChartScene( + defineChart({ + marks: [dot([{ x: 1, y: revision, revision }], { x: 'x', y: 'y' })], + scales: { + x: { scale: scaleLinear().domain([0, 2]) }, + y: { scale: scaleLinear().domain([0, 4]) }, + }, + guides: false, + }), + { width: 400, height: 200 }, + ) + const container = document.createElement('div') + const surface = motion<{ x: number; y: number; revision: number }>({ + initial: false, + transition: { + type: 'tween', + duration: phase === 'snap' ? 0 : 100, + easing: 'linear', + }, + }).mount(container, () => {}) + const third = makeScene(3) + let armed = phase === 'snap' || phase === 'initial' + let reentered = false + const observations: number[] = [] + try { + surface.render(makeScene(1), { ariaLabel: 'one' }) + surface.subscribePresentationPoints?.((points) => { + if (armed && !reentered && points[0]?.datum.revision === 2) { + reentered = true + surface.render(third, { ariaLabel: 'three' }) + } + }) + surface.subscribePresentationPoints?.((points) => { + observations.push(points[0]!.datum.revision) + }) + surface.render(makeScene(2), { ariaLabel: 'two' }) + if (phase === 'cancel') { + armed = true + surface.render(makeScene(4), { ariaLabel: 'four' }) + } + if (phase !== 'snap') { + frames.run(0) + if (phase === 'mid') armed = true + frames.run(50) + armed = true + frames.run(100) + if (frames.pending()) frames.run(200) + if (frames.pending()) frames.run(400) + } + const expected = phase === 'cancel' ? 4 : 3 + expect(reentered).toBe(phase !== 'cancel') + expect(observations).toContain(expected) + expect( + observations.slice(observations.indexOf(expected)), + ).not.toContain(2) + expect(container.querySelector('svg')?.getAttribute('aria-label')).toBe( + phase === 'cancel' ? 'four' : 'three', + ) + expect(surface.getPresentationPoints?.()).toBeUndefined() + expect( + Number(container.querySelector('circle')?.getAttribute('cy')), + ).toBeCloseTo(makeScene(expected).points[0]!.y) + } finally { + surface.destroy() + expect(frames.pending()).toBe(0) + frames.restore() + } + }, + ) +}) + describe('motion resize policy', () => { it.each([false, true])( 'handles a resize during entrance with resize: %s', diff --git a/packages/charts-core/src/motion.ts b/packages/charts-core/src/motion.ts index a0656cb3..2676dfc0 100644 --- a/packages/charts-core/src/motion.ts +++ b/packages/charts-core/src/motion.ts @@ -828,6 +828,7 @@ function createMotionSvgChartRenderer< let stateTransitions: Readonly> | undefined let stateScene: ChartScene | undefined + let rendering = false let dataMotionRevision = 0 let dataMotionActive = false let stateFlushQueued = false @@ -861,7 +862,12 @@ function createMotionSvgChartRenderer< points: readonly ChartPoint[], ) => { presentationPoints = points - for (const listener of presentationListeners) listener(points) + if (rendering) return + const revision = dataMotionRevision + for (const listener of presentationListeners) { + if (revision !== dataMotionRevision) break + listener(points) + } } const queuePendingStateFocus = () => { if (stateFlushQueued || !pendingStateFocus) return @@ -953,105 +959,116 @@ function createMotionSvgChartRenderer< }) return presented.scene } + function renderScene( + nextScene: ChartScene, + options: ChartSurfaceRenderOptions, + ) { + const previousScene = scene + const initial = previousScene === undefined + const resized = Boolean( + previousScene && + (previousScene.width !== nextScene.width || + previousScene.height !== nextScene.height), + ) + const reduced = + motion.respectReducedMotion && + (container.ownerDocument.defaultView?.matchMedia?.( + '(prefers-reduced-motion: reduce)', + ).matches ?? + false) + const animate = + !reduced && + (initial + ? motion.initial && (!adoptedRoot || motion.initial === 'always') + : motion.resize || !resized) + const viewportMoved = Boolean( + previousScene && viewportTranslationChanged(previousScene, nextScene), + ) + const markup = renderSvg(nextScene, options) + cancelAnimation() + const previousPresentation = + presentationPoints ?? previousScene?.points ?? [] + cancelFocusAnimation() + cancelFocusAnimation = () => {} + const retainsFocusGuideLayers = Boolean( + previousScene?.focusGuides?.length, + ) + const focusGuideLayers = retainsFocusGuideLayers + ? detachSvgFocusGuideLayers(svgElement()) + : {} + for (const placement of visibleFocusGuides) { + if ( + !nextScene.focusGuides?.some( + (guide) => guide.placement === placement, + ) + ) { + visibleFocusGuides.delete(placement) + } + } + const revision = ++dataMotionRevision + stateScene = undefined + stateTransition = undefined + scene = nextScene + renderOptions = options + dataMotionActive = animate && !viewportMoved + pendingStateFocus = dataMotionActive ? desiredStateFocus : undefined + if (animate && !viewportMoved) { + if (initial) reconcileChartSvg(container, markup) + cancelAnimation = motion.animateSvg({ + container, + scene: nextScene as ChartScene, + previousScene: previousScene as ChartScene | undefined, + presentationPoints: + previousPresentation as readonly ChartPoint[], + markup, + phase: initial ? 'initial' : 'update', + setPresentationPoints(points) { + publishPresentationPoints( + points as readonly ChartPoint[], + ) + if ( + revision === dataMotionRevision && + points === nextScene.points + ) { + dataMotionActive = false + queuePendingStateFocus() + } + }, + }) + } else { + reconcileChartSvg(container, markup) + publishPresentationPoints(nextScene.points) + dataMotionActive = false + } + if (retainsFocusGuideLayers) { + restoreSvgFocusGuideLayers( + svgElement(), + focusGuideLayers, + (placement) => + nextScene.focusGuides?.some( + (guide) => guide.placement === placement, + ) === true, + ) + } + scene = nextScene + stateScene = undefined + renderOptions = options + stateTransition = undefined + stateTransitions = undefined + } const surface: ChartSurface = { renderer: ownerRenderer ?? renderer, get element() { return svgElement() }, render(nextScene, options) { - const previousScene = scene - const initial = previousScene === undefined - const resized = Boolean( - previousScene && - (previousScene.width !== nextScene.width || - previousScene.height !== nextScene.height), - ) - const reduced = - motion.respectReducedMotion && - (container.ownerDocument.defaultView?.matchMedia?.( - '(prefers-reduced-motion: reduce)', - ).matches ?? - false) - const animate = - !reduced && - (initial - ? motion.initial && (!adoptedRoot || motion.initial === 'always') - : motion.resize || !resized) - const viewportMoved = Boolean( - previousScene && - viewportTranslationChanged(previousScene, nextScene), - ) - const markup = renderSvg(nextScene, options) - cancelAnimation() - const previousPresentation = - presentationPoints ?? previousScene?.points ?? [] - cancelFocusAnimation() - cancelFocusAnimation = () => {} - const retainsFocusGuideLayers = Boolean( - previousScene?.focusGuides?.length, - ) - const focusGuideLayers = retainsFocusGuideLayers - ? detachSvgFocusGuideLayers(svgElement()) - : {} - for (const placement of visibleFocusGuides) { - if ( - !nextScene.focusGuides?.some( - (guide) => guide.placement === placement, - ) - ) { - visibleFocusGuides.delete(placement) - } - } - const revision = ++dataMotionRevision - stateScene = undefined - stateTransition = undefined - scene = nextScene - renderOptions = options - dataMotionActive = animate && !viewportMoved - pendingStateFocus = dataMotionActive ? desiredStateFocus : undefined - if (animate && !viewportMoved) { - if (initial) reconcileChartSvg(container, markup) - cancelAnimation = motion.animateSvg({ - container, - scene: nextScene as ChartScene, - previousScene: previousScene as ChartScene | undefined, - presentationPoints: - previousPresentation as readonly ChartPoint[], - markup, - phase: initial ? 'initial' : 'update', - setPresentationPoints(points) { - publishPresentationPoints( - points as readonly ChartPoint[], - ) - if ( - revision === dataMotionRevision && - points === nextScene.points - ) { - dataMotionActive = false - queuePendingStateFocus() - } - }, - }) - } else { - reconcileChartSvg(container, markup) - publishPresentationPoints(nextScene.points) - dataMotionActive = false - } - if (retainsFocusGuideLayers) { - restoreSvgFocusGuideLayers( - svgElement(), - focusGuideLayers, - (placement) => - nextScene.focusGuides?.some( - (guide) => guide.placement === placement, - ) === true, - ) + rendering = true + try { + renderScene(nextScene, options) + } finally { + rendering = false } - scene = nextScene - stateScene = undefined - renderOptions = options - stateTransition = undefined - stateTransitions = undefined + if (presentationPoints) publishPresentationPoints(presentationPoints) }, clientToScene(currentScene, clientX, clientY) { return svgClientToScene(svgElement(), currentScene, clientX, clientY) @@ -3994,6 +4011,7 @@ function runTracks( } } lifecycle.publish?.() + if (cancelled) return root.dataset.tsMotionProgress = String(finished.size / activeTracks.length) if (finished.size < activeTracks.length && elapsed < safetyLimit) { frame = view.requestAnimationFrame(tick) @@ -4003,6 +4021,7 @@ function runTracks( if (!finished.has(track)) completeMotionTrack(track) } lifecycle.finish?.() + if (cancelled) return root.dataset.tsMotionState = 'finished' root.dataset.tsMotionProgress = '1' } diff --git a/scripts/measure-bundles.mjs b/scripts/measure-bundles.mjs index 3026af4a..7f7f784d 100644 --- a/scripts/measure-bundles.mjs +++ b/scripts/measure-bundles.mjs @@ -1789,7 +1789,7 @@ const entries = [ budgeted( 'Motion SVG renderer', 'benchmarks/entries/charts-motion-svg-renderer.ts', - 23_240 / 1024, + 23_286 / 1024, { rendererBoundary: 'svg', inputBoundary: { From 233d29b4fc28ef49acd9517fb3e1dd872cd3759b Mon Sep 17 00:00:00 2001 From: Tanner Linsley Date: Tue, 3 Nov 2026 22:26:36 -0700 Subject: [PATCH 02/10] fix: preserve the latest render during presentation subscriber re-entry --- .changeset/presentation-subscriber-reentry.md | 5 + packages/charts-core/src/motion.test.ts | 126 +++++++++++ packages/charts-core/src/motion.ts | 205 ++++++++++-------- 3 files changed, 243 insertions(+), 93 deletions(-) create mode 100644 .changeset/presentation-subscriber-reentry.md diff --git a/.changeset/presentation-subscriber-reentry.md b/.changeset/presentation-subscriber-reentry.md new file mode 100644 index 00000000..39cdc140 --- /dev/null +++ b/.changeset/presentation-subscriber-reentry.md @@ -0,0 +1,5 @@ +--- +'@tanstack/charts': patch +--- + +Keep presentation subscribers and animation completion on the newest scene when a subscriber renders another scene. diff --git a/packages/charts-core/src/motion.test.ts b/packages/charts-core/src/motion.test.ts index ef4049b0..a00b58db 100644 --- a/packages/charts-core/src/motion.test.ts +++ b/packages/charts-core/src/motion.test.ts @@ -31,6 +31,132 @@ const rows = [ { id: 'b', category: 'B', value: 80 }, ] +describe('presentation subscriber re-entry', () => { + it('defers notifications while a motion callback nests a render', () => { + const frames = installManagedFrames() + const container = document.createElement('div') + const surface = motion<{ x: number; y: number }>({ initial: false }).mount( + container, + () => {}, + ) + let armed = false + let insideCallback = false + const observedInside: boolean[] = [] + const makeScene = (value: number) => + createChartScene( + defineChart({ + marks: [ + dot([{ x: 1, y: value }], { + x: 'x', + y: 'y', + motion: () => { + if (armed) { + armed = false + insideCallback = true + surface.render(makeScene(3), { ariaLabel: 'three' }) + insideCallback = false + } + return { transition: { type: 'tween', duration: 100 } } + }, + }), + ], + scales: { + x: { scale: scaleLinear().domain([0, 2]) }, + y: { scale: scaleLinear().domain([0, 4]) }, + }, + guides: false, + }), + { width: 400, height: 200 }, + ) + try { + surface.render(makeScene(1), { ariaLabel: 'one' }) + surface.subscribePresentationPoints?.(() => + observedInside.push(insideCallback), + ) + armed = true + surface.render(makeScene(2), { ariaLabel: 'two' }) + expect(observedInside).not.toContain(true) + } finally { + surface.destroy() + frames.restore() + } + }) + it.each(['snap', 'initial', 'mid', 'finish', 'cancel'])( + 'keeps the newest render after %s notification re-entry', + (phase) => { + const frames = installManagedFrames() + const makeScene = (revision: number) => + createChartScene( + defineChart({ + marks: [dot([{ x: 1, y: revision, revision }], { x: 'x', y: 'y' })], + scales: { + x: { scale: scaleLinear().domain([0, 2]) }, + y: { scale: scaleLinear().domain([0, 4]) }, + }, + guides: false, + }), + { width: 400, height: 200 }, + ) + const container = document.createElement('div') + const surface = motion<{ x: number; y: number; revision: number }>({ + initial: false, + transition: { + type: 'tween', + duration: phase === 'snap' ? 0 : 100, + easing: 'linear', + }, + }).mount(container, () => {}) + const third = makeScene(3) + let armed = phase === 'snap' || phase === 'initial' + let reentered = false + const observations: number[] = [] + try { + surface.render(makeScene(1), { ariaLabel: 'one' }) + surface.subscribePresentationPoints?.((points) => { + if (armed && !reentered && points[0]?.datum.revision === 2) { + reentered = true + surface.render(third, { ariaLabel: 'three' }) + } + }) + surface.subscribePresentationPoints?.((points) => { + observations.push(points[0]!.datum.revision) + }) + surface.render(makeScene(2), { ariaLabel: 'two' }) + if (phase === 'cancel') { + armed = true + surface.render(makeScene(4), { ariaLabel: 'four' }) + } + if (phase !== 'snap') { + frames.run(0) + if (phase === 'mid') armed = true + frames.run(50) + armed = true + frames.run(100) + if (frames.pending()) frames.run(200) + if (frames.pending()) frames.run(400) + } + const expected = phase === 'cancel' ? 4 : 3 + expect(reentered).toBe(phase !== 'cancel') + expect(observations).toContain(expected) + expect( + observations.slice(observations.indexOf(expected)), + ).not.toContain(2) + expect(container.querySelector('svg')?.getAttribute('aria-label')).toBe( + phase === 'cancel' ? 'four' : 'three', + ) + expect(surface.getPresentationPoints?.()).toBeUndefined() + expect( + Number(container.querySelector('circle')?.getAttribute('cy')), + ).toBeCloseTo(makeScene(expected).points[0]!.y) + } finally { + surface.destroy() + expect(frames.pending()).toBe(0) + frames.restore() + } + }, + ) +}) + describe('motion resize policy', () => { it.each([false, true])( 'handles a resize during entrance with resize: %s', diff --git a/packages/charts-core/src/motion.ts b/packages/charts-core/src/motion.ts index a0656cb3..382a6c4d 100644 --- a/packages/charts-core/src/motion.ts +++ b/packages/charts-core/src/motion.ts @@ -828,6 +828,7 @@ function createMotionSvgChartRenderer< let stateTransitions: Readonly> | undefined let stateScene: ChartScene | undefined + let rendering = 0 let dataMotionRevision = 0 let dataMotionActive = false let stateFlushQueued = false @@ -861,7 +862,12 @@ function createMotionSvgChartRenderer< points: readonly ChartPoint[], ) => { presentationPoints = points - for (const listener of presentationListeners) listener(points) + if (rendering) return + const revision = dataMotionRevision + for (const listener of presentationListeners) { + if (revision !== dataMotionRevision) break + listener(points) + } } const queuePendingStateFocus = () => { if (stateFlushQueued || !pendingStateFocus) return @@ -953,105 +959,116 @@ function createMotionSvgChartRenderer< }) return presented.scene } + function renderScene( + nextScene: ChartScene, + options: ChartSurfaceRenderOptions, + ) { + const previousScene = scene + const initial = previousScene === undefined + const resized = Boolean( + previousScene && + (previousScene.width !== nextScene.width || + previousScene.height !== nextScene.height), + ) + const reduced = + motion.respectReducedMotion && + (container.ownerDocument.defaultView?.matchMedia?.( + '(prefers-reduced-motion: reduce)', + ).matches ?? + false) + const animate = + !reduced && + (initial + ? motion.initial && (!adoptedRoot || motion.initial === 'always') + : motion.resize || !resized) + const viewportMoved = Boolean( + previousScene && viewportTranslationChanged(previousScene, nextScene), + ) + const markup = renderSvg(nextScene, options) + cancelAnimation() + const previousPresentation = + presentationPoints ?? previousScene?.points ?? [] + cancelFocusAnimation() + cancelFocusAnimation = () => {} + const retainsFocusGuideLayers = Boolean( + previousScene?.focusGuides?.length, + ) + const focusGuideLayers = retainsFocusGuideLayers + ? detachSvgFocusGuideLayers(svgElement()) + : {} + for (const placement of visibleFocusGuides) { + if ( + !nextScene.focusGuides?.some( + (guide) => guide.placement === placement, + ) + ) { + visibleFocusGuides.delete(placement) + } + } + const revision = ++dataMotionRevision + stateScene = undefined + stateTransition = undefined + scene = nextScene + renderOptions = options + dataMotionActive = animate && !viewportMoved + pendingStateFocus = dataMotionActive ? desiredStateFocus : undefined + if (animate && !viewportMoved) { + if (initial) reconcileChartSvg(container, markup) + cancelAnimation = motion.animateSvg({ + container, + scene: nextScene as ChartScene, + previousScene: previousScene as ChartScene | undefined, + presentationPoints: + previousPresentation as readonly ChartPoint[], + markup, + phase: initial ? 'initial' : 'update', + setPresentationPoints(points) { + publishPresentationPoints( + points as readonly ChartPoint[], + ) + if ( + revision === dataMotionRevision && + points === nextScene.points + ) { + dataMotionActive = false + queuePendingStateFocus() + } + }, + }) + } else { + reconcileChartSvg(container, markup) + publishPresentationPoints(nextScene.points) + dataMotionActive = false + } + if (retainsFocusGuideLayers) { + restoreSvgFocusGuideLayers( + svgElement(), + focusGuideLayers, + (placement) => + nextScene.focusGuides?.some( + (guide) => guide.placement === placement, + ) === true, + ) + } + scene = nextScene + stateScene = undefined + renderOptions = options + stateTransition = undefined + stateTransitions = undefined + } const surface: ChartSurface = { renderer: ownerRenderer ?? renderer, get element() { return svgElement() }, render(nextScene, options) { - const previousScene = scene - const initial = previousScene === undefined - const resized = Boolean( - previousScene && - (previousScene.width !== nextScene.width || - previousScene.height !== nextScene.height), - ) - const reduced = - motion.respectReducedMotion && - (container.ownerDocument.defaultView?.matchMedia?.( - '(prefers-reduced-motion: reduce)', - ).matches ?? - false) - const animate = - !reduced && - (initial - ? motion.initial && (!adoptedRoot || motion.initial === 'always') - : motion.resize || !resized) - const viewportMoved = Boolean( - previousScene && - viewportTranslationChanged(previousScene, nextScene), - ) - const markup = renderSvg(nextScene, options) - cancelAnimation() - const previousPresentation = - presentationPoints ?? previousScene?.points ?? [] - cancelFocusAnimation() - cancelFocusAnimation = () => {} - const retainsFocusGuideLayers = Boolean( - previousScene?.focusGuides?.length, - ) - const focusGuideLayers = retainsFocusGuideLayers - ? detachSvgFocusGuideLayers(svgElement()) - : {} - for (const placement of visibleFocusGuides) { - if ( - !nextScene.focusGuides?.some( - (guide) => guide.placement === placement, - ) - ) { - visibleFocusGuides.delete(placement) - } - } - const revision = ++dataMotionRevision - stateScene = undefined - stateTransition = undefined - scene = nextScene - renderOptions = options - dataMotionActive = animate && !viewportMoved - pendingStateFocus = dataMotionActive ? desiredStateFocus : undefined - if (animate && !viewportMoved) { - if (initial) reconcileChartSvg(container, markup) - cancelAnimation = motion.animateSvg({ - container, - scene: nextScene as ChartScene, - previousScene: previousScene as ChartScene | undefined, - presentationPoints: - previousPresentation as readonly ChartPoint[], - markup, - phase: initial ? 'initial' : 'update', - setPresentationPoints(points) { - publishPresentationPoints( - points as readonly ChartPoint[], - ) - if ( - revision === dataMotionRevision && - points === nextScene.points - ) { - dataMotionActive = false - queuePendingStateFocus() - } - }, - }) - } else { - reconcileChartSvg(container, markup) - publishPresentationPoints(nextScene.points) - dataMotionActive = false - } - if (retainsFocusGuideLayers) { - restoreSvgFocusGuideLayers( - svgElement(), - focusGuideLayers, - (placement) => - nextScene.focusGuides?.some( - (guide) => guide.placement === placement, - ) === true, - ) + rendering += 1 + try { + renderScene(nextScene, options) + } finally { + rendering -= 1 } - scene = nextScene - stateScene = undefined - renderOptions = options - stateTransition = undefined - stateTransitions = undefined + if (presentationPoints) publishPresentationPoints(presentationPoints) }, clientToScene(currentScene, clientX, clientY) { return svgClientToScene(svgElement(), currentScene, clientX, clientY) @@ -3994,6 +4011,7 @@ function runTracks( } } lifecycle.publish?.() + if (cancelled) return root.dataset.tsMotionProgress = String(finished.size / activeTracks.length) if (finished.size < activeTracks.length && elapsed < safetyLimit) { frame = view.requestAnimationFrame(tick) @@ -4003,6 +4021,7 @@ function runTracks( if (!finished.has(track)) completeMotionTrack(track) } lifecycle.finish?.() + if (cancelled) return root.dataset.tsMotionState = 'finished' root.dataset.tsMotionProgress = '1' } From 2e7dc38ee310688452f54c2c440f813fee3dae7c Mon Sep 17 00:00:00 2001 From: Tanner Linsley Date: Tue, 3 Nov 2026 22:37:59 -0700 Subject: [PATCH 03/10] chore: record approved subscriber correction bundle measurements --- benchmarks/comparison/bundle-baseline.json | 4 ++-- benchmarks/conformance/previews/manifest.json | 2 +- docs/comparison.md | 4 ++-- packages/charts-core/docs/comparison.md | 4 ++-- scripts/measure-bundles.mjs | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/benchmarks/comparison/bundle-baseline.json b/benchmarks/comparison/bundle-baseline.json index 85b85d85..9c9f70e8 100644 --- a/benchmarks/comparison/bundle-baseline.json +++ b/benchmarks/comparison/bundle-baseline.json @@ -11,8 +11,8 @@ "sources": { "tanstack": { "kind": "workspace", - "revision": "c6f214c5ec07e6795948373d9f1180620e7c7201", - "inputDigest": "sha256:b5b15f9b76251512fbd07e610230c361e8f26d4c2c1ee465d58bddaf7cca061d" + "revision": "92e0801c28415cbedd85f677d29598f90fb0fd31", + "inputDigest": "sha256:f10c7eef40f5970f90b33c27d99555ac9290300a0b570ffda61403f2372f7f61" }, "chartjs": { "kind": "package", diff --git a/benchmarks/conformance/previews/manifest.json b/benchmarks/conformance/previews/manifest.json index 6cbf633c..52512ba4 100644 --- a/benchmarks/conformance/previews/manifest.json +++ b/benchmarks/conformance/previews/manifest.json @@ -2,7 +2,7 @@ "schemaVersion": 1, "width": 288, "height": 192, - "sourceHash": "0a9bce517636862b84f408fe6efd422af1785018a4f7da10a1fd53964ee5ee2e", + "sourceHash": "4d24007b5db8817671c815c5351fba8d43d33716a9415f4c11e71021d9ed9510", "assets": [ { "id": "01-line-gaps", diff --git a/docs/comparison.md b/docs/comparison.md index 3b65b8d5..cee27270 100644 --- a/docs/comparison.md +++ b/docs/comparison.md @@ -12,14 +12,14 @@ turning untested behavior into a checkmark. | Library | Package | Measured source | | -------------------------------------------------------------------------------------- | -------------------- | ------------------- | -| [TanStack Charts](./overview.md) | `@tanstack/charts` | workspace `c6f214c` | +| [TanStack Charts](./overview.md) | `@tanstack/charts` | workspace `92e0801` | | [Chart.js](https://www.chartjs.org/docs/latest/) | `chart.js` | npm `4.5.1` | | [Apache ECharts](https://echarts.apache.org/handbook/en/best-practices/canvas-vs-svg/) | `echarts` | npm `6.1.0` | | [Recharts](https://recharts.github.io/en-US/) | `recharts` | npm `3.10.1` | | [Observable Plot](https://observablehq.com/plot/features/plots) | `@observablehq/plot` | npm `0.6.17` | The competitor versions are exact package pins, not latest versions inferred -at page render time. The measured TanStack workspace revision is `c6f214c`. +at page render time. The measured TanStack workspace revision is `92e0801`. ## Capability matrix diff --git a/packages/charts-core/docs/comparison.md b/packages/charts-core/docs/comparison.md index 3b65b8d5..cee27270 100644 --- a/packages/charts-core/docs/comparison.md +++ b/packages/charts-core/docs/comparison.md @@ -12,14 +12,14 @@ turning untested behavior into a checkmark. | Library | Package | Measured source | | -------------------------------------------------------------------------------------- | -------------------- | ------------------- | -| [TanStack Charts](./overview.md) | `@tanstack/charts` | workspace `c6f214c` | +| [TanStack Charts](./overview.md) | `@tanstack/charts` | workspace `92e0801` | | [Chart.js](https://www.chartjs.org/docs/latest/) | `chart.js` | npm `4.5.1` | | [Apache ECharts](https://echarts.apache.org/handbook/en/best-practices/canvas-vs-svg/) | `echarts` | npm `6.1.0` | | [Recharts](https://recharts.github.io/en-US/) | `recharts` | npm `3.10.1` | | [Observable Plot](https://observablehq.com/plot/features/plots) | `@observablehq/plot` | npm `0.6.17` | The competitor versions are exact package pins, not latest versions inferred -at page render time. The measured TanStack workspace revision is `c6f214c`. +at page render time. The measured TanStack workspace revision is `92e0801`. ## Capability matrix diff --git a/scripts/measure-bundles.mjs b/scripts/measure-bundles.mjs index 214edb30..db3bbc27 100644 --- a/scripts/measure-bundles.mjs +++ b/scripts/measure-bundles.mjs @@ -1789,7 +1789,7 @@ const entries = [ budgeted( 'Motion SVG renderer', 'benchmarks/entries/charts-motion-svg-renderer.ts', - 23_240 / 1024, + 23_289 / 1024, { rendererBoundary: 'svg', inputBoundary: { From f15ef90a655c9c87d8be34f7cdf00bdfb0a0243a Mon Sep 17 00:00:00 2001 From: Tanner Linsley Date: Thu, 5 Nov 2026 17:15:27 -0700 Subject: [PATCH 04/10] fix: preserve nested presentation updates --- packages/charts-core/src/motion.test.ts | 8 ++++++++ packages/charts-core/src/motion.ts | 12 ++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/packages/charts-core/src/motion.test.ts b/packages/charts-core/src/motion.test.ts index a00b58db..a31806ed 100644 --- a/packages/charts-core/src/motion.test.ts +++ b/packages/charts-core/src/motion.test.ts @@ -76,6 +76,14 @@ describe('presentation subscriber re-entry', () => { armed = true surface.render(makeScene(2), { ariaLabel: 'two' }) expect(observedInside).not.toContain(true) + frames.run(0) + frames.run(100) + expect(container.querySelector('svg')?.getAttribute('aria-label')).toBe( + 'three', + ) + expect( + Number(container.querySelector('circle')?.getAttribute('cy')), + ).toBeCloseTo(makeScene(3).points[0]!.y) } finally { surface.destroy() frames.restore() diff --git a/packages/charts-core/src/motion.ts b/packages/charts-core/src/motion.ts index 382a6c4d..6131c008 100644 --- a/packages/charts-core/src/motion.ts +++ b/packages/charts-core/src/motion.ts @@ -1014,7 +1014,7 @@ function createMotionSvgChartRenderer< pendingStateFocus = dataMotionActive ? desiredStateFocus : undefined if (animate && !viewportMoved) { if (initial) reconcileChartSvg(container, markup) - cancelAnimation = motion.animateSvg({ + const cancel = motion.animateSvg({ container, scene: nextScene as ChartScene, previousScene: previousScene as ChartScene | undefined, @@ -1023,18 +1023,21 @@ function createMotionSvgChartRenderer< markup, phase: initial ? 'initial' : 'update', setPresentationPoints(points) { + if (revision !== dataMotionRevision) return publishPresentationPoints( points as readonly ChartPoint[], ) if ( - revision === dataMotionRevision && - points === nextScene.points + points === nextScene.points && + revision === dataMotionRevision ) { dataMotionActive = false queuePendingStateFocus() } }, }) + if (revision === dataMotionRevision) cancelAnimation = cancel + else cancel() } else { reconcileChartSvg(container, markup) publishPresentationPoints(nextScene.points) @@ -1045,11 +1048,12 @@ function createMotionSvgChartRenderer< svgElement(), focusGuideLayers, (placement) => - nextScene.focusGuides?.some( + scene?.focusGuides?.some( (guide) => guide.placement === placement, ) === true, ) } + if (revision !== dataMotionRevision) return scene = nextScene stateScene = undefined renderOptions = options From 828b520d7a9c1488a4ab66259162dfe048084acd Mon Sep 17 00:00:00 2001 From: Tanner Linsley Date: Thu, 5 Nov 2026 18:16:00 -0700 Subject: [PATCH 05/10] chore: apply approved presentation correction budget --- scripts/measure-bundles.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/measure-bundles.mjs b/scripts/measure-bundles.mjs index 4d135c8f..567f8fa7 100644 --- a/scripts/measure-bundles.mjs +++ b/scripts/measure-bundles.mjs @@ -1789,7 +1789,7 @@ const entries = [ budgeted( 'Motion SVG renderer', 'benchmarks/entries/charts-motion-svg-renderer.ts', - 23_289 / 1024, + 23_301 / 1024, { rendererBoundary: 'svg', inputBoundary: { From 5f5b3a8233f1a1bd5f30c7ffcab54420c1e8f5e8 Mon Sep 17 00:00:00 2001 From: Tanner Linsley Date: Thu, 5 Nov 2026 19:45:36 -0700 Subject: [PATCH 06/10] chore: refresh verified comparison source fingerprint --- benchmarks/comparison/bundle-baseline.json | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/benchmarks/comparison/bundle-baseline.json b/benchmarks/comparison/bundle-baseline.json index 1129d730..3cec1574 100644 --- a/benchmarks/comparison/bundle-baseline.json +++ b/benchmarks/comparison/bundle-baseline.json @@ -11,8 +11,8 @@ "sources": { "tanstack": { "kind": "workspace", - "revision": "af1fbe696130b86804194b49159d7adca8f4c97e", - "inputDigest": "sha256:d69c77dee8bd32caa953245d7153983aa3fa8520d407c8410b7a19a93287b33a" + "revision": "828b520d7a9c1488a4ab66259162dfe048084acd", + "inputDigest": "sha256:09545bea7164c4cea02bc5e30e48076ba227c1d33643f73ea75de5120c50bdf2" }, "chartjs": { "kind": "package", @@ -36,8 +36,17 @@ } }, "matrix": { - "chartTypes": ["line", "bar", "area", "scatter"], - "tiers": ["basic", "interactive", "advanced"] + "chartTypes": [ + "line", + "bar", + "area", + "scatter" + ], + "tiers": [ + "basic", + "interactive", + "advanced" + ] }, "tolerance": { "relative": 0.03, From ed8828d4a74dbab12fc75e1fe18680bef363245e Mon Sep 17 00:00:00 2001 From: Tanner Linsley Date: Thu, 5 Nov 2026 19:45:57 -0700 Subject: [PATCH 07/10] style: format comparison fingerprint record --- benchmarks/comparison/bundle-baseline.json | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/benchmarks/comparison/bundle-baseline.json b/benchmarks/comparison/bundle-baseline.json index 3cec1574..38798945 100644 --- a/benchmarks/comparison/bundle-baseline.json +++ b/benchmarks/comparison/bundle-baseline.json @@ -36,17 +36,8 @@ } }, "matrix": { - "chartTypes": [ - "line", - "bar", - "area", - "scatter" - ], - "tiers": [ - "basic", - "interactive", - "advanced" - ] + "chartTypes": ["line", "bar", "area", "scatter"], + "tiers": ["basic", "interactive", "advanced"] }, "tolerance": { "relative": 0.03, From dad140371470ca365f1b1bfa7004905cb59956bd Mon Sep 17 00:00:00 2001 From: Tanner Linsley Date: Thu, 5 Nov 2026 20:45:44 -0700 Subject: [PATCH 08/10] chore: synchronize verified presentation fix provenance --- benchmarks/conformance/previews/manifest.json | 2 +- docs/comparison.md | 4 ++-- packages/charts-core/docs/comparison.md | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/benchmarks/conformance/previews/manifest.json b/benchmarks/conformance/previews/manifest.json index a69af0b2..506767e9 100644 --- a/benchmarks/conformance/previews/manifest.json +++ b/benchmarks/conformance/previews/manifest.json @@ -2,7 +2,7 @@ "schemaVersion": 1, "width": 288, "height": 192, - "sourceHash": "b3278434002dbce5d618fa0ef27b126696ab8a3406f37899d6e4492e7c6ab66c", + "sourceHash": "9e3bf0e06796e3f7a4f41dcada68f334a5e38160608e2964900dbb74e3b65970", "assets": [ { "id": "01-line-gaps", diff --git a/docs/comparison.md b/docs/comparison.md index 1ae6e917..c94a28ed 100644 --- a/docs/comparison.md +++ b/docs/comparison.md @@ -12,14 +12,14 @@ turning untested behavior into a checkmark. | Library | Package | Measured source | | -------------------------------------------------------------------------------------- | -------------------- | ------------------- | -| [TanStack Charts](./overview.md) | `@tanstack/charts` | workspace `af1fbe6` | +| [TanStack Charts](./overview.md) | `@tanstack/charts` | workspace `828b520` | | [Chart.js](https://www.chartjs.org/docs/latest/) | `chart.js` | npm `4.5.1` | | [Apache ECharts](https://echarts.apache.org/handbook/en/best-practices/canvas-vs-svg/) | `echarts` | npm `6.1.0` | | [Recharts](https://recharts.github.io/en-US/) | `recharts` | npm `3.10.1` | | [Observable Plot](https://observablehq.com/plot/features/plots) | `@observablehq/plot` | npm `0.6.17` | The competitor versions are exact package pins, not latest versions inferred -at page render time. The measured TanStack workspace revision is `af1fbe6`. +at page render time. The measured TanStack workspace revision is `828b520`. ## Capability matrix diff --git a/packages/charts-core/docs/comparison.md b/packages/charts-core/docs/comparison.md index 1ae6e917..c94a28ed 100644 --- a/packages/charts-core/docs/comparison.md +++ b/packages/charts-core/docs/comparison.md @@ -12,14 +12,14 @@ turning untested behavior into a checkmark. | Library | Package | Measured source | | -------------------------------------------------------------------------------------- | -------------------- | ------------------- | -| [TanStack Charts](./overview.md) | `@tanstack/charts` | workspace `af1fbe6` | +| [TanStack Charts](./overview.md) | `@tanstack/charts` | workspace `828b520` | | [Chart.js](https://www.chartjs.org/docs/latest/) | `chart.js` | npm `4.5.1` | | [Apache ECharts](https://echarts.apache.org/handbook/en/best-practices/canvas-vs-svg/) | `echarts` | npm `6.1.0` | | [Recharts](https://recharts.github.io/en-US/) | `recharts` | npm `3.10.1` | | [Observable Plot](https://observablehq.com/plot/features/plots) | `@observablehq/plot` | npm `0.6.17` | The competitor versions are exact package pins, not latest versions inferred -at page render time. The measured TanStack workspace revision is `af1fbe6`. +at page render time. The measured TanStack workspace revision is `828b520`. ## Capability matrix From e4c0a0c060a1e5894c8d0c28741f26968a6c2b66 Mon Sep 17 00:00:00 2001 From: Tanner Linsley Date: Thu, 5 Nov 2026 22:16:14 -0700 Subject: [PATCH 09/10] docs: align Solid peer requirement with package manifests --- docs/installation.md | 2 +- packages/charts-core/docs/installation.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/installation.md b/docs/installation.md index d735384f..63354ac4 100644 --- a/docs/installation.md +++ b/docs/installation.md @@ -96,7 +96,7 @@ D3 dependency. | `@tanstack/charts/react-native` | React `^19.2.3`, React Native `^0.86.0` or `^0.88.0`, and `react-native-svg` `>=15.15.4 <16` | | `@tanstack/charts/preact` | Preact `>=10` | | `@tanstack/charts/vue` | Vue `>=3.5` | -| `@tanstack/charts/solid` | Solid `>=1.8` | +| `@tanstack/charts/solid` | Solid `^1.8` | | `@tanstack/charts/svelte` | Svelte `^5.20.0` | | `@tanstack/charts/angular` | Angular core and platform browser `>=19` | | `@tanstack/charts/lit` | Lit `>=3.1.3` | diff --git a/packages/charts-core/docs/installation.md b/packages/charts-core/docs/installation.md index d735384f..63354ac4 100644 --- a/packages/charts-core/docs/installation.md +++ b/packages/charts-core/docs/installation.md @@ -96,7 +96,7 @@ D3 dependency. | `@tanstack/charts/react-native` | React `^19.2.3`, React Native `^0.86.0` or `^0.88.0`, and `react-native-svg` `>=15.15.4 <16` | | `@tanstack/charts/preact` | Preact `>=10` | | `@tanstack/charts/vue` | Vue `>=3.5` | -| `@tanstack/charts/solid` | Solid `>=1.8` | +| `@tanstack/charts/solid` | Solid `^1.8` | | `@tanstack/charts/svelte` | Svelte `^5.20.0` | | `@tanstack/charts/angular` | Angular core and platform browser `>=19` | | `@tanstack/charts/lit` | Lit `>=3.1.3` | From 87dbee9f1db3f7839171a73acb1b87333f45e83d Mon Sep 17 00:00:00 2001 From: Tanner Linsley Date: Thu, 5 Nov 2026 23:18:47 -0700 Subject: [PATCH 10/10] docs: format Solid peer requirement table --- docs/installation.md | 2 +- packages/charts-core/docs/installation.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/installation.md b/docs/installation.md index 63354ac4..307c8ad4 100644 --- a/docs/installation.md +++ b/docs/installation.md @@ -96,7 +96,7 @@ D3 dependency. | `@tanstack/charts/react-native` | React `^19.2.3`, React Native `^0.86.0` or `^0.88.0`, and `react-native-svg` `>=15.15.4 <16` | | `@tanstack/charts/preact` | Preact `>=10` | | `@tanstack/charts/vue` | Vue `>=3.5` | -| `@tanstack/charts/solid` | Solid `^1.8` | +| `@tanstack/charts/solid` | Solid `^1.8` | | `@tanstack/charts/svelte` | Svelte `^5.20.0` | | `@tanstack/charts/angular` | Angular core and platform browser `>=19` | | `@tanstack/charts/lit` | Lit `>=3.1.3` | diff --git a/packages/charts-core/docs/installation.md b/packages/charts-core/docs/installation.md index 63354ac4..307c8ad4 100644 --- a/packages/charts-core/docs/installation.md +++ b/packages/charts-core/docs/installation.md @@ -96,7 +96,7 @@ D3 dependency. | `@tanstack/charts/react-native` | React `^19.2.3`, React Native `^0.86.0` or `^0.88.0`, and `react-native-svg` `>=15.15.4 <16` | | `@tanstack/charts/preact` | Preact `>=10` | | `@tanstack/charts/vue` | Vue `>=3.5` | -| `@tanstack/charts/solid` | Solid `^1.8` | +| `@tanstack/charts/solid` | Solid `^1.8` | | `@tanstack/charts/svelte` | Svelte `^5.20.0` | | `@tanstack/charts/angular` | Angular core and platform browser `>=19` | | `@tanstack/charts/lit` | Lit `>=3.1.3` |