Skip to content

Commit b2a0bae

Browse files
fix(tables): unsubscribe the row deselect handler on unmount
subscribe and unsubscribe were both handed a freshly created arrow function, so the two never matched and the handler outlived the component. Every table that had been mounted kept answering the event, deselecting rows in tables the user had already navigated away from. Assisted-by: ClaudeCode:claude-opus-5 Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
1 parent fe3cc01 commit b2a0bae

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

src/shared/components/ncTable/sections/CustomTable.vue

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,14 +317,14 @@ export default {
317317
this.pendingTitleMeasure = window.requestAnimationFrame(() => this.updateCardTitleLines())
318318
})
319319
this.$nextTick(() => this.observeCardLayout())
320-
subscribe('tables:selected-rows:deselect', ({ elementId, isView }) => this.deselectAllRows(elementId, isView))
320+
subscribe('tables:selected-rows:deselect', this.handleDeselectAllRows)
321321
subscribe('tables:row:animate', this.enableRowAnimation)
322322
subscribe(PAGINATION_CHANGED, this.handlePaginationChanged)
323323
},
324324
beforeUnmount() {
325325
window.cancelAnimationFrame(this.pendingTitleMeasure)
326326
this.cardResizeObserver?.disconnect()
327-
unsubscribe('tables:selected-rows:deselect', ({ elementId, isView }) => this.deselectAllRows(elementId, isView))
327+
unsubscribe('tables:selected-rows:deselect', this.handleDeselectAllRows)
328328
unsubscribe('tables:row:animate', this.enableRowAnimation)
329329
unsubscribe(PAGINATION_CHANGED, this.handlePaginationChanged)
330330
},
@@ -393,6 +393,11 @@ export default {
393393
this.rowsPerPage = payload.rowsPerPage
394394
}
395395
},
396+
// A named handler, so beforeUnmount can actually remove it: unsubscribe compares by
397+
// reference and a fresh arrow function never matches the one that was subscribed.
398+
handleDeselectAllRows({ elementId, isView }) {
399+
this.deselectAllRows(elementId, isView)
400+
},
396401
deselectAllRows(elementId, isView) {
397402
if (parseInt(elementId) === parseInt(this.elementId) && isView === this.isView) {
398403
this.selectedRows = []

0 commit comments

Comments
 (0)