diff --git a/apps/desktop/src/components/grid/DataGrid.vue b/apps/desktop/src/components/grid/DataGrid.vue index 4bb52f469f..5733f1c5ca 100644 --- a/apps/desktop/src/components/grid/DataGrid.vue +++ b/apps/desktop/src/components/grid/DataGrid.vue @@ -364,14 +364,14 @@ const DataGridInsertRowsDialog = defineAsyncComponent(() => import("@/components const ExportProgressDialog = defineAsyncComponent(() => import("@/components/export/ExportProgressDialog.vue")); const FORMATTED_JSON_EDIT_WARNING_COUNT_STORAGE_KEY = "dbx-cell-detail-formatted-json-edit-warning-count"; const FORMATTED_JSON_EDIT_WARNING_MAX_COUNT = 3; -let largeValueRuntime: ReturnType; +let largeValueRuntime: ReturnType | undefined; function scheduleVisibleLargeValuePreviewHydration(delay = 150) { - largeValueRuntime.scheduleVisibleLargeValuePreviewHydration(delay); + largeValueRuntime?.scheduleVisibleLargeValuePreviewHydration(delay); } async function hydrateLargeValueCell(rowId: number, columnIndex: number): Promise { - return largeValueRuntime.hydrateLargeValueCell(rowId, columnIndex); + return largeValueRuntime?.hydrateLargeValueCell(rowId, columnIndex) ?? false; } const { t } = useI18n(); @@ -3503,7 +3503,7 @@ const editor = useDataGridEditor({ cacheKey: computed(() => props.pendingStateKey ?? props.cacheKey), onResultPayloadMutated: () => queryStore.invalidateResultEstimateForPayload(props.result), refreshSavedRows, - onCellValueChanged: (rowId, columnIndex) => largeValueRuntime.invalidateVisibleLargeValuePreviewCell(rowId, columnIndex), + onCellValueChanged: (rowId, columnIndex) => largeValueRuntime?.invalidateVisibleLargeValuePreviewCell(rowId, columnIndex), prepareFullReload, emit, }); diff --git a/apps/desktop/src/components/grid/__tests__/DataGridInitializationOrder.spec.ts b/apps/desktop/src/components/grid/__tests__/DataGridInitializationOrder.spec.ts index 0a0d701154..3cde354a5b 100644 --- a/apps/desktop/src/components/grid/__tests__/DataGridInitializationOrder.spec.ts +++ b/apps/desktop/src/components/grid/__tests__/DataGridInitializationOrder.spec.ts @@ -21,4 +21,10 @@ describe("DataGrid setup initialization order", () => { expect(filterPreviewDeclaration).toBeGreaterThan(canUseWhereSearchDeclaration); expect(filterPreviewWatcher).toBeGreaterThan(filterPreviewDeclaration); }); + + it("does not expose an uninitialized large-value runtime to startup callbacks", () => { + expect(dataGridSource).toContain("let largeValueRuntime: ReturnType | undefined;"); + expect(dataGridSource).toContain("largeValueRuntime?.scheduleVisibleLargeValuePreviewHydration(delay)"); + expect(dataGridSource).toContain("largeValueRuntime?.hydrateLargeValueCell(rowId, columnIndex) ?? false"); + }); }); diff --git a/apps/desktop/src/composables/useDataGridColumnResize.ts b/apps/desktop/src/composables/useDataGridColumnResize.ts index 9a153a6be2..295acbc98a 100644 --- a/apps/desktop/src/composables/useDataGridColumnResize.ts +++ b/apps/desktop/src/composables/useDataGridColumnResize.ts @@ -86,7 +86,7 @@ export function useDataGridColumnResize(options: UseDataGridColumnResizeOptions) }); } - const neededColumnWidths = computed(() => columns.value.map((_, colIdx) => neededColumnWidth(colIdx))); + const neededColumnWidths = computed(() => (columns.value ?? []).map((_, colIdx) => neededColumnWidth(colIdx))); const neededColumnWidthSignature = computed(() => neededColumnWidths.value.join("|")); /** Grow-only: late pages with larger keys must not stay stuck at a short-header / early-page width. */ @@ -123,9 +123,10 @@ export function useDataGridColumnResize(options: UseDataGridColumnResizeOptions) const nextColumnIndexes = [...columnIndexes.value]; const cachedState = !force && previousColumnIndexes.length === 0 ? loadDataGridColumnWidthState(columnWidthStateIdentity(), nextColumnIndexes) : undefined; if (cachedState) userSizedColumnIndexes = new Set(cachedState.userSizedColumnIndexes); - const currentNeededWidths = neededColumnWidths.value; - if (force || columnWidths.value.length !== columns.value.length || previousColumnIndexes.join("\0") !== nextColumnIndexes.join("\0")) { - columnWidths.value = columns.value.map((_, colIdx) => { + const currentNeededWidths = neededColumnWidths.value ?? []; + const columnCount = columns.value?.length ?? 0; + if (force || columnWidths.value.length !== columnCount || previousColumnIndexes.join("\0") !== nextColumnIndexes.join("\0")) { + columnWidths.value = (columns.value ?? []).map((_, colIdx) => { if (!force) { const existingWidth = previousWidthsByColumnIndex.get(nextColumnIndexes[colIdx]); if (existingWidth !== undefined) return existingWidth;