fix(grid): guard DataGrid startup initialization
This commit is contained in:
3 files changed
+15
-8
No files matched your search
@@ -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<typeof useDataGridLargeValues>;
|
||||
let largeValueRuntime: ReturnType<typeof useDataGridLargeValues> | undefined;
|
||||
|
||||
function scheduleVisibleLargeValuePreviewHydration(delay = 150) {
|
||||
largeValueRuntime.scheduleVisibleLargeValuePreviewHydration(delay);
|
||||
largeValueRuntime?.scheduleVisibleLargeValuePreviewHydration(delay);
|
||||
}
|
||||
|
||||
async function hydrateLargeValueCell(rowId: number, columnIndex: number): Promise<boolean> {
|
||||
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,
|
||||
});
|
||||
|
||||
+6
@@ -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<typeof useDataGridLargeValues> | undefined;");
|
||||
expect(dataGridSource).toContain("largeValueRuntime?.scheduleVisibleLargeValuePreviewHydration(delay)");
|
||||
expect(dataGridSource).toContain("largeValueRuntime?.hydrateLargeValueCell(rowId, columnIndex) ?? false");
|
||||
});
|
||||
});
|
||||
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user