Skip to content

Fix double emit sorting events when sorting by different key #11432

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: main
Choose a base branch
from

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jul 25, 2025

The table sorting functionality was emitting multiple events when sorting by a different column, causing a "double emit" issue that could confuse developers and lead to unexpected behavior in applications.

Problem:
When sorting by a different column key, the updateSorterAndDirection method was calling both updateDirection(1) and updateSorter(sorter) separately, which caused:

  1. directionChange event to be emitted first
  2. sorterChange event to be emitted second
  3. Both events triggering separate change detection cycles

This resulted in what users perceived as "double emit" of sorting events.

Solution:
Introduced atomic updates when sorting by a different key by:

  • Adding a new private method updateSorterAndDirectionAtomically that updates both internal state and emits events together in the same execution context
  • Modifying updateSorterAndDirection to use atomic updates for different keys while preserving existing behavior for same-key sorting (direction toggle)
  • Ensuring backward compatibility with all existing functionality

Changes:

  • Modified TuiTableDirective.updateSorterAndDirection() to handle different-key sorting atomically
  • Added comprehensive test coverage to prevent regressions
  • Maintained all existing behavior for same-column sorting scenarios

The fix ensures that when sorting by a different column, both directionChange and sorterChange events are emitted together in the same execution context, eliminating the perception of double emissions while maintaining full backward compatibility.

Fixes #11420.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • cloud.nx.app
    • Triggering command: node /home/REDACTED/work/taiga-ui/taiga-ui/node_modules/.bin/nx run-many --target test --all --output-style=stream /tmp/test-double-emit.spec.ts --verbose (dns block)
    • Triggering command: /opt/hostedtoolcache/node/20.19.4/x64/bin/node /home/REDACTED/work/taiga-ui/taiga-ui/.nx/cache/cloud/2507.21.8/lib/heartbeat/heartbeat-process.js (dns block)
    • Triggering command: node /home/REDACTED/work/taiga-ui/taiga-ui/node_modules/.bin/nx run-many --target build --all --exclude=demo --output-style=stream --nxBail (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copy link

Tests are running 🚀

Wait for workflow run with tests to finish ☕

Copilot AI and others added 2 commits July 25, 2025 19:28
Co-authored-by: splincode <12021443+splincode@users.noreply.github.com>
Co-authored-by: splincode <12021443+splincode@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] 🐞 - fix double emit sorting events, when sort other key Fix double emit sorting events when sorting by different key Jul 25, 2025
@Copilot Copilot AI requested a review from splincode July 25, 2025 19:46
Copilot finished work on behalf of splincode July 25, 2025 19:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

🐞 - fix double emit sorting events, when sort other key
2 participants