Skip to content

fix(graph): cancel port connection drags when the layer is removed - #452

Merged
Antamansid merged 1 commit into
mainfrom
fix/port-connection-layer-cancellation
Nov 9, 2026
Merged

Antamansid merged 1 commit into
mainfrom
fix/port-connection-layer-cancellation

Conversation

@Antamansid

@Antamansid Antamansid commented Nov 9, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

PortConnectionLayer installs document drag listeners on port press, before the pointer crosses the drag threshold. Disabling or removing the layer in that interval lets the old gesture start on the next mouse move. Removing a layer during an active drag can also leave it handling the subsequent mouseup.

Changes

  • Cancel the layer's own pending or active gesture on disable, detach, and final unmount. Route settings changes through the same enable/disable methods.
  • Restore the settings subscription on reattachment and preserve explicit enablement while settings are unchanged.
  • Skip queued iterations after final unmount.

Verification

  • The lifecycle regression tests reproduce the issue on the previous implementation.
  • npm run test:unit -- --runInBand (497 passed)
  • npm run typecheck
  • npm run lint

Summary by Sourcery

Ensure port connection drags are safely cancelled across layer lifecycle changes and remain consistent after reattachment.

Bug Fixes:

  • Cancel pending and active port-connection gestures when the layer is disabled, detached, or unmounted.
  • Prevent queued layer iterations from running after final unmount.

Enhancements:

  • Restore settings observation after reattachment while preserving explicit enablement when settings are unchanged.

Tests:

  • Add lifecycle regression coverage for pending presses, active drags, reattachment settings, explicit enablement, and post-unmount iteration.

@gravity-ui-bot

Copy link
Copy Markdown
Contributor

Preview is ready.

@Antamansid
Antamansid marked this pull request as ready for review November 9, 2026 10:59
@sourcery-ai

sourcery-ai Bot commented Nov 9, 2026

Copy link
Copy Markdown

Reviewer's Guide

Implementation

Cancel pending and active gestures when the layer is disabled or unmounted, clear drag listeners when a gesture ends, and prevent queued iterations after final unmount.

  • src/components/canvas/layers/portConnectionLayer/PortConnectionLayer.ts L315-318, L494-497, L800-810 (+2 small edits)

Track settings identity and route changed settings through enable or disable so reattachment restores observation without overriding explicit enablement when settings are unchanged.

  • src/components/canvas/layers/portConnectionLayer/PortConnectionLayer.ts L220-235 (+3 small edits)

Tests

Cover cancellation of pending and active gestures across disable, detach, and unmount, plus settings reattachment, queued iterations, and preserved explicit enablement.

  • src/components/canvas/layers/portConnectionLayer/PortConnectionLayer.test.ts L77-147 (+3 small edits)

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@Antamansid
Antamansid merged commit d0f6062 into main Nov 9, 2026
6 checks passed
@Antamansid
Antamansid deleted the fix/port-connection-layer-cancellation branch November 9, 2026 11:00

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="src/components/canvas/layers/portConnectionLayer/PortConnectionLayer.ts" line_range="220" />
<code_context>

+  protected afterInit(): void {
     this.onSignal(this.props.graph.rootStore.settings.$settings, (value) => {
-      this.enabled = Boolean(value.canCreateNewConnections);
+      // Subscribing again must preserve explicit enable/disable calls until the settings change.
+      if (value === this.lastSettings) {
</code_context>
<issue_to_address>
**Connection drags ignore current setting**

When the setting changes while the layer is detached and remains unchanged after reattachment, `afterInit` only registers `onSignal` for future changes, so `enabled` remains stale; connection drags are accepted or rejected contrary to `canCreateNewConnections`.

On reattachment, reconcile `enabled` with the current setting when it differs from `lastSettings`, without overriding explicit enable/disable calls when the setting is unchanged.

Also at `src/components/canvas/layers/portConnectionLayer/PortConnectionLayer.ts:225-229`.
</issue_to_address>

Sourcery assessment

Needs a human reviewer. 1 finding to address first, and if cancellation or enablement handling is wrong, a drag could create an unintended graph connection that remains after reverting and may need to be removed manually. The impact is bounded to affected graph data and is repairable.

Blocking findings: src/components/canvas/layers/portConnectionLayer/PortConnectionLayer.ts:220


Sourcery is free for open source - if you like our reviews please consider sharing them ✨


protected afterInit(): void {
this.onSignal(this.props.graph.rootStore.settings.$settings, (value) => {
this.enabled = Boolean(value.canCreateNewConnections);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Medium · Connection drags ignore current setting

When the setting changes while the layer is detached and remains unchanged after reattachment, afterInit only registers onSignal for future changes, so enabled remains stale; connection drags are accepted or rejected contrary to canCreateNewConnections.

On reattachment, reconcile enabled with the current setting when it differs from lastSettings, without overriding explicit enable/disable calls when the setting is unchanged.

Also at src/components/canvas/layers/portConnectionLayer/PortConnectionLayer.ts:225-229.

Prompt for AI agents
In `src/components/canvas/layers/portConnectionLayer/PortConnectionLayer.ts` at line 220:

**Connection drags ignore current setting**

When the setting changes while the layer is detached and remains unchanged after reattachment, `afterInit` only registers `onSignal` for future changes, so `enabled` remains stale; connection drags are accepted or rejected contrary to `canCreateNewConnections`.

On reattachment, reconcile `enabled` with the current setting when it differs from `lastSettings`, without overriding explicit enable/disable calls when the setting is unchanged.

Also at `src/components/canvas/layers/portConnectionLayer/PortConnectionLayer.ts:225-229`.

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.

3 participants