Skip to content

fix(dia.HighlighterView): prevent highlighting nodes outside cell view #2900

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

kumilingus
Copy link
Contributor

@kumilingus kumilingus commented Mar 10, 2025

Description

When a highlighter is used with an SVGElement as its NodeSelector, and that element is not part of the CellView, the node will not be highlighted. Instead, a cell:highlighter:invalid event is triggered—similar to what happens with a non-existent selector.

Motivation and Context

When a port is highlighted using an SVGElement selector and its attributes are updated, we need to make the highlighter invalid. This is because ports are re-rendered on each update, and the original SVGElement is removed from the DOM. The problem manifest during link reconnection, when the use set port attributes on link:connect event.

Note: This issue does not occur when using a JSON-based selector.

@kumilingus kumilingus requested a review from Copilot April 29, 2025 11:41
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR improves the HighlighterView behavior by ensuring that highlighting only applies to nodes within the cell view.

  • Updated tests verify that nodes outside the DOM are not highlighted.
  • Modified the HighlighterView implementation to include a check using cellView.el.contains.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
packages/joint-core/test/jointjs/dia/HighlighterView.js Adjusted test assertions to confirm the update behavior when nodes are detached from the DOM and the handling of the dirty flag.
packages/joint-core/src/dia/HighlighterView.mjs Added a condition to ensure that a node is only highlighted if it is a valid SVGElement within the cell view.

@kumilingus kumilingus force-pushed the fix-highlighter-view-on-removed-nodes branch from 9342738 to 1203b58 Compare April 30, 2025 07:32
@kumilingus kumilingus requested a review from Geliogabalus April 30, 2025 08:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant