Repository navigation
fix(core): getConnectedDataURL works with SVG renderer. close #19278 - #21838
Open
Raman-Katiyar wants to merge 1 commit into
Open
Raman-Katiyar wants to merge 1 commit into
Raman-Katiyar wants to merge 1 commit into
Conversation
|
Thanks for your contribution! Please DO NOT commit the files in dist, i18n, and ssr/client/dist folders in a non-release pull request. These folders are for release use only. |
This branch has not been deployed
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.
Brief Information
This pull request is in the type of:
What does this PR do?
Fixes
getConnectedDataURLthrowing aTypeErrorwhen the connected charts use the SVG renderer.Fixed issues
getConnectedDataURLbroken with SVG renderer #19278:getConnectedDataURLbroken with SVG renderer (TypeError: Cannot set properties of undefined (setting 'innerHTML'))Details
Before: What was the problem?
With two SVG-rendered charts connected via
echarts.connect(), callingchart.getConnectedDataURL({type: 'svg'})threw:Reproduction:
Root cause: in the SVG branch of
getConnectedDataURL, a throwaway zrender instance is created and resized, but never painted beforegetSvgRoot().innerHTMLis written. In zrender's SVG painter,getSvgRoot()returnsthis._mainVNode.elm, and_mainVNodeis only created insiderenderToVNode(), which only runs on paint — sogetSvgRoot()returnedundefinedand the assignment threw.A second, related problem: even if the root existed, the old code finished with
toDataURL(), which re-renders from the (empty) display list of the throwaway instance — so the injected<g>content would have been dropped from the output.After: How does it behave after the fixing?
getConnectedDataURL({type: 'svg'})now returns a validdata:image/svg+xml;charset=UTF-8,...URL containing both connected charts, with the correct combined geometry and the requestedconnectedBackgroundColor.The fix, all inside the SVG branch of
getConnectedDataURL(src/core/echarts.ts):setBackgroundColoris applied first, thenzr.refreshImmediately()is called before writinggetSvgRoot().innerHTML, so the painter's root<g>element exists.toDataURL()(which would re-render from the empty display list and drop the injected content), the composed svg element is serialized directly viagetSvgDom().outerHTML.refresh()leaves on the root element is removed, andviewBoxis set explicitly, so the export matches a plainrenderToSVGString()output. (Removing the attribute from this detached svg element can still leave a stale emptystyle=""behind in the serialized string in some browsers, so that is stripped from the string as well.)No zrender changes are needed — the bug is entirely in how ECharts drives the throwaway instance.
Regression test
New test:
test/ut/spec/api/getConnectedDataURL.test.ts— two SVG bar charts,echarts.connect(), thengetConnectedDataURL({type: 'svg'}); asserts adata:image/svg+xmlURL whose decoded svg contains<svg/</svg>and both chart titles (so the test fails if the content is lost, not just if it throws). A second test coversconnectedBackgroundColor: '#ff0000'.Fail-before (on master, before the fix — Node 14,
npx jest --config test/ut/jest.config.cjs test/ut/spec/api/getConnectedDataURL.test.ts --no-coverage):Pass-after (same command, after the fix):
Validation
npm run build:lib+node build/build.js --type all): two 400×300 SVG charts at x=10 and x=430,connectedBackgroundColor: '#ff0000'. Exported svg: root<svg ... width="820" height="300" viewBox="0 0 820 300">(no straystyleattribute), 2 translate wrapperstranslate(0,0)andtranslate(420,0)(exactly right), both titles present, red background rect present. Rendered as an<img>, the export shows both bar charts side by side with correct bar heights (10/20 against a 0–20 axis, 30/40 against a 0–40 axis). Note: jsdom'sgetBoundingClientRectreturns zeros, so this geometry check was done in a real browser rather than in Jest.npm run checktype— exit 0.npx eslint src/core/echarts.ts test/ut/spec/api/getConnectedDataURL.test.ts— exit 0, no warnings.npx jest --config test/ut/jest.config.cjs test/ut/spec/api --no-coverage— 4 suites passed, 12 tests passed, 0 failures (no regressions ingetVisual,containPixel,converter).src/core/echarts.ts(+23/−3) and the new test file (+104). Nodist/changes (restored before commit, per repo convention).Document Info
One of the following should be checked.
Misc
Security Checking
ZRender Changes
Related test cases or examples to use the new APIs
test/ut/spec/api/getConnectedDataURL.test.ts(new, see above).Merging options
Other information
innerHTMLassignment on the throwaway svg root pre-dates this PR; no new security-sensitive API is introduced (the change only reorders the existing calls and serializes the composed element instead of re-rendering).getConnectedDataURLbroken with SVG renderer #19278 exists: issue [Bug] cannot export two connected charts with svg renderer /getConnectedDataURLbroken with SVG renderer #19278 is still open, and the only PR referencing it is fix(core): makes theoptsargument ofechartsInstance.getConnectedDataURLoptional #21736 (closed/merged 14 Sep 2026, "makes theoptsargument ofechartsInstance.getConnectedDataURLoptional") — a different, adjacent fix; the crash persists on master.