Skip to content

fix(query-builder): end drag subscriptions on chip drop and destroy - #18041

Merged
kdinev merged 7 commits into
masterfrom
ipetrov/fix-17804
Dec 4, 2026
Merged

kdinev merged 7 commits into
masterfrom
ipetrov/fix-17804

Conversation

@ivanvpetrov

Copy link
Copy Markdown
Contributor

Closes #17804

Description

A condition dropped with the mouse on another condition no longer leaves the drag service listening, so the application becomes stable again. Destroying the query builder while a condition is dragged no longer throws.

  • resetDragAndDrop(true) now closes the drag ghost mousemove subscription and the keyboard subscription. It runs at the end of every drag, however it ends: move end, a drop on a condition, a keyboard drop, or a cancel. The four separate unsubscribe() calls it replaces were removed.
  • IgxQueryBuilderDragService implements ngOnDestroy. It closes both subscriptions and clears the pending ghost z-index timeout. The service is in the tree component's providers, so Angular calls it when the tree is destroyed, as with IgxTreeNavigationService.
  • dragGhostIsOnDropGhostRow() returns false when the drag ghost is gone, instead of throwing.

Motivation / Context

On release, igxDrag dispatches the drop to the drop area under the pointer before the dragged chip emits moveEnd. When that area is another condition's chip (dragDrop) or its wrapper (dropped → onDivDropped), onChipDropped() runs first and clears the drag state. onMoveEnd() then returns early and never reaches the unsubscribe() calls, which were the only ones for the ghost mousemove subscription. Effects:

  • The sampleTime(100) timer keeps running in the Angular zone, so ApplicationRef.isStable / fixture.whenStable() never settle.
  • The next drag doesn't subscribe to its ghost, because the closed guard sees the old subscription, which is attached to the removed ghost of the previous drag.
  • If the query builder is destroyed mid-drag, igxDrag removes the ghost without ending the drag. A pending sampled mouse move then calls onChipLeave() → dragGhostIsOnDropGhostRow(), which throws Cannot read properties of null (reading 'getBoundingClientRect').

Note on the issue's repro: the TypeError needs a destroy during a drag whose ghost the subscription is attached to. After a drop on a condition (step 2), the next drag has no ghost subscription, so step 4 as written doesn't reproduce it.

Type of Change (check all that apply):

  • Bug fix
  • New functionality
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Refactoring (no functional changes)
  • Documentation
  • Demos
  • CI/CD
  • Tests
  • Changelog
  • Skills/Agents

Component(s) / Area(s) Affected:

Query Builder (condition drag and drop), including the grids' advanced filtering dialog

How Has This Been Tested?

New specs in the Drag and drop section of query-builder.component.spec.ts:

  • Dropping a condition on another condition (the drop comes from the target chip, before moveEnd) closes both subscriptions.
  • After such a drop, fixture.isStable() becomes true (real timers).
  • A mouse drag that follows such a drop subscribes to its own ghost, and its sampled mouse moves are handled.
  • Destroying the query builder during a mouse drag, with a mouse move still to be sampled, closes both subscriptions and doesn't call onChipLeave().
  • onChipLeave() doesn't throw when the drag ghost is gone, and removes the drop ghost.

All five fail without the fix and pass with it. The comment in the spec that described the leak as expected was updated.

  • Unit tests
  • Manual testing
  • Automated e2e tests

Runs:

  • query-builder specs: 148 passed
  • grid-filtering-advanced specs: 55 passed
  • npm run lint:lib: no new errors or warnings

Test Configuration:

  • Angular version: 22.2.3
  • Browser(s): Chromium (Vitest browser mode via Playwright)
  • OS: Windows 11

Screenshots / Recordings

N/A: no visual change.

Checklist:

  • All relevant labels have been applied to this PR
  • This PR includes unit tests covering all the new code (test guidelines)
  • This PR includes API docs for newly added methods/properties (api docs guidelines)
  • This PR includes feature/README.MD updates for the feature docs
  • This PR includes general feature table updates in the root README.MD
  • This PR includes CHANGELOG.MD updates for newly added functionality
  • This PR contains breaking changes
  • This PR includes ng update migrations for the breaking changes (migrations guidelines)
  • This PR includes behavioral changes and the feature specification has been updated with them
  • Accessibility (ARIA, keyboard navigation, focus management) has been verified

Close the drag ghost mousemove and keyboard subscriptions whenever a
drag ends, including drops handled by a target condition, and when the
query builder is destroyed. Return false from the drop ghost row check
when the drag ghost is gone.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues are reported for the Query Builder drag-cleanup changes.

No open issues 🎉

What changed in this PR

Fixes Query Builder drag cleanup for #17804, restoring application stability after condition drops and preventing errors when the component is destroyed mid-drag.

Changes:

  • Centralizes drag subscription cleanup and clears the pending ghost timeout on destruction.
  • Guards against a missing drag ghost and adds five regression tests covering cleanup, stability, and subsequent drags.
  • Documents the user-visible fixes in the changelog.
File Description
projects/​igniteui-angular/​query-builder/​src/​query-builder/​query-builder.component.spec.ts Adds drag lifecycle regression tests and updates the timer-related comment.
projects/​igniteui-angular/​query-builder/​src/​query-builder/​query-builder-drag.service.ts Centralizes subscription cleanup, adds destruction handling, and guards missing ghosts.
CHANGELOG.md Records the stability and mid-drag destruction fixes.

Review effort: Balanced

@ivanvpetrov
ivanvpetrov marked this pull request as ready for review November 24, 2026 14:15

@viktorkombov viktorkombov left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@ivanvpetrov, CHANGELOG.md conflicts with master, and the entry is under 22.3.1, which is already released (22.3.2 too). Please move it to a new ## 22.3.3. Also 22.3.x and 21.2.x have the same bug (only onMoveEnd() unsubscribes, there is no ngOnDestroy), so this needs backports there.

@viktorkombov viktorkombov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please resolve the conflicts with master and update #18089 and #18090 with their base branches, so CI runs on them.

viktorkombov
viktorkombov previously approved these changes Dec 4, 2026
@viktorkombov viktorkombov added ✅ status: verified Applies to PRs that have passed manual verification and removed ❌ status: awaiting-test PRs awaiting manual verification labels Dec 4, 2026
kdinev pushed a commit that referenced this pull request Dec 4, 2026
…18089)

Close the drag ghost mousemove and keyboard subscriptions whenever a
drag ends, including drops handled by a target condition, and when the
query builder is destroyed. Return false from the drop ghost row check
when the drag ghost is gone.

Backport of #18041 to 22.3.x.
@kdinev
kdinev merged commit 52c5af1 into master Dec 4, 2026
7 checks passed
@kdinev
kdinev deleted the ipetrov/fix-17804 branch December 4, 2026 12:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

drag-drop query-builder version: 22.4.x ✅ status: verified Applies to PRs that have passed manual verification

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Query Builder: drag ghost mousemove subscription outlives the drag and throws TypeError

4 participants