YaoKaiPeng commented on code in PR #21391:
URL: https://github.com/apache/echarts/pull/21391#discussion_r2567087060


##########
src/component/toolbox/feature/SaveAsImage.ts:
##########
@@ -66,7 +81,7 @@ class SaveAsImage extends 
ToolboxFeature<ToolboxSaveAsImageFeatureOption> {
             $a.href = url;
             const evt = new MouseEvent('click', {

Review Comment:
   Hi, happy to discuss this further!
   
   In micro-frontend environments, `window` is often a proxy object (e.g., in 
qiankun, Micro-app, etc.), which can cause issues when creating `MouseEvent` 
with `new MouseEvent(..., { view: window })` — for example, throwing errors or 
behaving unexpectedly.
   
   I believe the key point isn't whether to use `element.click()` or 
`dispatchEvent`, but rather: which actual `window` object should be used as the 
`view` when creating the event.
   
   That’s why this PR replaces `document.defaultView` with `pickEventView()` — 
a safe utility that:
   
   1. Tries to use `window.rawWindow` (available in frameworks like 
`Micro-app`, where `window.proxy` holds the real `rawWindow`).
   2. Falls back to `document.defaultView` if that’s accessible.
   3. Finally defaults to `window` if all else fails.
   
   This ensures the `MouseEvent` always has a valid, real `window` as its 
`view`, regardless of whether `window` is a proxy — making the event creation 
robust in micro-frontend setups.
   
   Importantly, this change doesn’t alter how events are dispatched (we still 
use `dispatchEvent`), but it significantly improves reliability by ensuring the 
correct `view` context is used.
   
   This makes ECharts more resilient in micro-frontend applications without 
introducing any behavioral changes.
   
   Thanks for raising this question — happy to discuss further! 😊



-- 
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]

Reply via email to