Skip to content

πŸ”₯ πŸ”₯ πŸ”₯ A Free & Self-hostable Airtable Alternative

fix: cleanup event bus listeners by properly unsubscribing handlers on component unmount

DarkPhoenix27049e96c39ed473
diff --git a/packages/nc-gui/components/dashboard/settings/data-sources/CreateBase.vue b/packages/nc-gui/components/dashboard/settings/data-sources/CreateBase.vue
index e7303be70b..f30180def1 100644
--- a/packages/nc-gui/components/dashboard/settings/data-sources/CreateBase.vue
+++ b/packages/nc-gui/components/dashboard/settings/data-sources/CreateBase.vue
@@ -380,7 +380,7 @@ const handleAddNewConnection = () => {
pageMode.value = IntegrationsPageMode.LIST
}
-eventBus.on((event, payload) => {
+const eventBusHandler = (event, payload) => {
if (event === IntegrationStoreEvents.INTEGRATION_ADD && payload?.id) {
formState.value.fk_integration_id = payload.id
until(() => selectedIntegration.value?.id === payload.id)
@@ -389,6 +389,12 @@ eventBus.on((event, payload) => {
changeIntegration(true)
})
}
+}
+
+eventBus.on(eventBusHandler)
+
+onBeforeUnmount(() => {
+ eventBus.off(eventBusHandler)
})
const handleUpdateAdvancedOptionsExpansionPanel = (open: boolean) => {
diff --git a/packages/nc-gui/components/extensions/Pane.vue b/packages/nc-gui/components/extensions/Pane.vue
index aed9b48ff1..0e0327c4fb 100644
--- a/packages/nc-gui/components/extensions/Pane.vue
+++ b/packages/nc-gui/components/extensions/Pane.vue
@@ -137,10 +137,16 @@ const handleAutoScroll = async (id: string) => {
}
}
-eventBus.on((event, payload) => {
+const extensionEventBusEvent = (event: ExtensionsEvents, payload) => {
if ([ExtensionsEvents.DUPLICATE, ExtensionsEvents.ADD].includes(event) && payload) {
handleAutoScroll(payload)
}
+}
+
+eventBus.on(extensionEventBusEvent)
+
+onBeforeUnmount(() => {
+ eventBus.off(extensionEventBusEvent)
})
onMounted(() => {
diff --git a/packages/nc-gui/components/nc/form-builder/index.vue b/packages/nc-gui/components/nc/form-builder/index.vue
index 39217ccca0..b7d07cb36f 100644
--- a/packages/nc-gui/components/nc/form-builder/index.vue
+++ b/packages/nc-gui/components/nc/form-builder/index.vue
@@ -88,11 +88,17 @@ const setFormStateWithEmit = (path: string, value: any) => {
emit('change', path, value)
}
-eventBus.on((event, payload) => {
+const integegrationEventHandler = (event: IntegrationStoreEvents, payload: any) => {
if (event === IntegrationStoreEvents.INTEGRATION_ADD && payload?.id && activeModel.value) {
setFormStateWithEmit(activeModel.value, payload.id)
activeModel.value = null
}
+}
+
+eventBus.on(integegrationEventHandler)
+
+onBeforeUnmount(() => {
+ eventBus.off(integegrationEventHandler)
})
watch(
diff --git a/packages/nc-gui/components/smartsheet/Form.vue b/packages/nc-gui/components/smartsheet/Form.vue
index 6dcd02916e..75eeeb339b 100644
--- a/packages/nc-gui/components/smartsheet/Form.vue
+++ b/packages/nc-gui/components/smartsheet/Form.vue
@@ -111,10 +111,16 @@ reloadEventHook.on(
}),
)
-eventBus.on((event) => {
+const smartsheetEventHandler = (event: SmartsheetStoreEvents) => {
if (event === SmartsheetStoreEvents.COPIED_VIEW_CONFIG) {
reloadEventHook.trigger()
}
+}
+
+eventBus.on(smartsheetEventHandler)
+
+onBeforeUnmount(() => {
+ eventBus.off(smartsheetEventHandler)
})
const { fields, showAll, hideAll } = useViewColumnsOrThrow()
diff --git a/packages/nc-gui/components/smartsheet/Gallery.vue b/packages/nc-gui/components/smartsheet/Gallery.vue
index 4f658fb126..9cfd3efab8 100644
--- a/packages/nc-gui/components/smartsheet/Gallery.vue
+++ b/packages/nc-gui/components/smartsheet/Gallery.vue
@@ -177,8 +177,6 @@ const handleClick = (col, event) => {
openNewRecordFormHook?.on(openNewRecordFormHookHandler)
-onBeforeUnmount(() => openNewRecordFormHook.off(openNewRecordFormHookHandler))
-
const reloadAttachments = ref(false)
reloadViewMetaHook?.on(async () => {
@@ -374,10 +372,17 @@ reloadViewDataHook?.on(
}),
)
-eventBus.on((event) => {
+const smartsheetEventHandler = (event: SmartsheetStoreEvents) => {
if (event === SmartsheetStoreEvents.DATA_RELOAD) {
reloadViewDataHook?.trigger()
}
+}
+
+eventBus.on(smartsheetEventHandler)
+
+onBeforeUnmount(() => {
+ openNewRecordFormHook.off(openNewRecordFormHookHandler)
+ eventBus.off(smartsheetEventHandler)
})
const handleOpenNewRecordForm = () => {
diff --git a/packages/nc-gui/components/smartsheet/Kanban.vue b/packages/nc-gui/components/smartsheet/Kanban.vue
index b8130e9abc..ead461047a 100644
--- a/packages/nc-gui/components/smartsheet/Kanban.vue
+++ b/packages/nc-gui/components/smartsheet/Kanban.vue
@@ -132,11 +132,13 @@ reloadViewDataHook?.on(
}),
)
-eventBus.on((event) => {
+const smartsheetEventHandler = (event: SmartsheetStoreEvents) => {
if (event === SmartsheetStoreEvents.DATA_RELOAD) {
reloadViewDataHook?.trigger()
}
-})
+}
+
+eventBus.on(smartsheetEventHandler)
const attachments = (record: any): Attachment[] => {
if (!coverImageColumn.value?.title || !record.row[coverImageColumn.value.title]) return []
@@ -406,7 +408,10 @@ openNewRecordFormHook?.on(openNewRecordFormHookHandler)
// remove openNewRecordFormHookHandler before unmounting
// so that it won't be triggered multiple times
-onBeforeUnmount(() => openNewRecordFormHook.off(openNewRecordFormHookHandler))
+onBeforeUnmount(() => {
+ openNewRecordFormHook.off(openNewRecordFormHookHandler)
+ eventBus.off(smartsheetEventHandler)
+})
// reset context menu target on hide
watch(contextMenu, () => {
diff --git a/packages/nc-gui/components/smartsheet/Row.vue b/packages/nc-gui/components/smartsheet/Row.vue
index 0ea549cc24..333c0b9ae9 100644
--- a/packages/nc-gui/components/smartsheet/Row.vue
+++ b/packages/nc-gui/components/smartsheet/Row.vue
@@ -22,13 +22,19 @@ reloadHook.on((params) => {
const { eventBus } = useScriptExecutor()
-eventBus.on(async (event, payload) => {
+const eventHandler = async (event: SmartsheetScriptActions, payload: any) => {
if (event === SmartsheetScriptActions.RELOAD_ROW) {
// eslint-disable-next-line eqeqeq
if (payload.rowId == pk.value) {
await loadRow()
}
}
+}
+
+eventBus.on(eventHandler)
+
+onBeforeUnmount(() => {
+ eventBus.off(eventHandler)
})
provide(ReloadRowDataHookInj, reloadHook)
diff --git a/packages/nc-gui/components/smartsheet/grid/GroupByTable.vue b/packages/nc-gui/components/smartsheet/grid/GroupByTable.vue
index 8968c13080..971337e944 100644
--- a/packages/nc-gui/components/smartsheet/grid/GroupByTable.vue
+++ b/packages/nc-gui/components/smartsheet/grid/GroupByTable.vue
@@ -315,18 +315,21 @@ async function deleteSelectedRowsWrapper() {
const reloadViewDataHook = inject(ReloadViewDataHookInj, createEventHook())
+const smartsheetEvents = (event: string) => {
+ if (event === SmartsheetStoreEvents.GROUP_BY_RELOAD || event === SmartsheetStoreEvents.DATA_RELOAD) {
+ reloadViewDataHook?.trigger()
+ }
+}
+
+eventBus.on(smartsheetEvents)
+
onBeforeUnmount(async () => {
// reset hooks
+ eventBus.off(smartsheetEvents)
reloadViewDataHook?.off(reloadTableData)
})
reloadViewDataHook?.on(reloadTableData)
-
-eventBus.on((event) => {
- if (event === SmartsheetStoreEvents.GROUP_BY_RELOAD || event === SmartsheetStoreEvents.DATA_RELOAD) {
- reloadViewDataHook?.trigger()
- }
-})
</script>
<template>
diff --git a/packages/nc-gui/components/smartsheet/grid/InfiniteTable.vue b/packages/nc-gui/components/smartsheet/grid/InfiniteTable.vue
index ec8ff5d37e..8c89c47c9c 100644
--- a/packages/nc-gui/components/smartsheet/grid/InfiniteTable.vue
+++ b/packages/nc-gui/components/smartsheet/grid/InfiniteTable.vue
@@ -1794,7 +1794,7 @@ const resetProgress = (payload: { type: 'table' | 'row' | 'cell'; data: { rowId?
}
}
-eventBus.on(async (event, payload) => {
+const smartsheetEvents = async (event: SmartsheetStoreEvents, payload) => {
if (event === SmartsheetStoreEvents.FIELD_ADD) {
columnOrder.value = payload
addColumnDropdown.value = true
@@ -1806,8 +1806,9 @@ eventBus.on(async (event, payload) => {
removeRowIfNew?.(payload)
}
-})
+}
+eventBus.on(smartsheetEvents)
watch(activeCell, (activeCell) => {
const row = activeCell.row !== null ? cachedRows.value.get(activeCell.row)?.row : undefined
const col = row && activeCell.col !== null ? fields.value[activeCell.col] : undefined
@@ -1845,7 +1846,7 @@ const reloadViewDataHookHandler = withLoading(async (param) => {
let requestAnimationFrameId: null | number = null
const { eventBus: scriptEventBus } = useScriptExecutor()
-scriptEventBus.on(async (event, payload) => {
+const scriptEventHandler = async (event, payload) => {
if (event === SmartsheetScriptActions.UPDATE_PROGRESS) {
handleProgress(payload)
}
@@ -1855,7 +1856,9 @@ scriptEventBus.on(async (event, payload) => {
if (event === SmartsheetScriptActions.RELOAD_VIEW) {
await reloadViewDataHookHandler()
}
-})
+}
+
+scriptEventBus.on(scriptEventHandler)
useScroll(gridWrapper, {
onScroll: (e) => {
@@ -1974,6 +1977,8 @@ onBeforeUnmount(async () => {
reloadViewDataHook?.off(reloadViewDataHookHandler)
openNewRecordFormHook?.off(openNewRecordHandler)
reloadVisibleDataHook?.off(triggerReload)
+ eventBus.off(smartsheetEvents)
+ scriptEventBus.off(scriptEventHandler)
})
openNewRecordFormHook?.on(openNewRecordHandler)
diff --git a/packages/nc-gui/components/smartsheet/grid/Table.vue b/packages/nc-gui/components/smartsheet/grid/Table.vue
index 69a2c21332..355596d2ab 100644
--- a/packages/nc-gui/components/smartsheet/grid/Table.vue
+++ b/packages/nc-gui/components/smartsheet/grid/Table.vue
@@ -1567,7 +1567,7 @@ onMounted(() => {
// #Listeners
-eventBus.on(async (event, payload) => {
+const smartsheetEvents = async (event: SmartsheetStoreEvents, payload: any) => {
if (event === SmartsheetStoreEvents.FIELD_ADD) {
columnOrder.value = payload
addColumnDropdown.value = true
@@ -1579,7 +1579,9 @@ eventBus.on(async (event, payload) => {
removeRowIfNew?.(payload)
}
-})
+}
+
+eventBus.on(smartsheetEvents)
watch(activeCell, (activeCell) => {
const row = activeCell.row !== null ? dataRef.value[activeCell.row]?.row : undefined
@@ -1728,6 +1730,7 @@ onBeforeUnmount(async () => {
// reset hooks
reloadViewDataHook?.off(reloadViewDataHandler)
openNewRecordFormHook?.off(openNewRecordHandler)
+ eventBus.off(smartsheetEvents)
})
reloadViewDataHook?.on(reloadViewDataHandler)
diff --git a/packages/nc-gui/components/smartsheet/grid/canvas/composables/useCanvasTable.ts b/packages/nc-gui/components/smartsheet/grid/canvas/composables/useCanvasTable.ts
index edd03749f6..a56c1746f0 100644
--- a/packages/nc-gui/components/smartsheet/grid/canvas/composables/useCanvasTable.ts
+++ b/packages/nc-gui/components/smartsheet/grid/canvas/composables/useCanvasTable.ts
@@ -1376,13 +1376,20 @@ export function useCanvasTable({
triggerRefreshCanvas()
})
- eventBus.on((event) => {
+ const smartsheetEventHandler = (event) => {
if ([SmartsheetStoreEvents.TRIGGER_RE_RENDER, SmartsheetStoreEvents.ON_ROW_COLOUR_INFO_UPDATE].includes(event)) {
forcedNextTick(() => {
clearRowColouringCache()
triggerRefreshCanvas()
})
}
+ }
+
+ eventBus.on(smartsheetEventHandler)
+
+ onBeforeUnmount(() => {
+ actionManager.releaseEventListeners()
+ eventBus.off(smartsheetEventHandler)
})
// load metas and refresh canvas
diff --git a/packages/nc-gui/components/smartsheet/grid/canvas/index.vue b/packages/nc-gui/components/smartsheet/grid/canvas/index.vue
index fad160d4d7..73cb101a83 100644
--- a/packages/nc-gui/components/smartsheet/grid/canvas/index.vue
+++ b/packages/nc-gui/components/smartsheet/grid/canvas/index.vue
@@ -2524,14 +2524,7 @@ watch(
},
)
-onBeforeUnmount(() => {
- reloadViewDataHook.off(reloadViewDataHookHandler)
- reloadVisibleDataHook?.off(triggerReload)
- openNewRecordFormHook?.off(openNewRecordHandler)
- selectCellHook.off(selectCell)
-})
-
-eventBus.on(async (event, payload) => {
+const smartsheetEvents = async (event: SmartsheetStoreEvents, payload) => {
if (event === SmartsheetStoreEvents.CLEAR_NEW_ROW) {
selection.value.clear()
activeCell.value.row = -1
@@ -2543,6 +2536,16 @@ eventBus.on(async (event, payload) => {
calculateSlices()
requestAnimationFrame(triggerRefreshCanvas)
}
+}
+
+eventBus.on(smartsheetEvents)
+
+onBeforeUnmount(() => {
+ eventBus.off(smartsheetEvents)
+ reloadViewDataHook.off(reloadViewDataHookHandler)
+ reloadVisibleDataHook?.off(triggerReload)
+ openNewRecordFormHook?.off(openNewRecordHandler)
+ selectCellHook.off(selectCell)
})
function resetActiveCell(path?: Array<number>, force = false) {
diff --git a/packages/nc-gui/components/smartsheet/grid/canvas/loaders/ActionManager.ts b/packages/nc-gui/components/smartsheet/grid/canvas/loaders/ActionManager.ts
index 3cf6ae976c..1073403660 100644
--- a/packages/nc-gui/components/smartsheet/grid/canvas/loaders/ActionManager.ts
+++ b/packages/nc-gui/components/smartsheet/grid/canvas/loaders/ActionManager.ts
@@ -73,66 +73,72 @@ export class ActionManager {
this.setupEventListeners()
}
- private setupEventListeners() {
- if (!this.eventBus) return
-
- const eventHandlers = {
- [SmartsheetScriptActions.BULK_ACTION_START]: (payload: any) => {
- this.activeBulkExecs.set(payload.columnId, true)
- this.startAnimationLoop()
- },
- [SmartsheetScriptActions.BULK_ACTION_END]: (payload: any) => {
- if (payload.columnId) {
- this.activeBulkExecs.delete(payload.columnId)
- this.clearBulkRowStatesForColumn(payload.columnId)
- }
- },
- [SmartsheetScriptActions.BUTTON_ACTION_START]: (payload: any) => {
+ private eventMap = {
+ [SmartsheetScriptActions.BULK_ACTION_START]: (payload: any) => {
+ this.activeBulkExecs.set(payload.columnId, true)
+ this.startAnimationLoop()
+ },
+ [SmartsheetScriptActions.BULK_ACTION_END]: (payload: any) => {
+ if (payload.columnId) {
+ this.activeBulkExecs.delete(payload.columnId)
+ this.clearBulkRowStatesForColumn(payload.columnId)
+ }
+ },
+ [SmartsheetScriptActions.BUTTON_ACTION_START]: (payload: any) => {
+ this.setBulkRowState(payload.rowId, payload.columnId, {
+ status: 'loading',
+ startTime: Date.now(),
+ stepTitle: payload.stepTitle,
+ })
+ },
+ [SmartsheetScriptActions.BUTTON_ACTION_PROGRESS]: (payload: any) => {
+ console.log('BUTTON_ACTION_PROGRESS', payload)
+ const rowState = this.getBulkRowState(payload.rowId, payload.columnId)
+ if (rowState) {
this.setBulkRowState(payload.rowId, payload.columnId, {
- status: 'loading',
- startTime: Date.now(),
+ ...rowState,
stepTitle: payload.stepTitle,
})
- },
- [SmartsheetScriptActions.BUTTON_ACTION_PROGRESS]: (payload: any) => {
- console.log('BUTTON_ACTION_PROGRESS', payload)
- const rowState = this.getBulkRowState(payload.rowId, payload.columnId)
- if (rowState) {
- this.setBulkRowState(payload.rowId, payload.columnId, {
- ...rowState,
- stepTitle: payload.stepTitle,
- })
- }
- },
- [SmartsheetScriptActions.BUTTON_ACTION_COMPLETE]: (payload: any) => {
- this.setBulkRowState(payload.rowId, payload.columnId, {
- status: payload.success ? 'success' : 'error',
- error: payload.error,
- })
- },
- [SmartsheetScriptActions.BUTTON_ACTION_ERROR]: (payload: any) => {
- this.setBulkRowState(payload.rowId, payload.columnId, {
- status: 'error',
- error: payload.error,
- })
- },
- [SmartsheetScriptActions.UPDATE_STEP_TITLE]: (payload: any) => {
- this.setCurrentStepTitle(payload.pk, payload.fieldId, payload.title)
- },
- [SmartsheetScriptActions.START_CELL_UPDATE]: (payload: any) => {
- this.startCellUpdate(payload.recordId, payload.fieldId, payload.fieldName, payload.scriptId)
- },
- [SmartsheetScriptActions.COMPLETE_CELL_UPDATE]: (payload: any) => {
- this.completeCellUpdate(payload.recordId, payload.fieldId)
- },
- [SmartsheetScriptActions.CLEAR_SCRIPT_CELL_UPDATES]: (payload: any) => {
- this.clearScriptCellUpdates(payload.scriptId)
- },
- }
+ }
+ },
+ [SmartsheetScriptActions.BUTTON_ACTION_COMPLETE]: (payload: any) => {
+ this.setBulkRowState(payload.rowId, payload.columnId, {
+ status: payload.success ? 'success' : 'error',
+ error: payload.error,
+ })
+ },
+ [SmartsheetScriptActions.BUTTON_ACTION_ERROR]: (payload: any) => {
+ this.setBulkRowState(payload.rowId, payload.columnId, {
+ status: 'error',
+ error: payload.error,
+ })
+ },
+ [SmartsheetScriptActions.UPDATE_STEP_TITLE]: (payload: any) => {
+ this.setCurrentStepTitle(payload.pk, payload.fieldId, payload.title)
+ },
+ [SmartsheetScriptActions.START_CELL_UPDATE]: (payload: any) => {
+ this.startCellUpdate(payload.recordId, payload.fieldId, payload.fieldName, payload.scriptId)
+ },
+ [SmartsheetScriptActions.COMPLETE_CELL_UPDATE]: (payload: any) => {
+ this.completeCellUpdate(payload.recordId, payload.fieldId)
+ },
+ [SmartsheetScriptActions.CLEAR_SCRIPT_CELL_UPDATES]: (payload: any) => {
+ this.clearScriptCellUpdates(payload.scriptId)
+ },
+ }
- this.eventBus.on((event: string, payload: any) => {
- eventHandlers[event]?.(payload)
- })
+ private eventHandler = (event: string, payload: any) => {
+ this.eventMap[event]?.(payload)
+ }
+
+ private setupEventListeners() {
+ if (!this.eventBus) return
+ this.eventBus.on(this.eventHandler)
+ }
+
+ public releaseEventListeners() {
+ if (!this.eventBus) return
+ this.eventBus.off(this.eventHandler)
}
private getKey(rowId: string, columnId: string): string {
diff --git a/packages/nc-gui/components/smartsheet/grid/index.vue b/packages/nc-gui/components/smartsheet/grid/index.vue
index 4b508445be..1418c752f9 100644
--- a/packages/nc-gui/components/smartsheet/grid/index.vue
+++ b/packages/nc-gui/components/smartsheet/grid/index.vue
@@ -192,10 +192,16 @@ const { windowSize, leftSidebarWidth } = toRefs(sidebarStore)
const viewWidth = ref(0)
-eventBus.on((event) => {
+const smartsheetEvents = (event: SmartsheetStoreEvents) => {
if (event === SmartsheetStoreEvents.GROUP_BY_RELOAD || event === SmartsheetStoreEvents.DATA_RELOAD) {
reloadViewDataHook?.trigger()
}
+}
+
+eventBus.on(smartsheetEvents)
+
+onBeforeUnmount(() => {
+ eventBus.off(smartsheetEvents)
})
const goToNextRow = () => {
diff --git a/packages/nc-gui/components/smartsheet/toolbar/ColumnFilterMenu.vue b/packages/nc-gui/components/smartsheet/toolbar/ColumnFilterMenu.vue
index d684cb8cbe..9d88fd52f8 100644
--- a/packages/nc-gui/components/smartsheet/toolbar/ColumnFilterMenu.vue
+++ b/packages/nc-gui/components/smartsheet/toolbar/ColumnFilterMenu.vue
@@ -68,7 +68,7 @@ useMenuCloseOnEsc(open)
const draftFilter = ref({})
const queryFilterOpen = ref(false)
-eventBus.on(async (event, payload) => {
+const smartsheetEventListener = async (event: string, payload?: any) => {
if (validateViewConfigOverrideEvent(event, ViewSettingOverrideOptions.FILTER_CONDITION, payload) && activeView?.value?.id) {
await loadFilters({
hookId: undefined,
@@ -89,6 +89,12 @@ eventBus.on(async (event, payload) => {
draftFilter.value = { fk_column_id: column.id }
open.value = true
}
+}
+
+eventBus.on(smartsheetEventListener)
+
+onBeforeUnmount(() => {
+ eventBus.off(smartsheetEventListener)
})
const combinedFilterLength = computed(() => {
diff --git a/packages/nc-gui/components/smartsheet/toolbar/FieldsMenu.vue b/packages/nc-gui/components/smartsheet/toolbar/FieldsMenu.vue
index beb0ac37fa..52fb3a8f1e 100644
--- a/packages/nc-gui/components/smartsheet/toolbar/FieldsMenu.vue
+++ b/packages/nc-gui/components/smartsheet/toolbar/FieldsMenu.vue
@@ -63,7 +63,7 @@ const viewStore = useViewsStore()
const { updateViewMeta } = viewStore
-eventBus.on(async (event, payload) => {
+const eventBusHandler = async (event: SmartsheetStoreEvents, payload?: any) => {
if (event === SmartsheetStoreEvents.FIELD_RELOAD) {
try {
await loadViewColumns()
@@ -73,6 +73,12 @@ eventBus.on(async (event, payload) => {
} else if (event === SmartsheetStoreEvents.MAPPED_BY_COLUMN_CHANGE) {
loadViewColumns()
}
+}
+
+eventBus.on(eventBusHandler)
+
+onBeforeUnmount(() => {
+ eventBus.off(eventBusHandler)
})
const gridDisplayValueField = computed(() => {
diff --git a/packages/nc-gui/components/smartsheet/toolbar/GroupByMenu.vue b/packages/nc-gui/components/smartsheet/toolbar/GroupByMenu.vue
index 54c87d0165..4c96b5989e 100644
--- a/packages/nc-gui/components/smartsheet/toolbar/GroupByMenu.vue
+++ b/packages/nc-gui/components/smartsheet/toolbar/GroupByMenu.vue
@@ -154,8 +154,8 @@ watch(open, () => {
}
})
-eventBus.on(async (event, payload = {}) => {
- const column = payload.column
+const smartSheetListener = async (event: SmartsheetStoreEvents, payload = {}) => {
+ const column = payload?.column
if (!column?.id) return
@@ -168,6 +168,12 @@ eventBus.on(async (event, payload = {}) => {
await saveGroupBy()
}
+}
+
+eventBus.on(smartSheetListener)
+
+onBeforeUnmount(() => {
+ eventBus.off(smartSheetListener)
})
const onMove = async (event: { moved: { newIndex: number; oldIndex: number } }) => {
diff --git a/packages/nc-gui/components/smartsheet/toolbar/SortListMenu.vue b/packages/nc-gui/components/smartsheet/toolbar/SortListMenu.vue
index 5dbceb6fe8..a92bffa049 100644
--- a/packages/nc-gui/components/smartsheet/toolbar/SortListMenu.vue
+++ b/packages/nc-gui/components/smartsheet/toolbar/SortListMenu.vue
@@ -31,13 +31,19 @@ const isToolbarIconMode = inject(
computed(() => false),
)
-eventBus.on((event, payload) => {
+const smartsheetEventHandler = (event: SmartsheetStoreEvents) => {
if (
event === SmartsheetStoreEvents.SORT_RELOAD ||
validateViewConfigOverrideEvent(event, ViewSettingOverrideOptions.SORT, payload)
) {
loadSorts()
}
+}
+
+eventBus.on(smartsheetEventHandler)
+
+onBeforeUnmount(() => {
+ eventBus.off(smartsheetEventHandler)
})
const columns = computed(() =>
diff --git a/packages/nc-gui/composables/useCalendarViewStore.ts b/packages/nc-gui/composables/useCalendarViewStore.ts
index 22a25b2619..2fe628a51c 100644
--- a/packages/nc-gui/composables/useCalendarViewStore.ts
+++ b/packages/nc-gui/composables/useCalendarViewStore.ts
@@ -949,7 +949,7 @@ const [useProvideCalendarViewStore, useCalendarViewStore] = useInjectionState(
/**
* This is used to update the rowMeta color info when the row colour info is updated
*/
- eventBus.on((event) => {
+ const smartsheetEventHandler = (event) => {
if (![SmartsheetStoreEvents.TRIGGER_RE_RENDER, SmartsheetStoreEvents.ON_ROW_COLOUR_INFO_UPDATE].includes(event)) {
return
}
@@ -963,7 +963,9 @@ const [useProvideCalendarViewStore, useCalendarViewStore] = useInjectionState(
Object.assign(row.rowMeta, getEvaluatedRowMetaRowColorInfo(row.row))
return row
})
- })
+ }
+
+ eventBus.on(smartsheetEventHandler)
const updateActiveDatesForNewRecord = (rowData: Record<string, any>): void => {
if (!calendarRange.value?.length) return
@@ -1206,6 +1208,7 @@ const [useProvideCalendarViewStore, useCalendarViewStore] = useInjectionState(
if (activeDataListener.value) {
$ncSocket.offMessage(activeDataListener.value)
}
+ eventBus.off(smartsheetEventHandler)
})
return {
diff --git a/packages/nc-gui/composables/useInfiniteData.ts b/packages/nc-gui/composables/useInfiniteData.ts
index 99ce40cbff..080c21d379 100644
--- a/packages/nc-gui/composables/useInfiniteData.ts
+++ b/packages/nc-gui/composables/useInfiniteData.ts
@@ -592,6 +592,7 @@ export function useInfiniteData(args: {
let upgradeModalTimer: any
onBeforeUnmount(() => {
+ eventBus.off(smartsheetEventHandler)
clearTimeout(upgradeModalTimer)
})
@@ -2011,7 +2012,7 @@ export function useInfiniteData(args: {
/**
* This is used to update the rowMeta color info when the row colour info is updated
*/
- eventBus.on((event) => {
+ const smartsheetEventHandler = (event: SmartsheetStoreEvents) => {
if (![SmartsheetStoreEvents.TRIGGER_RE_RENDER, SmartsheetStoreEvents.ON_ROW_COLOUR_INFO_UPDATE].includes(event)) {
return
}
@@ -2031,7 +2032,9 @@ export function useInfiniteData(args: {
Object.assign(row.rowMeta, getEvaluatedRowMetaRowColorInfo(row.row))
})
}
- })
+ }
+
+ eventBus.on(smartsheetEventHandler)
const activeDataListener = ref<string | null>(null)
const activeCommentListener = ref<string | null>(null)
diff --git a/packages/nc-gui/composables/useKanbanViewStore.ts b/packages/nc-gui/composables/useKanbanViewStore.ts
index d577f28b13..057d86bc6a 100644
--- a/packages/nc-gui/composables/useKanbanViewStore.ts
+++ b/packages/nc-gui/composables/useKanbanViewStore.ts
@@ -753,7 +753,7 @@ const [useProvideKanbanViewStore, useKanbanViewStore] = useInjectionState(
/**
* This is used to update the rowMeta color info when the row colour info is updated
*/
- eventBus.on((event) => {
+ const smartsheetStoreEventHandler = (event: SmartsheetStoreEvents) => {
if (![SmartsheetStoreEvents.TRIGGER_RE_RENDER, SmartsheetStoreEvents.ON_ROW_COLOUR_INFO_UPDATE].includes(event)) {
return
}
@@ -771,7 +771,9 @@ const [useProvideKanbanViewStore, useKanbanViewStore] = useInjectionState(
formattedData.value.set(key, formattedDataCopy)
})
- })
+ }
+
+ eventBus.on(smartsheetStoreEventHandler)
watch([groupingFieldColumn], () => {
loadKanbanData()
@@ -928,6 +930,7 @@ const [useProvideKanbanViewStore, useKanbanViewStore] = useInjectionState(
)
onBeforeUnmount(() => {
+ eventBus.off(smartsheetStoreEventHandler)
if (activeDataListener.value) {
$ncSocket.offMessage(activeDataListener.value)
}
diff --git a/packages/nc-gui/extensions/data-exporter/index.vue b/packages/nc-gui/extensions/data-exporter/index.vue
index 75dc72bb52..2eec7dc9fc 100644
--- a/packages/nc-gui/extensions/data-exporter/index.vue
+++ b/packages/nc-gui/extensions/data-exporter/index.vue
@@ -250,7 +250,7 @@ const filterOption = (input: string, option: { key: string }) => {
return option.key?.toLowerCase()?.includes(input?.toLowerCase())
}
-eventBus.on(async (event, payload) => {
+const extensionEvents = async (event: string, payload) => {
if (event === ExtensionsEvents.CLEARDATA && payload && extension.value.id && payload === extension.value.id) {
const deleteExportsPayload = exportedFiles.value.map((exp) => exp.id)
@@ -259,6 +259,12 @@ eventBus.on(async (event, payload) => {
await extension.value.kvStore.set('deletedExports', deletedExports.value)
}
}
+}
+
+eventBus.on(extensionEvents)
+
+onBeforeUnmount(() => {
+ eventBus.off(extensionEvents)
})
onMounted(async () => {