Skip to content

Commit 8f2d179

Browse files
authored
Add support for React 19 (adazzle#3545)
* Add support for React 19 * react ci matrix * --allow-unrelated-histories * set up git user * log diff with main * merge website job into test job
1 parent 759a3d8 commit 8f2d179

15 files changed

+38
-49
lines changed

.github/workflows/ci.yml

Lines changed: 18 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,26 @@ on:
1212
jobs:
1313
test:
1414
runs-on: ubuntu-latest
15+
strategy:
16+
matrix:
17+
react: [18, 19]
1518
steps:
1619
- uses: actions/checkout@v4
1720
- uses: actions/setup-node@v4
1821
with:
1922
node-version: '22.x'
2023
check-latest: true
21-
- uses: actions/cache@v4
22-
with:
23-
path: ~/.npm
24-
key: npm-${{ hashFiles('package.json') }}
24+
- name: Set up git user
25+
run: |
26+
git config --global user.email '[email protected]'
27+
git config --global user.name 'GitHub Action'
28+
- name: merge react 19 branch
29+
if: matrix.react == 19
30+
run: |
31+
git fetch origin react19
32+
git merge origin/react19 -X theirs --allow-unrelated-histories
33+
git fetch origin main
34+
git diff origin/main
2535
- name: npm install
2636
run: npm i
2737
- name: Biome
@@ -36,41 +46,18 @@ jobs:
3646
run: |
3747
node --run build
3848
node --run build:types
49+
- name: Build website
50+
run: node --run build:website
3951
- name: Test
4052
run: npm --run test
4153
timeout-minutes: 4
4254
- name: Upload coverage
55+
if: matrix.react == 18
4356
uses: codecov/codecov-action@v4
4457
with:
4558
token: ${{ secrets.CODECOV_TOKEN }}
46-
47-
website:
48-
runs-on: ubuntu-latest
49-
steps:
50-
- uses: actions/checkout@v4
51-
- uses: actions/setup-node@v4
52-
with:
53-
node-version: '22.x'
54-
check-latest: true
55-
- uses: actions/cache@v4
56-
with:
57-
path: ~/.npm
58-
key: npm-${{ hashFiles('package.json') }}
59-
- uses: actions/cache@v4
60-
with:
61-
path: node_modules/.cache
62-
key: build-${{ hashFiles('package.json') }}
63-
- name: Build
64-
run: |
65-
npm i
66-
node --run build:website
67-
- name: Set up git user
68-
if: github.event_name == 'push'
69-
run: |
70-
git config --global user.email '[email protected]'
71-
git config --global user.name 'GitHub Action'
7259
- name: Deploy gh-pages
73-
if: github.ref == 'refs/heads/main'
60+
if: matrix.react == 18 && github.event_name == 'push' && github.ref == 'refs/heads/main'
7461
run: |
7562
git fetch origin gh-pages
7663
git worktree add gh-pages gh-pages

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
"@testing-library/user-event": "^14.5.2",
7575
"@types/lodash-es": "^4.17.7",
7676
"@types/node": "^20.10.3",
77-
"@types/react": "^18.3.0",
77+
"@types/react": "^18.3.3",
7878
"@types/react-dom": "^18.3.0",
7979
"@typescript-eslint/eslint-plugin": "^7.0.1",
8080
"@typescript-eslint/parser": "^7.0.1",
@@ -110,7 +110,7 @@
110110
"vitest": "^2.0.1"
111111
},
112112
"peerDependencies": {
113-
"react": "^18.0",
114-
"react-dom": "^18.0"
113+
"react": "^18.0 || ^19.0",
114+
"react-dom": "^18.0 || ^19.0"
115115
}
116116
}

src/Cell.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,4 +116,4 @@ function Cell<R, SR>({
116116
);
117117
}
118118

119-
export default memo(Cell) as <R, SR>(props: CellRendererProps<R, SR>) => JSX.Element;
119+
export default memo(Cell) as <R, SR>(props: CellRendererProps<R, SR>) => React.JSX.Element;

src/DataGrid.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1225,4 +1225,4 @@ function isSamePosition(p1: Position, p2: Position) {
12251225

12261226
export default forwardRef(DataGrid) as <R, SR = unknown, K extends Key = Key>(
12271227
props: DataGridProps<R, SR, K> & RefAttributes<DataGridHandle>
1228-
) => JSX.Element;
1228+
) => React.JSX.Element;

