MohammadWasi opened a new pull request, #21749:
URL: https://github.com/apache/echarts/pull/21749
## Brief Information
This pull request is in the type of:
- [x] bug fixing
- [ ] new feature
- [ ] others
### What does this PR do?
Stops ECharts from wrongly requiring `TimelineComponent` when an option uses
the `{ baseOption, media }` form without a `timeline`.
### Fixed issues
- #21686: `baseOption` with `media` incorrectly requires `TimelineComponent`
when no timeline is configured
## Details
### Before: What was the problem?
Using the modular build without registering `TimelineComponent`, an option
structured with `baseOption` + `media` but **no** `timeline` reported:
```text
Component timeline is used but not imported.
import { TimelineComponent } from 'echarts/components';
echarts.use([TimelineComponent]);
```
Depending on the environment this surfaces as an exception during
`setOption`, forcing users to register a component they don't use.
**Root cause:** in `OptionManager.parseRawOption`, when a `baseOption` is
declared, the parser injects the root timeline into it for merge purposes:
```ts
if (!baseOption.timeline) {
baseOption.timeline = timelineOnRoot; // `undefined` when no timeline is
configured
}
```
This leaves an own `timeline` key on `baseOption` whose value is
`undefined`. `checkMissingComponents` then iterates every key of the option and
reports any `mainType` whose class isn't registered — so the empty `timeline`
entry is wrongly flagged as a missing `TimelineComponent`. It only reproduces
with the `{ baseOption, media }` form because the plain root-option path
doesn't inject that key.
### After: How does it behave after the fixing?
`checkMissingComponents` now skips component options whose value is
`null`/`undefined`, since such an entry means the component isn't actually
used. An option with `baseOption` + `media` and no `timeline` works with the
modular build without registering `TimelineComponent`. Genuine
missing-component reporting is unchanged (a real `timeline: {...}` still
reports when unregistered).
```ts
each(option, function (componentOption, mainType) {
// A `null`/`undefined` option value means the component is not actually
used.
if (componentOption != null && !ComponentModel.hasClass(mainType)) {
// ...report as missing...
}
});
```
The fix is guarded by `__DEV__` (this check only runs in development
builds), so there is no production behavior change.
### Regression test
Added a case to `test/ut/spec/model/componentMissing.test.ts` asserting that
a `{ baseOption, media }` option without a timeline does **not** report
`TimelineComponent` as missing. Verified it fails on `master` (reproduces the
bug) and passes with this fix. The full `test/ut/spec/model` suite passes,
along with `npm run lint` and `npm run checktype`.
## Document Info
One of the following should be checked.
- [x] 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 a Jest regression test in
`test/ut/spec/model/componentMissing.test.ts`.
### Merging options
- [x] Please squash the commits into a single one when merging.
### Other information
🤖 Generated with [Claude Code](https://claude.com/claude-code)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]