fix(TooltipHandler): initialize the div when tooltip is shown by HalilFocic · Pull Request #591 · maxGraph/maxGraph
86-86: Optional property for div improves state management
Making div optional and nullable is a neat change, allowing you to conditionally initialize it and avoid potential null references. This also supports the lazy creation approach in init().
240-240: Visibility check prevents redundant show calls
The condition (!this.div || this.div.style.visibility == 'hidden') is a good safeguard to avoid re-showing an already visible tooltip. Confirm that this logic covers scenarios where the tooltip content needs to be updated while currently visible. If dynamic content updates are needed, consider removing or adjusting the visibility check.
302-304: Initialization on demand aligns with lazy loading goals
Auto-initializing the tooltip on show ensures minimal DOM footprint at startup. This matches the PR objective of deferring mxTooltip creation until necessary.
310-313: Efficient node-based tooltip insertion
Handling the node-based tooltip separately is a nice approach to support rich content. This keeps the design flexible and works well with the new lazy creation logic.
316-317: fit call ensures tooltip stays in viewport
Nice step to adjust position after insertion. This helps avoid tooltips cropped by the browser window.
326-326: Cleaner approach to reset the timer in onDestroy
Clearing the pending timeout thread prevents lingering events after destruction and is consistent with best practices for resource cleanup.
328-330: Double-check InternalEvent.release usage
Releasing the tooltip element before removing it is good. Ensure there are no references held by other event listeners or outside code that might become stale after this call.
332-332: Ensuring complete removal from DOM
Removing the div from its parent is correct if it’s guaranteed that the parent is in the normal DOM, not in a user-provided container. Confirm that dynamic container changes do not lead to unexpected side effects.
337-337: Nulling this.div finalizes cleanup
Clearing the reference ensures the tooltip handler cannot accidentally attempt operations on an outdated element. This aligns with the overall PR goal of preventing leftover DOM usage.