-
Notifications
You must be signed in to change notification settings - Fork 198
Extra mxToolip elements created in the DOM #200
Description
mxToolip DOM elements are created to render Tooltips. Currently in v0.2.0, one or several mxTooltip elements are created in the DOM even if Tooltips are not used.
I don't see any reason to create such elements and they were not created in the former mxGraph implementation.
This can be reproduce with Storybook stories, with the ts-example of this repository and examples of https://github.com/maxGraph/maxgraph-integration-examples

DOM snapshot of the ts-example
mxGraph examples showing there wasn't extra tooltip element
- https://jgraph.github.io/mxgraph/javascript/examples/shape.html
- https://jgraph.github.io/mxgraph/javascript/examples/markers.html
First analysis
In mxGraph, the div was created only when calling the show method (if it didn’t previously exist):
- https://github.com/jgraph/mxgraph/blob/ff141aab158417bd866e2dfebd06c61d40773cd2/javascript/src/js/handler/mxTooltipHandler.js#L295-L309
- https://github.com/jgraph/mxgraph/blob/ff141aab158417bd866e2dfebd06c61d40773cd2/javascript/src/js/handler/mxTooltipHandler.js#L136
The div in maxGraph is currently created in the constructor: https://github.com/maxGraph/maxGraph/blob/v0.10.2/packages/core/src/view/handler/TooltipHandler.ts#L51-L55
This means that if the TooltipHandler plugin is declared at Graph initialization (default behavior), a tooltip div is always created even if it is never used.
The behavior should be restored (lazy loading) and the init method could be renamed into ensureDivIsAvailable if there is a naming clarification to do (this would reduce the compatibility with mxGraph).
Notes for implementation
It should be feasible to add an automatic test that reproduce this behavior.