fix(chart): defer sankey render until container has a non-zero size#83
Open
TomK wants to merge 1 commit into
Open
fix(chart): defer sankey render until container has a non-zero size#83TomK wants to merge 1 commit into
TomK wants to merge 1 commit into
Conversation
ECharts' sankey layout crashes with "Cannot read properties of null (reading '0')" when asked to render into a zero-width or zero-height container (e.g. a chart created inside a hidden tab or a flex/grid cell that has not been laid out yet). bar/line charts tolerate this; sankey does not. zn-chart forces the host height but takes its width from layout, so a sankey chart initialised before its container has a width crashes. Defer setOption until the chart container reports a non-zero size, and let the existing ResizeController trigger the deferred render once the container becomes visible. Route all full-option setOption call sites through the guard. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
A
zn-chart type="sankey"crashes on draw with:The crash is not caused by the chart data (orphan nodes, link values, etc.). The trigger is a zero-width or zero-height container at render time. ECharts' bar/line layouts tolerate a zero-size container; the sankey layout does not — it builds a degenerate coordinate system and reads
null[0]in_updateViewCoordSys, matching the reported stack trace.zn-chartforces the host height (default 300px) but takes its width from layout. So when a sankey chart initialises inside a hidden tab or a flex/grid cell that has not been laid out yet, width is0and it crashes.Fix
Defer
setOptionuntil the chart container reports a non-zero size:renderChart()guard — if width or height is0, markpendingRenderand skip; otherwise apply the option.ResizeControllertriggers the deferred render once the container gains a size (e.g. a hidden tab becomes visible).setOptioncall sites (init, live updates, attribute changes) routed through the guard.No behaviour change for charts that already have a sized container.
Test plan
width:0/height:300pxcontainer threwCannot read properties of null (reading '0'); bar and line charts in the same container rendered fine.width:0defers without throwing (pendingRender=true), and after the container is given a width theResizeObserverfires and the chart renders (series.length > 0) with no page errors.chart.test.ts(does not crash when a sankey chart starts in a zero-width container).tsc --noEmitpasses; no new lint errors introduced.Notes for reviewer
dist/zn.min.js, so the new regression test only exercises this fix after adistrebuild. I did not rebuilddistin this PR because the production build currently fails on an unrelated, pre-existing error (markdown-editor.component.ts(282,53): Property 'description' does not exist on type 'ZnMarkdownEditor'). That should be addressed separately before the next bundle is cut.🤖 Generated with Claude Code