Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions src/DataGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ export function DataGrid<R, SR = unknown, K extends Key = Key>(props: DataGridPr
[columnWidths]
);

const [gridRef, gridWidth, gridHeight, horizontalScrollbarHeight] = useGridDimensions();
const [gridRef, gridWidth, gridHeight] = useGridDimensions();
const {
columns,
colSpanColumns,
Expand Down Expand Up @@ -461,8 +461,6 @@ export function DataGrid<R, SR = unknown, K extends Key = Key>(props: DataGridPr
const maxColIdx = columns.length - 1;
const selectedCellIsWithinSelectionBounds = isCellWithinSelectionBounds(selectedPosition);
const selectedCellIsWithinViewportBounds = isCellWithinViewportBounds(selectedPosition);
const scrollHeight =
headerRowHeight + totalRowHeight + summaryRowsHeight + horizontalScrollbarHeight;

/**
* The identity of the wrapper function is stable so it won't break memoization
Expand Down Expand Up @@ -1189,7 +1187,6 @@ export function DataGrid<R, SR = unknown, K extends Key = Key>(props: DataGridPr
gridTemplateColumns,
gridTemplateRows: templateRows,
'--rdg-header-row-height': `${headerRowHeight}px`,
'--rdg-scroll-height': `${scrollHeight}px`,
...layoutCssVars
}}
dir={direction}
Expand Down
16 changes: 4 additions & 12 deletions src/hooks/useGridDimensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ export function useGridDimensions() {
const gridRef = useRef<HTMLDivElement>(null);
const [inlineSize, setInlineSize] = useState(1);
const [blockSize, setBlockSize] = useState(1);
const [horizontalScrollbarHeight, setHorizontalScrollbarHeight] = useState(0);

useLayoutEffect(() => {
const { ResizeObserver } = window;
Expand All @@ -14,25 +13,18 @@ export function useGridDimensions() {
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
if (ResizeObserver == null) return;

const { clientWidth, clientHeight, offsetWidth, offsetHeight } = gridRef.current!;
const { width, height } = gridRef.current!.getBoundingClientRect();
const initialHorizontalScrollbarHeight = offsetHeight - clientHeight;
const initialWidth = width - offsetWidth + clientWidth;
const initialHeight = height - initialHorizontalScrollbarHeight;
const { clientWidth, clientHeight } = gridRef.current!;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can revisit #3873

Copy link
Collaborator Author

@nstepien nstepien Feb 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I predicted your comment a few days earlier: #3968


setInlineSize(initialWidth);
setBlockSize(initialHeight);
setHorizontalScrollbarHeight(initialHorizontalScrollbarHeight);
setInlineSize(clientWidth);
setBlockSize(clientHeight);

const resizeObserver = new ResizeObserver((entries) => {
const size = entries[0].contentBoxSize[0];
const { clientHeight, offsetHeight } = gridRef.current!;

// we use flushSync here to avoid flashing scrollbars
flushSync(() => {
setInlineSize(size.inlineSize);
setBlockSize(size.blockSize);
setHorizontalScrollbarHeight(offsetHeight - clientHeight);
});
});
resizeObserver.observe(gridRef.current!);
Expand All @@ -42,5 +34,5 @@ export function useGridDimensions() {
};
}, []);

return [gridRef, inlineSize, blockSize, horizontalScrollbarHeight] as const;
return [gridRef, inlineSize, blockSize] as const;
}
21 changes: 10 additions & 11 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { tanstackRouter } from '@tanstack/router-plugin/vite';
import react from '@vitejs/plugin-react';
import { playwright } from '@vitest/browser-playwright';
import { playwright, type PlaywrightProviderOptions } from '@vitest/browser-playwright';
import { ecij } from 'ecij/plugin';
import { defineConfig, type ViteUserConfig } from 'vitest/config';
import type { BrowserCommand, BrowserInstanceOption } from 'vitest/node';
Expand Down Expand Up @@ -43,27 +43,26 @@ const viewport = { width: 1920, height: 1080 } as const;

// vitest modifies the instance objects, so we cannot rely on static objects
function getInstances(): BrowserInstanceOption[] {
const opts: PlaywrightProviderOptions = {
actionTimeout: 2000,
contextOptions: {
viewport
}
};

return [
{
browser: 'chromium',
provider: playwright({
actionTimeout: 1000,
contextOptions: {
viewport
},
...opts,
launchOptions: {
channel: 'chromium'
}
})
},
{
browser: 'firefox',
provider: playwright({
actionTimeout: 1000,
contextOptions: {
viewport
}
}),
provider: playwright(opts),
// TODO: remove when FF tests are stable
fileParallelism: false
}
Expand Down