Skip to content

fix(rux-tree-node): emit ruxtreenodeselected once when selected via setSelected - #1527

Closed
East Agile Tracker (eastagiletracker) wants to merge 1 commit into
RocketCommunicationsInc:mainfrom
eastagiletracker:agile-board/tree-node-single-selected-event
Closed

East Agile Tracker (eastagiletracker) wants to merge 1 commit into
RocketCommunicationsInc:mainfrom
eastagiletracker:agile-board/tree-node-single-selected-event

Conversation

@eastagiletracker

Copy link
Copy Markdown

This PR proposes fixing rux-tree-node emitting ruxtreenodeselected twice when a node is selected through setSelected(true). Fixes #1458. We include this PR work along with a full history of your repo at https://eastagiletracker.com/projects/652. You can sign in with your GitHub ID to claim ownership of the project.

What changed and why

In rux-tree-node.tsx, setSelected(true) sets this.selected, which synchronously fires the @Watch('selected') handler. That handler called setSelected(newValue) again, which emitted ruxtreenodeselected, and then the original call emitted it a second time. Clicking a node only emitted once because the click handler sets selected directly and goes through the watcher a single time. The Enter key handler calls setSelected(true) too, so keyboard selection had the same double emit. The fix moves the emit into the watcher (so every change to true emits exactly once, whether it comes from a click, the Enter key, setSelected, or setting the selected prop), and setSelected now only emits on its own when re-selecting a node that is already selected, which keeps the existing single event for that case. Deselecting still emits nothing. A patch changeset is included.

Reproduction at current main (6f4dc9f). With the new regression tests added to src/components/rux-tree-node/test/tree-node.spec.ts and the component unchanged, npx playwright test --project=chromium-e2e src/components/rux-tree-node fails 3 tests: setSelected(true) on an unselected node, setSelected(true) on a node inside a rux-tree, and selecting with the Enter key, each with Error: expected event "ruxtreenodeselected" to have been called 1 times, but was called 2 times.

Verification. After stencil build, the full chromium-e2e project was run before and after the change: 334 passed / 8 failed on main, 340 passed / 8 failed with this branch (the 6 new tests all pass). The 8 failures are identical in both runs and unrelated to the tree (rux-dialog, rux-tabs, rux-textarea, rux-timeline). The new tests also pin the paths whose behavior should not move: setting the selected prop still emits once, setSelected(true) on an already selected node still emits once, and setSelected(false) emits nothing. The existing rux-tree tests (keyboard controls, independent selection across trees) stay green, and the rux-tree-node.spec.tsx unit spec passes.

How this was managed

This work was tracked as story https://eastagiletracker.com/projects/652/stories/566812 on a board imported from this repo's issues and pull requests (1,453 stories), which we used to manage the fix: https://eastagiletracker.com/projects/652

board

If you'd rather not receive contributions like this, reply no-more-prs on this pull request and we won't open any further ones on your repositories.


Lawrence W. Sinclair
CEO / East Agile
linkedin.com/in/lwsinclair/
eastagile.com

…etSelected

The selected watcher called setSelected, which emitted again after the
watcher-triggered call had already emitted, so selecting an unselected
node through setSelected(true) or the Enter key fired the event twice.
The watcher now emits on change, and setSelected only emits itself when
re-selecting an already selected node.
@changeset-bot

changeset-bot Bot commented Sep 28, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: b80e9a7

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@netlify

netlify Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for astro-preview ready!

Name Link
🔨 Latest commit b80e9a7
🔍 Latest deploy log https://app.netlify.com/projects/astro-preview/deploys/6aba1fef2ecf4200081ac6b5
😎 Deploy Preview https://deploy-preview-1527--astro-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify

netlify Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for astro-stencil ready!

Name Link
🔨 Latest commit b80e9a7
🔍 Latest deploy log https://app.netlify.com/projects/astro-stencil/deploys/6aba1fef77120e00089c892c
😎 Deploy Preview https://deploy-preview-1527--astro-stencil.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

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.

duplicate events emitted during when setSelected(true) is called on a rux-tree-node

2 participants