matiaslopezd opened a new issue, #21897:
URL: https://github.com/apache/echarts/issues/21897
### What problem does this feature solve?
Pages that enforce Trusted Types with no policy (`require-trusted-types-for
'script'; trusted-types 'none'`) cannot use ECharts today: any string
assignment to `innerHTML` throws. Trusted Types is shipped in Chromium-based
browsers and is a common hardening requirement for consoles and admin UIs. No
issue tracks this yet.
Audit of 6.1.0 (`lib/`), the sinks that run in a typical canvas setup:
1. **Init/dispose**: `zrender/lib/canvas/Painter.js` clears the root with
`innerHTML = ''`. Fixed upstream by ecomfe/zrender#1167 (`textContent = ''`),
still unreviewed.
2. **HTML tooltip**: `TooltipHTMLContent.setContent` (`el.innerHTML =
content + arrow`, `el.innerHTML = ''`, `arrowEl.innerHTML = arrow`). The
default `renderMode: 'html'` breaks every chart with a tooltip.
3. **`renderMode: 'richText'` is not a full alternative**: with a custom
`formatter`, `tooltip.textStyle.rich` is ignored
(`TooltipRichContent.setContent` passes only
`markupStyleCreator.richTextStyles` as `rich`), so a formatter can't style its
text. See #18339, #19966, #20240, #17543 (#21675 applies root `textStyle` but
not `rich`).
Not hit by default, listed for completeness: DataView (`innerHTML` for
title/`optionToContent`), `SaveAsImage` legacy IE branch (`document.write`; the
modern branch uses `<a download>` and works), connected SVG export
(`echarts.js`, `getSvgRoot().innerHTML`), `parseXML`
(`DOMParser.parseFromString`) for SVG maps, and the `new Function` JSON
fallback in `GeoJSONResource`.
### What does the proposed API look like?
No new API for most of it:
- Depend on a zrender release including ecomfe/zrender#1167.
- `TooltipHTMLContent`: clear with `textContent = ''`, build the arrow with
`createElement` instead of an HTML string, and assign `content` alone (no `+
arrow` concatenation). Then a formatter returning DOM nodes is fully
Trusted-Types-safe, and a formatter returning a `TrustedHTML` value works
as-is, since concatenation is what turns it back into a string.
- `TooltipRichContent`: merge `tooltip.textStyle.rich` under the generated
marker styles, so `richText` formatters can use named styles (`{value|…}`). We
run this one-line change in production:
`rich: extend(extend({}, tooltipModel.get(['textStyle', 'rich'])),
markupStyleCreator.richTextStyles)`.
Happy to send PRs for the tooltip parts if this direction is acceptable.
--
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]