Home / Function/ reapplyOptimisticUpdates() — supabase Function Reference

reapplyOptimisticUpdates() — supabase Function Reference

Architecture documentation for the reapplyOptimisticUpdates() function in queueOperationUtils.ts from the supabase codebase.

Entity Profile

Dependency Diagram

graph TD
  16d57069_e009_dae3_11f3_3e1e07423636["reapplyOptimisticUpdates()"]
  be97f35c_a68f_0a38_2fc8_b1e46b157381["SupabaseGrid()"]
  be97f35c_a68f_0a38_2fc8_b1e46b157381 -->|calls| 16d57069_e009_dae3_11f3_3e1e07423636
  2bcfeb05_2677_1569_194b_e5c28c769248["applyCellEdit()"]
  16d57069_e009_dae3_11f3_3e1e07423636 -->|calls| 2bcfeb05_2677_1569_194b_e5c28c769248
  30aae06d_5d4f_f515_1e24_486146dfa430["applyRowAdd()"]
  16d57069_e009_dae3_11f3_3e1e07423636 -->|calls| 30aae06d_5d4f_f515_1e24_486146dfa430
  c3ed25f2_a5bf_3779_0009_261419f29eb9["markRowAsDeleted()"]
  16d57069_e009_dae3_11f3_3e1e07423636 -->|calls| c3ed25f2_a5bf_3779_0009_261419f29eb9
  style 16d57069_e009_dae3_11f3_3e1e07423636 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

apps/studio/components/grid/utils/queueOperationUtils.ts lines 233–275

export function reapplyOptimisticUpdates({
  queryClient,
  projectRef,
  tableId,
  operations,
}: ReapplyOptimisticUpdatesParams) {
  const tableOperations = operations.filter((op) => op.tableId === tableId)
  if (tableOperations.length === 0) return

  const queryKey = tableRowKeys.tableRows(projectRef, { table: { id: tableId } })
  queryClient.setQueriesData<TableRowsData>({ queryKey }, (old) => {
    if (!old) return old

    let rows = [...old.rows]
    for (const operation of tableOperations) {
      switch (operation.type) {
        case QueuedOperationType.EDIT_CELL_CONTENT: {
          const { rowIdentifiers, columnName, newValue } = operation.payload
          rows = applyCellEdit(rows, columnName, rowIdentifiers, newValue)
          break
        }
        case QueuedOperationType.ADD_ROW: {
          const { tempId, rowData } = operation.payload
          // Derive idx from tempId (tempId is stringified negative timestamp)
          const idx = Number(tempId)
          rows = applyRowAdd(rows, tempId, idx, rowData)
          break
        }
        case QueuedOperationType.DELETE_ROW: {
          const { rowIdentifiers } = operation.payload
          rows = markRowAsDeleted(rows, rowIdentifiers)
          break
        }
        default: {
          // Need to explicitly handle other operations
          throw new Error(`Unknown operation type: ${(operation as never)['type']}`)
        }
      }
    }

    return { ...old, rows }
  })
}

Subdomains

Called By

Frequently Asked Questions

What does reapplyOptimisticUpdates() do?
reapplyOptimisticUpdates() is a function in the supabase codebase.
What does reapplyOptimisticUpdates() call?
reapplyOptimisticUpdates() calls 3 function(s): applyCellEdit, applyRowAdd, markRowAsDeleted.
What calls reapplyOptimisticUpdates()?
reapplyOptimisticUpdates() is called by 1 function(s): SupabaseGrid.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free