src/EditCell.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export default function EditCell<R, SR>({
5656
onKeyDown,
5757
navigate
5858
}: EditCellProps<R, SR>) {
59-
const frameRequestRef = useRef<number | undefined>();
59+
const frameRequestRef = useRef<number | undefined>(undefined);
6060
const commitOnOutsideClick = column.editorOptions?.commitOnOutsideClick !== false;
6161

6262
// We need to prevent the `useEffect` from cleaning up between re-renders,

src/GroupCell.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,4 @@ function GroupCell<R, SR>({
6767
);
6868
}
6969

70-
export default memo(GroupCell) as <R, SR>(props: GroupCellProps<R, SR>) => JSX.Element;
70+
export default memo(GroupCell) as <R, SR>(props: GroupCellProps<R, SR>) => React.JSX.Element;

src/GroupRow.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,6 @@ function GroupedRow<R, SR>({
9090
);
9191
}
9292

93-
export default memo(GroupedRow) as <R, SR>(props: GroupRowRendererProps<R, SR>) => JSX.Element;
93+
export default memo(GroupedRow) as <R, SR>(
94+
props: GroupRowRendererProps<R, SR>
95+
) => React.JSX.Element;

src/GroupedColumnHeaderRow.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,4 @@ function GroupedColumnHeaderRow<R, SR>({
6060

6161
export default memo(GroupedColumnHeaderRow) as <R, SR>(
6262
props: GroupedColumnHeaderRowProps<R, SR>
63-
) => JSX.Element;
63+
) => React.JSX.Element;

src/HeaderRow.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,4 @@ function HeaderRow<R, SR, K extends React.Key>({
102102

103103
export default memo(HeaderRow) as <R, SR, K extends React.Key>(
104104
props: HeaderRowProps<R, SR, K>
105-
) => JSX.Element;
105+
) => React.JSX.Element;

src/Row.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ function Row<R, SR>(
104104

105105
const RowComponent = memo(forwardRef(Row)) as <R, SR>(
106106
props: RenderRowProps<R, SR> & RefAttributes<HTMLDivElement>
107-
) => JSX.Element;
107+
) => React.JSX.Element;
108108

109109
export default RowComponent;
110110

src/SummaryCell.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,4 @@ function SummaryCell<R, SR>({
5858
);
5959
}
6060

61-
export default memo(SummaryCell) as <R, SR>(props: SummaryCellProps<R, SR>) => JSX.Element;
61+
export default memo(SummaryCell) as <R, SR>(props: SummaryCellProps<R, SR>) => React.JSX.Element;

src/SummaryRow.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,4 @@ function SummaryRow<R, SR>({
113113
);
114114
}
115115

116-
export default memo(SummaryRow) as <R, SR>(props: SummaryRowProps<R, SR>) => JSX.Element;
116+
export default memo(SummaryRow) as <R, SR>(props: SummaryRowProps<R, SR>) => React.JSX.Element;

src/TreeDataGrid.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,4 +439,4 @@ function isReadonlyArray(arr: unknown): arr is readonly unknown[] {
439439

440440
export default forwardRef(TreeDataGrid) as <R, SR = unknown, K extends Key = Key>(
441441
props: TreeDataGridProps<R, SR, K> & RefAttributes<DataGridHandle>
442-
) => JSX.Element;
442+
) => React.JSX.Element;

src/hooks/useColumnWidths.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export function useColumnWidths<R, SR>(
99
columns: readonly CalculatedColumn<R, SR>[],
1010
viewportColumns: readonly CalculatedColumn<R, SR>[],
1111
templateColumns: readonly string[],
12-
gridRef: React.RefObject<HTMLDivElement>,
12+
gridRef: React.RefObject<HTMLDivElement | null>,
1313
gridWidth: number,
1414
resizedColumnWidths: ReadonlyMap<string, number>,
1515
measuredColumnWidths: ReadonlyMap<string, number>,
@@ -105,8 +105,8 @@ export function useColumnWidths<R, SR>(
105105
} as const;
106106
}
107107

108-
function measureColumnWidth(gridRef: React.RefObject<HTMLDivElement>, key: string) {
108+
function measureColumnWidth(gridRef: React.RefObject<HTMLDivElement | null>, key: string) {
109109
const selector = `[data-measuring-cell-key="${CSS.escape(key)}"]`;
110-
const measuringCell = gridRef.current!.querySelector(selector);
110+
const measuringCell = gridRef.current?.querySelector(selector);
111111
return measuringCell?.getBoundingClientRect().width;
112112
}

website/demos/CommonFeatures.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ function ExportButton({
377377
children
378378
}: {
379379
onExport: () => Promise<unknown>;
380-
children: React.ReactChild;
380+
children: React.ReactNode;
381381
}) {
382382
const [exporting, setExporting] = useState(false);
383383
return (

0 commit comments

Comments
 (0)