Skip to content

Remove memo and use react-compiler #3780

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
9 changes: 2 additions & 7 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import vitest from '@vitest/eslint-plugin';
import { defineConfig, globalIgnores } from 'eslint/config';
import jestDom from 'eslint-plugin-jest-dom';
import react from 'eslint-plugin-react';
import reactCompiler from 'eslint-plugin-react-compiler';
import reactHooks from 'eslint-plugin-react-hooks';
import reactHooksExtra from 'eslint-plugin-react-hooks-extra';
import sonarjs from 'eslint-plugin-sonarjs';
Expand All @@ -26,7 +25,6 @@ export default defineConfig([

plugins: {
react,
'react-compiler': reactCompiler,
'react-hooks': reactHooks,
'react-hooks-extra': reactHooksExtra,
sonarjs,
Expand Down Expand Up @@ -381,14 +379,11 @@ export default defineConfig([
'react/style-prop-object': 0,
'react/void-dom-elements-no-children': 1,

// React Compiler
// https://react.dev/learn/react-compiler#installing-eslint-plugin-react-compiler
'react-compiler/react-compiler': 1,

// React Hooks
// https://www.npmjs.com/package/eslint-plugin-react-hooks
'react-hooks/rules-of-hooks': 1,
'react-hooks/exhaustive-deps': 1,
'react-hooks/react-compiler': 1,
'react-hooks/rules-of-hooks': 1,

// React Hooks Extra
// https://eslint-react.xyz/
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@
"@vitest/eslint-plugin": "^1.1.44",
"@wyw-in-js/rollup": "^0.6.0",
"@wyw-in-js/vite": "^0.6.0",
"babel-plugin-react-compiler": "^19.1.0-rc.1",
"browserslist": "^4.24.5",
"eslint": "^9.26.0",
"eslint-plugin-jest-dom": "^5.5.0",
"eslint-plugin-react": "^7.37.4",
"eslint-plugin-react-compiler": "^19.1.0-rc.1",
"eslint-plugin-react-hooks": "^5.2.0",
"eslint-plugin-react-hooks": "^6.0.0-rc.1",
"eslint-plugin-react-hooks-extra": "^1.49.0",
"eslint-plugin-sonarjs": "^3.0.2",
"eslint-plugin-testing-library": "^7.1.1",
Expand Down
6 changes: 6 additions & 0 deletions rolldown.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { isAbsolute } from 'node:path';
import wyw from '@wyw-in-js/rollup';
import pkg from './package.json' with { type: 'json' };
import react from '@vitejs/plugin-react';
import { defineConfig } from 'rolldown';

export default defineConfig({
Expand All @@ -15,6 +16,11 @@ export default defineConfig({
platform: 'browser',
external: (id) => !id.startsWith('.') && !isAbsolute(id),
plugins: [
react({
babel: {
plugins: [['babel-plugin-react-compiler', { target: '19' }]]
}
}),
// @ts-expect-error
wyw({
preprocessor: 'none',
Expand Down
8 changes: 3 additions & 5 deletions src/Cell.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { memo, type MouseEvent } from 'react';
import type { MouseEvent } from 'react';
import { css } from '@linaria/core';

import { useRovingTabIndex } from './hooks';
Expand Down Expand Up @@ -126,10 +126,8 @@ function Cell<R, SR>({
);
}

const CellComponent = memo(Cell) as <R, SR>(props: CellRendererProps<R, SR>) => React.JSX.Element;

export default CellComponent;
export default Cell;

export function defaultRenderCell<R, SR>(key: React.Key, props: CellRendererProps<R, SR>) {
return <CellComponent key={key} {...props} />;
return <Cell key={key} {...props} />;
}
6 changes: 1 addition & 5 deletions src/GroupCell.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { memo } from 'react';

import { useRovingTabIndex } from './hooks';
import { getCellClassname, getCellStyle } from './utils';
import type { CalculatedColumn, GroupRow } from './types';
Expand All @@ -17,7 +15,7 @@ interface GroupCellProps<R, SR> {
isGroupByColumn: boolean;
}

function GroupCell<R, SR>({
export default function GroupCell<R, SR>({
id,
groupKey,
childRows,
Expand Down Expand Up @@ -70,5 +68,3 @@ function GroupCell<R, SR>({
</div>
);
}

export default memo(GroupCell) as <R, SR>(props: GroupCellProps<R, SR>) => React.JSX.Element;
8 changes: 2 additions & 6 deletions src/GroupRow.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { memo, useMemo } from 'react';
import { useMemo } from 'react';
import { css } from '@linaria/core';
import clsx from 'clsx';

Expand Down Expand Up @@ -31,7 +31,7 @@ interface GroupRowRendererProps<R, SR> extends BaseRenderRowProps<R, SR> {
toggleGroup: (expandedGroupId: unknown) => void;
}

function GroupedRow<R, SR>({
export default function GroupedRow<R, SR>({
className,
row,
rowIdx,
Expand Down Expand Up @@ -95,7 +95,3 @@ function GroupedRow<R, SR>({
</RowSelectionContext>
);
}

export default memo(GroupedRow) as <R, SR>(
props: GroupRowRendererProps<R, SR>
) => React.JSX.Element;
8 changes: 1 addition & 7 deletions src/GroupedColumnHeaderRow.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { memo } from 'react';

import type { CalculatedColumn, CalculatedColumnParent, Position } from './types';
import GroupedColumnHeaderCell from './GroupedColumnHeaderCell';
import { headerRowClassname } from './HeaderRow';
Expand All @@ -12,7 +10,7 @@ export interface GroupedColumnHeaderRowProps<R, SR> {
selectedCellIdx: number | undefined;
}

function GroupedColumnHeaderRow<R, SR>({
export default function GroupedColumnHeaderRow<R, SR>({
rowIdx,
level,
columns,
Expand Down Expand Up @@ -57,7 +55,3 @@ function GroupedColumnHeaderRow<R, SR>({
</div>
);
}

export default memo(GroupedColumnHeaderRow) as <R, SR>(
props: GroupedColumnHeaderRowProps<R, SR>
) => React.JSX.Element;
8 changes: 2 additions & 6 deletions src/HeaderRow.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { memo, useId } from 'react';
import { useId } from 'react';
import { css } from '@linaria/core';
import clsx from 'clsx';

Expand Down Expand Up @@ -46,7 +46,7 @@ const headerRow = css`

export const headerRowClassname = `rdg-header-row ${headerRow}`;

function HeaderRow<R, SR, K extends React.Key>({
export default function HeaderRow<R, SR, K extends React.Key>({
headerRowClass,
rowIdx,
columns,
Expand Down Expand Up @@ -105,7 +105,3 @@ function HeaderRow<R, SR, K extends React.Key>({
</div>
);
}

export default memo(HeaderRow) as <R, SR, K extends React.Key>(
props: HeaderRowProps<R, SR, K>
) => React.JSX.Element;
8 changes: 3 additions & 5 deletions src/Row.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { memo, useMemo } from 'react';
import { useMemo } from 'react';
import clsx from 'clsx';

import { RowSelectionContext, useLatestFunc, type RowSelectionContextValue } from './hooks';
Expand Down Expand Up @@ -101,10 +101,8 @@ function Row<R, SR>({
);
}

const RowComponent = memo(Row) as <R, SR>(props: RenderRowProps<R, SR>) => React.JSX.Element;

export default RowComponent;
export default Row;

export function defaultRenderRow<R, SR>(key: React.Key, props: RenderRowProps<R, SR>) {
return <RowComponent key={key} {...props} />;
return <Row key={key} {...props} />;
}
5 changes: 1 addition & 4 deletions src/SummaryCell.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { memo } from 'react';
import { css } from '@linaria/core';

import { useRovingTabIndex } from './hooks';
Expand All @@ -21,7 +20,7 @@ interface SummaryCellProps<R, SR> extends SharedCellRendererProps<R, SR> {
row: SR;
}

function SummaryCell<R, SR>({
export default function SummaryCell<R, SR>({
column,
colSpan,
row,
Expand Down Expand Up @@ -57,5 +56,3 @@ function SummaryCell<R, SR>({
</div>
);
}

export default memo(SummaryCell) as <R, SR>(props: SummaryCellProps<R, SR>) => React.JSX.Element;
5 changes: 1 addition & 4 deletions src/SummaryRow.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { memo } from 'react';
import { css } from '@linaria/core';
import clsx from 'clsx';

Expand Down Expand Up @@ -50,7 +49,7 @@ const topSummaryRow = css`

const summaryRowClassname = `rdg-summary-row ${summaryRow}`;

function SummaryRow<R, SR>({
export default function SummaryRow<R, SR>({
rowIdx,
gridRowStart,
row,
Expand Down Expand Up @@ -112,5 +111,3 @@ function SummaryRow<R, SR>({
</div>
);
}

export default memo(SummaryRow) as <R, SR>(props: SummaryRowProps<R, SR>) => React.JSX.Element;
2 changes: 1 addition & 1 deletion src/hooks/useViewportColumns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export function useViewportColumns<R, SR>({

const updateStartIdx = (colIdx: number, colSpan: number | undefined) => {
if (colSpan !== undefined && colIdx + colSpan > colOverscanStartIdx) {
// eslint-disable-next-line react-compiler/react-compiler
// eslint-disable-next-line react-hooks/react-compiler
startIdx = colIdx;
return true;
}
Expand Down
5 changes: 4 additions & 1 deletion vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ export default defineConfig(({ command }) => ({
autoCodeSplitting: true
}),
react({
exclude: ['./.cache/**/*']
exclude: ['./.cache/**/*'],
babel: {
plugins: [['babel-plugin-react-compiler', { target: '19' }]]
}
}),
wyw({
exclude: ['./.cache/**/*'],
Expand Down