Skip to content

Commit e94a96d

Browse files
authored
Merge pull request #922 from buildo/ssr-fixes
Update to React 18.3.1 and fix two React warnings in Table
2 parents dc7e752 + 72730e9 commit e94a96d

File tree

3 files changed

+670
-729
lines changed

3 files changed

+670
-729
lines changed

packages/bento-design-system/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,8 @@
190190
"playroom": "0.32.1",
191191
"postcss": "8.4.47",
192192
"prettier": "2.8.8",
193-
"react": "18.2.0",
194-
"react-dom": "18.2.0",
193+
"react": "18.3.1",
194+
"react-dom": "18.3.1",
195195
"storybook": "8.0.8",
196196
"style-loader": "3.3.4",
197197
"ts-loader": "9.4.4",

packages/bento-design-system/src/Table/Table.tsx

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ import {
5151
GridWidth,
5252
Row as RowType,
5353
} from "./types";
54-
import { useLayoutEffect, useMemo, useState, CSSProperties, useEffect, useRef } from "react";
54+
import { useMemo, useState, CSSProperties, useEffect, useRef } from "react";
5555
import { match, __ } from "ts-pattern";
5656
import { useBentoConfig } from "../BentoConfigContext";
5757
import { assignInlineVars } from "@vanilla-extract/dynamic";
@@ -233,12 +233,12 @@ export function Table<
233233
.map((c) => c.id ?? c.accessor)
234234
.indexOf(stickyLeftColumnsIds[stickyLeftColumnsIds.length - 1]);
235235

236-
// Keep a style object for each sticky column, which will be updated by the useLayoutEffect below
236+
// Keep a style object for each sticky column, which will be updated by the useEffect below
237237
const [stickyLeftColumnStyle, setStickyLeftColumnStyle] = useState(
238238
{} as Record<string, CSSProperties>
239239
);
240240

241-
// Keep a state for the height of the first row of headers, which will be updated by the useLayoutEffect below
241+
// Keep a state for the height of the first row of headers, which will be updated by the useEffect below
242242
const [stickyHeaderHeight, setStickyHeaderHeight] = useState(0);
243243

244244
const tableContainerRef = useRef<HTMLDivElement>(null);
@@ -249,7 +249,7 @@ export function Table<
249249
/** Get the width of each sticky column (using the header width as reference) and use it to set the `left` of each sticky column.
250250
* Each sticky column must have as `left` the total width of the previous sticky columns.
251251
*/
252-
useLayoutEffect(() => {
252+
useEffect(() => {
253253
// Make this computation only if we have any data, because headers are not rendered when there are no rows
254254
// and we need them to get the column width.
255255
if (data.length > 0) {
@@ -375,20 +375,24 @@ export function Table<
375375
rowIndex: number,
376376
interactiveRow: boolean
377377
) {
378-
return cells.map((cell, index) => (
379-
<CellContainer
380-
{...cell.getCellProps()}
381-
index={rowIndex}
382-
lastLeftSticky={index === lastStickyColumnIndex}
383-
style={stickyLeftColumnStyle[cell.column.id]}
384-
first={index === 0}
385-
last={(index + 1) % flatColumns.length === 0}
386-
interactiveRow={interactiveRow}
387-
withDividers={withDividers}
388-
>
389-
{cell.render("Cell")}
390-
</CellContainer>
391-
));
378+
return cells.map((cell, index) => {
379+
const { key, ...cellProps } = cell.getCellProps();
380+
return (
381+
<CellContainer
382+
key={key}
383+
{...cellProps}
384+
index={rowIndex}
385+
lastLeftSticky={index === lastStickyColumnIndex}
386+
style={stickyLeftColumnStyle[cell.column.id]}
387+
first={index === 0}
388+
last={(index + 1) % flatColumns.length === 0}
389+
interactiveRow={interactiveRow}
390+
withDividers={withDividers}
391+
>
392+
{cell.render("Cell")}
393+
</CellContainer>
394+
);
395+
});
392396
}
393397

394398
const rowsToRender = virtualizeRows
@@ -581,6 +585,7 @@ function ColumnHeader<D extends Record<string, unknown>>({
581585
) : null;
582586

583587
const hasHeaderContent = column.Header || hint || sortIcon;
588+
const { key: _key, ...headerProps } = column.getHeaderProps(column.getSortByToggleProps());
584589

585590
return (
586591
<Box
@@ -598,7 +603,7 @@ function ColumnHeader<D extends Record<string, unknown>>({
598603
className={[columnHeader({ withDividers, first, lastLeftSticky })]}
599604
background={config.headerBackgroundColor}
600605
color={config.headerForegroundColor}
601-
{...column.getHeaderProps(column.getSortByToggleProps())}
606+
{...headerProps}
602607
textAlign={column.align}
603608
{...config.padding.header}
604609
>

0 commit comments

Comments
 (0)