π₯ π₯ π₯ A Free & Self-hostable Airtable Alternative
TypeScript airtableairtable-alternativeautomatic-apihacktoberfestlow-codeno-codeno-code-databaseno-code-platformpostgresqlrest-apirestful-apispreadsheetsqliteswagger
fix: avoid leaking listeners
mertmit44460e753649
diff --git a/packages/nc-gui/composables/useExpandedFormStore.ts b/packages/nc-gui/composables/useExpandedFormStore.tsindex adcefbecd1..b64250aa48 100644--- a/packages/nc-gui/composables/useExpandedFormStore.ts+++ b/packages/nc-gui/composables/useExpandedFormStore.ts@@ -775,8 +775,8 @@ const [useProvideExpandedFormStore, useExpandedFormStore] = useInjectionState(}})- const activeDataChannel = ref<string | null>(null)- const activeCommentChannel = ref<string | null>(null)+ const activeDataListener = ref<string | null>(null)+ const activeCommentListener = ref<string | null>(null)watch(meta,@@ -784,85 +784,85 @@ const [useProvideExpandedFormStore, useExpandedFormStore] = useInjectionState(if (newMeta?.fk_workspace_id && newMeta?.base_id && newMeta?.id) {if (oldMeta?.id && oldMeta.id === newMeta.id) return- if (activeDataChannel.value) {- $ncSocket.offMessage(activeDataChannel.value)+ if (activeDataListener.value) {+ $ncSocket.offMessage(activeDataListener.value)}- if (activeCommentChannel.value) {- $ncSocket.offMessage(activeCommentChannel.value)+ if (activeCommentListener.value) {+ $ncSocket.offMessage(activeCommentListener.value)}- activeDataChannel.value = `${EventType.DATA_EVENT}:${newMeta.fk_workspace_id}:${newMeta.base_id}:${newMeta.id}`- activeCommentChannel.value = `${EventType.COMMENT_EVENT}:${newMeta.fk_workspace_id}:${newMeta.base_id}:${newMeta.id}`-- $ncSocket.subscribe(activeDataChannel.value)- $ncSocket.subscribe(activeCommentChannel.value)-- $ncSocket.onMessage(activeDataChannel.value, (data: DataPayload) => {- const { id, action, payload } = data-- const activePk = extractPkFromRow(row.value.row, meta.value?.columns as ColumnType[])-- if (`${id}` === activePk) {- if (action === 'update') {- try {- if (payload) {- // Merge payload with local row, but preserve locally changed columns- const mergedRow = { ...row.value.row, ...payload }- for (const col of changedColumns.value) {- if (Object.prototype.hasOwnProperty.call(row.value.row, col)) {- mergedRow[col] = row.value.row[col]- if (row.value.row[col] !== payload[col]) {- localOnlyChanges.value[col] = payload[col]+ activeDataListener.value = $ncSocket.onMessage(+ `${EventType.DATA_EVENT}:${newMeta.fk_workspace_id}:${newMeta.base_id}:${newMeta.id}`,+ (data: DataPayload) => {+ const { id, action, payload } = data++ const activePk = extractPkFromRow(row.value.row, meta.value?.columns as ColumnType[])++ if (`${id}` === activePk) {+ if (action === 'update') {+ try {+ if (payload) {+ // Merge payload with local row, but preserve locally changed columns+ const mergedRow = { ...row.value.row, ...payload }+ for (const col of changedColumns.value) {+ if (Object.prototype.hasOwnProperty.call(row.value.row, col)) {+ mergedRow[col] = row.value.row[col]+ if (row.value.row[col] !== payload[col]) {+ localOnlyChanges.value[col] = payload[col]+ }}}+ Object.assign(row.value, {+ row: mergedRow,+ oldRow: { ...mergedRow },+ })+ // Do NOT clear changedColumns here, as we want to preserve local changes+ } else {+ console.warn('No payload provided for update action')}- Object.assign(row.value, {- row: mergedRow,- oldRow: { ...mergedRow },- })- // Do NOT clear changedColumns here, as we want to preserve local changes- } else {- console.warn('No payload provided for update action')+ } catch (e) {+ console.error('Failed to update cached row on socket event', e)+ }+ } else if (action === 'delete') {+ try {+ //+ } catch (e) {+ console.error('Failed to delete cached row on socket event', e)}- } catch (e) {- console.error('Failed to update cached row on socket event', e)- }- } else if (action === 'delete') {- try {- //- } catch (e) {- console.error('Failed to delete cached row on socket event', e)}}- }- })+ },+ )- $ncSocket.onMessage(activeCommentChannel.value, (data: CommentPayload) => {- const { action, id, payload } = data-- if (primaryKey.value && `${id}` === `${primaryKey.value}`) {- const commentId = payload.id- const user = baseUsers.value.find((u) => u.id === payload.created_by)- const finalPayload = {- ...payload,- created_display_name: user?.display_name ?? (user?.email ?? '').split('@')[0],- created_by_email: user?.email,- created_by_meta: user?.meta,- }+ activeCommentListener.value = $ncSocket.onMessage(+ `${EventType.COMMENT_EVENT}:${newMeta.fk_workspace_id}:${newMeta.base_id}:${newMeta.id}`,+ (data: CommentPayload) => {+ const { action, id, payload } = data++ if (primaryKey.value && `${id}` === `${primaryKey.value}`) {+ const commentId = payload.id+ const user = baseUsers.value.find((u) => u.id === payload.created_by)+ const finalPayload = {+ ...payload,+ created_display_name: user?.display_name ?? (user?.email ?? '').split('@')[0],+ created_by_email: user?.email,+ created_by_meta: user?.meta,+ }- if (action === 'add') {- comments.value.push(finalPayload)- } else if (action === 'update') {- const index = comments.value.findIndex((comment) => comment.id === commentId)- if (index !== -1) {- comments.value[index] = finalPayload+ if (action === 'add') {+ comments.value.push(finalPayload)+ } else if (action === 'update') {+ const index = comments.value.findIndex((comment) => comment.id === commentId)+ if (index !== -1) {+ comments.value[index] = finalPayload+ }+ } else if (action === 'delete') {+ comments.value = comments.value.filter((comment) => comment.id !== commentId)}- } else if (action === 'delete') {- comments.value = comments.value.filter((comment) => comment.id !== commentId)}- }- })+ },+ )}},{ immediate: true },diff --git a/packages/nc-gui/composables/useInfiniteData.ts b/packages/nc-gui/composables/useInfiniteData.tsindex e610451367..cf9706237e 100644--- a/packages/nc-gui/composables/useInfiniteData.ts+++ b/packages/nc-gui/composables/useInfiniteData.ts@@ -2021,8 +2021,8 @@ export function useInfiniteData(args: {}})- const activeDataChannel = ref<string | null>(null)- const activeCommentChannel = ref<string | null>(null)+ const activeDataListener = ref<string | null>(null)+ const activeCommentListener = ref<string | null>(null)watch(meta,@@ -2030,151 +2030,208 @@ export function useInfiniteData(args: {if (newMeta?.fk_workspace_id && newMeta?.base_id && newMeta?.id) {if (oldMeta?.id && oldMeta.id === newMeta.id) return- if (activeDataChannel.value) {- $ncSocket.offMessage(activeDataChannel.value)+ if (activeDataListener.value) {+ $ncSocket.offMessage(activeDataListener.value)}- if (activeCommentChannel.value) {- $ncSocket.offMessage(activeCommentChannel.value)+ if (activeCommentListener.value) {+ $ncSocket.offMessage(activeCommentListener.value)}- activeDataChannel.value = `${EventType.DATA_EVENT}:${newMeta.fk_workspace_id}:${newMeta.base_id}:${newMeta.id}`- activeCommentChannel.value = `${EventType.COMMENT_EVENT}:${newMeta.fk_workspace_id}:${newMeta.base_id}:${newMeta.id}`+ activeDataListener.value = $ncSocket.onMessage(+ `${EventType.DATA_EVENT}:${newMeta.fk_workspace_id}:${newMeta.base_id}:${newMeta.id}`,+ (data: DataPayload) => {+ const { id, action, payload, before } = data- $ncSocket.subscribe(activeDataChannel.value)- $ncSocket.subscribe(activeCommentChannel.value)+ if (action === 'add') {+ // Add the new row to the local cache (cachedRows)+ try {+ const dataCache = getDataCache()- $ncSocket.onMessage(activeDataChannel.value, (data: DataPayload) => {- const { id, action, payload, before } = data+ // find index to insert the new row+ if (before) {+ for (const [rowIndex, cachedRow] of dataCache.cachedRows.value.entries()) {+ const pk = extractPkFromRow(cachedRow.row, meta.value?.columns as ColumnType[])+ if (pk && `${pk}` === `${before}`) {+ // Insert before the found row+ const newRowIndex = rowIndex+ // Use descending order so that we first open the position then place the new record+ const rowsToShift = Array.from(dataCache.cachedRows.value.entries())+ .filter(([index]) => index >= newRowIndex)+ .sort((a, b) => b[0] - a[0])++ for (const [index, rowData] of rowsToShift) {+ rowData.rowMeta.rowIndex = index + 1+ dataCache.cachedRows.value.delete(index)+ dataCache.cachedRows.value.set(index + 1, rowData)+ }- if (action === 'add') {- // Add the new row to the local cache (cachedRows)- try {- const dataCache = getDataCache()+ dataCache.cachedRows.value.set(newRowIndex, {+ row: payload,+ oldRow: {},+ rowMeta: { new: false, rowIndex: newRowIndex, path: [] },+ })- // find index to insert the new row- if (before) {- for (const [rowIndex, cachedRow] of dataCache.cachedRows.value.entries()) {- const pk = extractPkFromRow(cachedRow.row, meta.value?.columns as ColumnType[])- if (pk && `${pk}` === `${before}`) {- // Insert before the found row- const newRowIndex = rowIndex- // Use descending order so that we first open the position then place the new record- const rowsToShift = Array.from(dataCache.cachedRows.value.entries())- .filter(([index]) => index >= newRowIndex)- .sort((a, b) => b[0] - a[0])-- for (const [index, rowData] of rowsToShift) {- rowData.rowMeta.rowIndex = index + 1- dataCache.cachedRows.value.delete(index)- dataCache.cachedRows.value.set(index + 1, rowData)- }+ dataCache.totalRows.value+++ dataCache.actualTotalRows.value = Math.max(dataCache.actualTotalRows.value || 0, dataCache.totalRows.value)- dataCache.cachedRows.value.set(newRowIndex, {- row: payload,- oldRow: {},- rowMeta: { new: false, rowIndex: newRowIndex, path: [] },- })+ callbacks?.syncVisibleData?.()+ return+ }+ }+ }- dataCache.totalRows.value++- dataCache.actualTotalRows.value = Math.max(dataCache.actualTotalRows.value || 0, dataCache.totalRows.value)+ // If no order is found, append to the end+ const newRowIndex = dataCache.totalRows.value+ dataCache.cachedRows.value.set(newRowIndex, {+ row: payload,+ oldRow: {},+ rowMeta: { new: false, rowIndex: newRowIndex, path: [] },+ })+ dataCache.totalRows.value+++ dataCache.actualTotalRows.value = Math.max(dataCache.actualTotalRows.value || 0, dataCache.totalRows.value)- callbacks?.syncVisibleData?.()- return+ callbacks?.syncVisibleData?.()+ } catch (e) {+ console.error('Failed to add cached row on socket event', e)+ }+ } else if (action === 'update') {+ // Update the row in the local cache (cachedRows)+ try {+ const dataCache = getDataCache()+ let updated = false+ for (const cachedRow of dataCache.cachedRows.value.values()) {+ const pk = extractPkFromRow(cachedRow.row, meta.value?.columns as ColumnType[])+ if (pk && `${pk}` === `${id}`) {+ Object.assign(cachedRow.row, payload)+ Object.assign(cachedRow.oldRow, payload)+ cachedRow.rowMeta.changed = false+ updated = true+ break}}+ if (updated) {+ callbacks?.syncVisibleData?.()+ }+ } catch (e) {+ console.error('Failed to update cached row on socket event', e)}+ } else if (action === 'delete') {+ // Delete the row from the local cache (cachedRows)+ try {+ const dataCache = getDataCache()+ for (const [rowIndex, cachedRow] of dataCache.cachedRows.value.entries()) {+ const pk = extractPkFromRow(cachedRow.row, meta.value?.columns as ColumnType[])+ if (pk && `${pk}` === `${id}`) {+ dataCache.cachedRows.value.delete(rowIndex)- // If no order is found, append to the end- const newRowIndex = dataCache.totalRows.value- dataCache.cachedRows.value.set(newRowIndex, {- row: payload,- oldRow: {},- rowMeta: { new: false, rowIndex: newRowIndex, path: [] },- })- dataCache.totalRows.value++- dataCache.actualTotalRows.value = Math.max(dataCache.actualTotalRows.value || 0, dataCache.totalRows.value)+ const rows = Array.from(dataCache.cachedRows.value.entries())+ const rowsToShift = rows.filter(([index]) => index > rowIndex)+ rowsToShift.sort((a, b) => a[0] - b[0])- callbacks?.syncVisibleData?.()- } catch (e) {- console.error('Failed to add cached row on socket event', e)- }- } else if (action === 'update') {- // Update the row in the local cache (cachedRows)- try {- const dataCache = getDataCache()- let updated = false- for (const cachedRow of dataCache.cachedRows.value.values()) {- const pk = extractPkFromRow(cachedRow.row, meta.value?.columns as ColumnType[])- if (pk && `${pk}` === `${id}`) {- Object.assign(cachedRow.row, payload)- Object.assign(cachedRow.oldRow, payload)- cachedRow.rowMeta.changed = false- updated = true- break+ for (const [index, row] of rowsToShift) {+ const newIndex = index - 1+ row.rowMeta.rowIndex = newIndex+ dataCache.cachedRows.value.delete(index)+ dataCache.cachedRows.value.set(newIndex, row)+ }++ if (rowsToShift.length) {+ dataCache.chunkStates.value[getChunkIndex(rowsToShift[rowsToShift.length - 1][0])] = undefined+ }++ dataCache.totalRows.value = (dataCache.totalRows.value || 0) - 1+ dataCache.actualTotalRows.value = Math.max(0, (dataCache.actualTotalRows.value || 0) - 1)+ }}- }- if (updated) {callbacks?.syncVisibleData?.()+ } catch (e) {+ console.error('Failed to delete cached row on socket event', e)}- } catch (e) {- console.error('Failed to update cached row on socket event', e)- }- } else if (action === 'delete') {- // Delete the row from the local cache (cachedRows)- try {- const dataCache = getDataCache()- for (const [rowIndex, cachedRow] of dataCache.cachedRows.value.entries()) {- const pk = extractPkFromRow(cachedRow.row, meta.value?.columns as ColumnType[])- if (pk && `${pk}` === `${id}`) {- dataCache.cachedRows.value.delete(rowIndex)-- const rows = Array.from(dataCache.cachedRows.value.entries())- const rowsToShift = rows.filter(([index]) => index > rowIndex)- rowsToShift.sort((a, b) => a[0] - b[0])-- for (const [index, row] of rowsToShift) {- const newIndex = index - 1- row.rowMeta.rowIndex = newIndex- dataCache.cachedRows.value.delete(index)- dataCache.cachedRows.value.set(newIndex, row)+ } else if (action === 'reorder') {+ // Reorder/move the row in the local cache (cachedRows)+ try {+ const dataCache = getDataCache()++ // Find the row to be moved by its primary key+ let rowToMove: Row | null = null+ let currentIndex: number | null = null++ for (const [index, cachedRow] of dataCache.cachedRows.value.entries()) {+ const pk = extractPkFromRow(cachedRow.row, meta.value?.columns as ColumnType[])+ if (pk && `${pk}` === `${id}`) {+ rowToMove = cachedRow+ currentIndex = index+ break}+ }++ if (!rowToMove || currentIndex === null) {+ console.warn('Row to move not found in cache:', id)++ if (before) {+ // Find the 'before' row in cache+ let beforeIndex: number | null = null+ for (const [index, cachedRow] of dataCache.cachedRows.value.entries()) {+ const pk = extractPkFromRow(cachedRow.row, meta.value?.columns as ColumnType[])+ if (pk && `${pk}` === `${before}`) {+ beforeIndex = index+ break+ }+ }- if (rowsToShift.length) {- dataCache.chunkStates.value[getChunkIndex(rowsToShift[rowsToShift.length - 1][0])] = undefined+ if (beforeIndex !== null) {+ // The new row position is before an existing cached row+ // We need to shift all rows from beforeIndex onwards down by 1+ const newCachedRows = new Map(dataCache.cachedRows.value.entries())++ // Get all rows that need to be shifted (from beforeIndex onwards)+ const rowsToShift = Array.from((dataCache.cachedRows.value as Map<number, Row>).entries())+ .filter(([index]) => index >= beforeIndex!)+ .sort((a, b) => b[0] - a[0])++ // Shift each row down by 1+ for (const [index, row] of rowsToShift) {+ const newIndex = index + 1+ row.rowMeta.rowIndex = newIndex+ newCachedRows.delete(index)+ newCachedRows.set(newIndex, row)+ }++ // Invalidate affected chunks+ if (rowsToShift.length > 0) {+ const minAffectedChunk = getChunkIndex(beforeIndex!)+ const maxAffectedChunk = getChunkIndex(rowsToShift[rowsToShift.length - 1][0] + 1)+ for (let i = minAffectedChunk; i <= maxAffectedChunk; i++) {+ dataCache.chunkStates.value[i] = undefined+ }+ }++ // Apply the changes+ dataCache.cachedRows.value = newCachedRows++ callbacks?.syncVisibleData?.()+ } else {+ // The 'before' row is not in cache, skip+ console.log('Before row not in cache, skipping reorder operation')+ }+ } else {+ // No 'before' specified means move to end+ // No changes needed to cache since it's moving to the end+ console.log('Row moved to end, no cache changes needed')+ callbacks?.syncVisibleData?.()}- dataCache.totalRows.value = (dataCache.totalRows.value || 0) - 1- dataCache.actualTotalRows.value = Math.max(0, (dataCache.actualTotalRows.value || 0) - 1)+ return}- }- callbacks?.syncVisibleData?.()- } catch (e) {- console.error('Failed to delete cached row on socket event', e)- }- } else if (action === 'reorder') {- // Reorder/move the row in the local cache (cachedRows)- try {- const dataCache = getDataCache()-- // Find the row to be moved by its primary key- let rowToMove: Row | null = null- let currentIndex: number | null = null-- for (const [index, cachedRow] of dataCache.cachedRows.value.entries()) {- const pk = extractPkFromRow(cachedRow.row, meta.value?.columns as ColumnType[])- if (pk && `${pk}` === `${id}`) {- rowToMove = cachedRow- currentIndex = index- break- }- }- if (!rowToMove || currentIndex === null) {- console.warn('Row to move not found in cache:', id)+ // Row found in cache - proceed with reordering++ // Find the target position based on the 'before' parameter+ let targetIndex: numberif (before) {- // Find the 'before' row in cache+ // Find the row that should come after the moved rowlet beforeIndex: number | null = nullfor (const [index, cachedRow] of dataCache.cachedRows.value.entries()) {const pk = extractPkFromRow(cachedRow.row, meta.value?.columns as ColumnType[])@@ -2185,175 +2242,122 @@ export function useInfiniteData(args: {}if (beforeIndex !== null) {- // The new row position is before an existing cached row- // We need to shift all rows from beforeIndex onwards down by 1- const newCachedRows = new Map(dataCache.cachedRows.value.entries())-- // Get all rows that need to be shifted (from beforeIndex onwards)- const rowsToShift = Array.from((dataCache.cachedRows.value as Map<number, Row>).entries())- .filter(([index]) => index >= beforeIndex!)- .sort((a, b) => b[0] - a[0])-- // Shift each row down by 1- for (const [index, row] of rowsToShift) {- const newIndex = index + 1- row.rowMeta.rowIndex = newIndex- newCachedRows.delete(index)- newCachedRows.set(newIndex, row)- }-- // Invalidate affected chunks- if (rowsToShift.length > 0) {- const minAffectedChunk = getChunkIndex(beforeIndex!)- const maxAffectedChunk = getChunkIndex(rowsToShift[rowsToShift.length - 1][0] + 1)- for (let i = minAffectedChunk; i <= maxAffectedChunk; i++) {- dataCache.chunkStates.value[i] = undefined- }- }-- // Apply the changes- dataCache.cachedRows.value = newCachedRows-- callbacks?.syncVisibleData?.()+ targetIndex = beforeIndex} else {- // The 'before' row is not in cache, skip- console.log('Before row not in cache, skipping reorder operation')+ // If 'before' row not found in cache, move to end+ targetIndex = Math.max(...Array.from(dataCache.cachedRows.value.keys())) + 1}} else {- // No 'before' specified means move to end- // No changes needed to cache since it's moving to the end- console.log('Row moved to end, no cache changes needed')- callbacks?.syncVisibleData?.()+ // If no 'before' specified, move to the end+ targetIndex = Math.max(...Array.from(dataCache.cachedRows.value.keys())) + 1}- return- }+ // If the row is already at the target position, no need to move+ if (currentIndex === targetIndex) {+ return+ }- // Row found in cache - proceed with reordering+ // Create a new cached rows map with the updated positions+ const newCachedRows = new Map(dataCache.cachedRows.value.entries())- // Find the target position based on the 'before' parameter- let targetIndex: number+ // Remove the row from its current position+ newCachedRows.delete(currentIndex)- if (before) {- // Find the row that should come after the moved row- let beforeIndex: number | null = null- for (const [index, cachedRow] of dataCache.cachedRows.value.entries()) {- const pk = extractPkFromRow(cachedRow.row, meta.value?.columns as ColumnType[])- if (pk && `${pk}` === `${before}`) {- beforeIndex = index- break- }- }+ // Determine the final target index (similar to updateRecordOrder logic)+ const finalTargetIndex = targetIndex > currentIndex ? targetIndex - 1 : targetIndex- if (beforeIndex !== null) {- targetIndex = beforeIndex+ // Shift rows to make space for the moved row+ if (finalTargetIndex < currentIndex) {+ // Moving up: shift rows down+ for (let i = currentIndex - 1; i >= finalTargetIndex; i--) {+ const row = newCachedRows.get(i)+ if (row) {+ const newIndex = i + 1+ row.rowMeta.rowIndex = newIndex+ newCachedRows.delete(i)+ newCachedRows.set(newIndex, row)+ }+ }} else {- // If 'before' row not found in cache, move to end- targetIndex = Math.max(...Array.from(dataCache.cachedRows.value.keys())) + 1+ // Moving down: shift rows up+ for (let i = currentIndex + 1; i <= finalTargetIndex; i++) {+ const row = newCachedRows.get(i)+ if (row) {+ const newIndex = i - 1+ row.rowMeta.rowIndex = newIndex+ newCachedRows.delete(i)+ newCachedRows.set(newIndex, row)+ }+ }}- } else {- // If no 'before' specified, move to the end- targetIndex = Math.max(...Array.from(dataCache.cachedRows.value.keys())) + 1- }- // If the row is already at the target position, no need to move- if (currentIndex === targetIndex) {- return- }+ // Place the moved row at its new position+ rowToMove.rowMeta.rowIndex = finalTargetIndex+ newCachedRows.set(finalTargetIndex, rowToMove)- // Create a new cached rows map with the updated positions- const newCachedRows = new Map(dataCache.cachedRows.value.entries())-- // Remove the row from its current position- newCachedRows.delete(currentIndex)-- // Determine the final target index (similar to updateRecordOrder logic)- const finalTargetIndex = targetIndex > currentIndex ? targetIndex - 1 : targetIndex-- // Shift rows to make space for the moved row- if (finalTargetIndex < currentIndex) {- // Moving up: shift rows down- for (let i = currentIndex - 1; i >= finalTargetIndex; i--) {- const row = newCachedRows.get(i)- if (row) {- const newIndex = i + 1- row.rowMeta.rowIndex = newIndex- newCachedRows.delete(i)- newCachedRows.set(newIndex, row)- }+ // Update any changed data in the moved row (if payload contains updates)+ if (payload && typeof payload === 'object') {+ Object.assign(rowToMove.row, payload)+ Object.assign(rowToMove.oldRow, payload)}- } else {- // Moving down: shift rows up- for (let i = currentIndex + 1; i <= finalTargetIndex; i++) {- const row = newCachedRows.get(i)- if (row) {- const newIndex = i - 1- row.rowMeta.rowIndex = newIndex- newCachedRows.delete(i)- newCachedRows.set(newIndex, row)- }+ rowToMove.rowMeta.changed = false++ // Invalidate affected chunks+ const targetChunkIndex = getChunkIndex(finalTargetIndex)+ const sourceChunkIndex = getChunkIndex(currentIndex)+ for (+ let i = Math.min(sourceChunkIndex, targetChunkIndex);+ i <= Math.max(sourceChunkIndex, targetChunkIndex);+ i+++ ) {+ dataCache.chunkStates.value[i] = undefined}- }- // Place the moved row at its new position- rowToMove.rowMeta.rowIndex = finalTargetIndex- newCachedRows.set(finalTargetIndex, rowToMove)+ // Apply the changes+ dataCache.cachedRows.value = newCachedRows- // Update any changed data in the moved row (if payload contains updates)- if (payload && typeof payload === 'object') {- Object.assign(rowToMove.row, payload)- Object.assign(rowToMove.oldRow, payload)- }- rowToMove.rowMeta.changed = false-- // Invalidate affected chunks- const targetChunkIndex = getChunkIndex(finalTargetIndex)- const sourceChunkIndex = getChunkIndex(currentIndex)- for (let i = Math.min(sourceChunkIndex, targetChunkIndex); i <= Math.max(sourceChunkIndex, targetChunkIndex); i++) {- dataCache.chunkStates.value[i] = undefined+ callbacks?.syncVisibleData?.()+ } catch (e) {+ console.error('Failed to reorder cached row on socket event', e)}-- // Apply the changes- dataCache.cachedRows.value = newCachedRows-- callbacks?.syncVisibleData?.()- } catch (e) {- console.error('Failed to reorder cached row on socket event', e)}- }- })+ },+ )- $ncSocket.onMessage(activeCommentChannel.value, (data: CommentPayload) => {- const { action, id } = data+ activeCommentListener.value = $ncSocket.onMessage(+ `${EventType.COMMENT_EVENT}:${newMeta.fk_workspace_id}:${newMeta.base_id}:${newMeta.id}`,+ (data: CommentPayload) => {+ const { action, id } = data- const dataCache = getDataCache()+ const dataCache = getDataCache()- let row = null+ let row = null- for (const [_, cachedRow] of dataCache.cachedRows.value.entries()) {- const pk = extractPkFromRow(cachedRow.row, meta.value?.columns as ColumnType[])- if (pk && `${pk}` === `${id}`) {- row = cachedRow- break+ for (const [_, cachedRow] of dataCache.cachedRows.value.entries()) {+ const pk = extractPkFromRow(cachedRow.row, meta.value?.columns as ColumnType[])+ if (pk && `${pk}` === `${id}`) {+ row = cachedRow+ break+ }}- }- if (row) {- if (action === 'add') {- if (row) {- row.rowMeta.commentCount = (row.rowMeta.commentCount || 0) + 1- }- } else if (action === 'update') {- // Handle updated comment- } else if (action === 'delete') {- if (row) {- row.rowMeta.commentCount = Math.max((row.rowMeta.commentCount || 0) - 1, 0)+ if (row) {+ if (action === 'add') {+ if (row) {+ row.rowMeta.commentCount = (row.rowMeta.commentCount || 0) + 1+ }+ } else if (action === 'update') {+ // Handle updated comment+ } else if (action === 'delete') {+ if (row) {+ row.rowMeta.commentCount = Math.max((row.rowMeta.commentCount || 0) - 1, 0)+ }}- }- callbacks?.syncVisibleData?.()- }- })+ callbacks?.syncVisibleData?.()+ }+ },+ )}},{ immediate: true },diff --git a/packages/nc-gui/nuxt-shim.d.ts b/packages/nc-gui/nuxt-shim.d.tsindex 2a49fa3690..846fca4749 100644--- a/packages/nc-gui/nuxt-shim.d.ts+++ b/packages/nc-gui/nuxt-shim.d.ts@@ -36,9 +36,8 @@ declare module '#app' {}$ncSocket: {id: () => string | null- subscribe: (event: string) => void- onMessage: (evt: string, handler: (...args: any[]) => void) => void- offMessage: (evt: string) => void+ onMessage: (evt: string, handler: (...args: any[]) => void) => string+ offMessage: (listenerId: string) => void}$eventBus: {smartsheetStoreEventBus: UseEventBusReturn<string, any>diff --git a/packages/nocodb-sdk/src/lib/realtime/index.ts b/packages/nocodb-sdk/src/lib/realtime/index.tsindex a6297e3838..98cc7e8643 100644--- a/packages/nocodb-sdk/src/lib/realtime/index.ts+++ b/packages/nocodb-sdk/src/lib/realtime/index.ts@@ -66,7 +66,13 @@ export interface MetaPayload<T = any> extends BaseSocketPayload {| 'view_create'| 'view_update'| 'view_delete'- | 'permission_update';+ | 'permission_update'+ | 'filter_create'+ | 'filter_update'+ | 'filter_delete'+ | 'sort_create'+ | 'sort_update'+ | 'sort_delete';payload: T;baseId?: string;}