Skip to content

fix(core): make getConnectedDataURL opts optional - #21736

Open
SEPURI-SAI-KRISHNA wants to merge 1 commit into
apache:masterfrom
SEPURI-SAI-KRISHNA:fix/get-connected-dataurl-optional-opts
Open

fix(core): make getConnectedDataURL opts optional#21736
SEPURI-SAI-KRISHNA wants to merge 1 commit into
apache:masterfrom
SEPURI-SAI-KRISHNA:fix/get-connected-dataurl-optional-opts

Conversation

@SEPURI-SAI-KRISHNA

Copy link
Copy Markdown

Brief Information

This pull request is in the type of:

  • bug fixing
  • new feature
  • others

What does this PR do?

Makes the opts argument of echartsInstance.getConnectedDataURL actually optional, as the rest of the method already assumes.

Fixed issues

Details

Before: What was the problem?

Calling the documented public API with no argument always threw:

chart.getConnectedDataURL();
TypeError: Cannot read properties of undefined (reading 'type')
    at ECharts.getConnectedDataURL (src/core/echarts.ts:1026)

opts is declared optional and every other read of it inside the method is written
defensively, but the very first read is not:

getConnectedDataURL(opts?: {...}): string {
    // ...
    const isSvg = opts.type === 'svg';                             // <- throws
    // ...
    const dpr = (opts && opts.pixelRatio) || this.getDevicePixelRatio();   // guarded
    // ...
    return targetCanvas.toDataURL('image/' + (opts && opts.type || 'png'));// guarded
    // ...
    return this.getDataURL(opts);   // getDataURL does `opts = opts || {}`
}

So the method is internally inconsistent: the opts && guards further down and the
delegation to getDataURL (which normalizes opts itself) are unreachable for a
no-argument call, because line 1026 has already thrown. The failure does not depend
on whether the chart is connected, on the renderer, or on the environment.

After: How does it behave after the fixing?

opts is normalized once at the top, mirroring getDataURL:

opts = opts || {};

getConnectedDataURL(), getConnectedDataURL(undefined) and
getConnectedDataURL({...}) all behave as documented. The existing opts && ...
reads are left alone — they are now simply redundant rather than load-bearing.

Document Info

One of the following should be checked.

  • This PR doesn't relate to document changes
  • The document should be updated later
  • The document changes have been made in apache/echarts-doc#xxx

Misc

Security Checking

  • This PR uses security-sensitive Web APIs.

ZRender Changes

  • This PR depends on ZRender changes (ecomfe/zrender#xxx).

Related test cases or examples to use the new APIs

Added test/ut/spec/api/getConnectedDataURL.test.ts: no argument, explicit
undefined, and an explicit options object. The first two fail on master; the
third passes before and after and is kept as a control.

npm run test, npx tsc --noEmit and eslint on the changed file all pass.

Merging options

  • Please squash the commits into a single one when merging.

Other information

This is a different problem from #19278, which is about the SVG branch of the same
method; this PR does not address that issue.

@echarts-bot

echarts-bot Bot commented Aug 15, 2026

Copy link
Copy Markdown

Thanks for your contribution!
The community will review it ASAP. In the meanwhile, please checkout the coding standard and Wiki about How to make a pull request.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant