Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): fix potential NPE when reading default init options from global object in dev environment #19217

Merged
merged 3 commits into from
Oct 18, 2023

Conversation

sunpm
Copy link
Contributor

@sunpm sunpm commented Oct 17, 2023

Brief Information

This pull request is in the type of:

  • bug fixing
  • new feature
  • others

What does this PR do?

The value of repairing the development environment __ECHARTS__DEFAULT__RENDERER__ is undefined
image

Details

Before: What was the problem?

After: How does it behave after the fixing?

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

ZRender Changes

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

Related test cases or examples to use the new APIs

N.A.

Others

Merging options

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

Other information

@echarts-bot
Copy link

echarts-bot bot commented Oct 17, 2023

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.

@bymomo
Copy link

bymomo commented Oct 17, 2023

Very good, I have also encountered this issue and hope to merge

@@ -418,11 +418,11 @@ class ECharts extends Eventful<ECEventDefinition> {
env.hasGlobalWindow ? window : global
) as any;

defaultRenderer = root.__ECHARTS__DEFAULT__RENDERER__ || defaultRenderer;
defaultRenderer = root?.__ECHARTS__DEFAULT__RENDERER__ ?? defaultRenderer;
Copy link
Member

@plainheart plainheart Oct 18, 2023

Choose a reason for hiding this comment

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

As the build target of ECharts is currently still ES3, to reduce the transpiled code size as possible, instead of ?. and ??, just fallback root to {} when it is not defined or simply surround the block (line 421- line 428) with if (root) {}.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right. I overlooked that. I'll revise it.

if (__DEV__) {
let devUseDirtyRect = null;
Copy link
Member

Choose a reason for hiding this comment

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

Remove this line.

Comment on lines 430 to 432
defaultUseDirtyRect = devUseDirtyRect == null
? defaultUseDirtyRect
: devUseDirtyRect;
Copy link
Member

Choose a reason for hiding this comment

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

Remove this three lines.

defaultRenderer = root.__ECHARTS__DEFAULT__RENDERER__ || defaultRenderer;
if (root) {
defaultRenderer = root.__ECHARTS__DEFAULT__RENDERER__ || defaultRenderer;
devUseDirtyRect = root.__ECHARTS__DEFAULT__USE_DIRTY_RECT__;
Copy link
Member

Choose a reason for hiding this comment

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

Change to:

defaultUseDirtyRect = retrieve2(root.__ECHARTS__DEFAULT__USE_DIRTY_RECT__, defaultUseDirtyRect);

@sunpm
Copy link
Contributor Author

sunpm commented Oct 18, 2023

I don’t know if this modification is correct?

Copy link
Member

@plainheart plainheart left a comment

Choose a reason for hiding this comment

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

Looks good

@sunpm
Copy link
Contributor Author

sunpm commented Oct 18, 2023

Thank you for your careful guidance

@plainheart plainheart changed the title fix: '__ECHARTS__DEFAULT__RENDERER__' of undefined fix(core): fix potential NPE when reading default init options from global object in dev environment Oct 18, 2023
@plainheart plainheart merged commit 677adea into apache:master Oct 18, 2023
@echarts-bot
Copy link

echarts-bot bot commented Oct 18, 2023

Congratulations! Your PR has been merged. Thanks for your contribution! 👍

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.

3 participants