Skip to content

Commit

Permalink
fix: 修复 React 18 StrictMode 同时挂载两个表格的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
lijinke666 committed Nov 23, 2023
1 parent 121f24d commit 081eaea
Show file tree
Hide file tree
Showing 4 changed files with 1,033 additions and 925 deletions.
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -167,5 +167,8 @@
"vue-jest": "^5.0.0-alpha.10"
},
"license": "MIT",
"repository": "[email protected]:antvis/S2.git"
"repository": {
"type": "git",
"url": "https://github.com/antvis/S2.git"
}
}
32 changes: 30 additions & 2 deletions packages/s2-react/__tests__/spreadsheet/spread-sheet-spec.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react';
import { waitFor } from '@testing-library/react';
import { SheetComponent, type SheetComponentsProps } from '../../src';
import * as mockDataConfig from '../data/simple-data.json';
import { getContainer, renderComponent } from '../util/helpers';
Expand Down Expand Up @@ -31,7 +32,7 @@ describe('Spread Sheet Tests', () => {
container?.remove();
});

test('should display scroll bar if s2Options.width more than browser window width', () => {
test('should display scroll bar if s2Options.width more than browser window width', async () => {
renderComponent(
<SheetComponent
options={{
Expand All @@ -43,7 +44,9 @@ describe('Spread Sheet Tests', () => {
container,
);

expect(hasScrollBar(container)).toBeTruthy();
await waitFor(() => {
expect(hasScrollBar(container)).toBeTruthy();
});
});

test.skip('should hidden scroll bar if window width more than s2Options.width', () => {
Expand All @@ -53,5 +56,30 @@ describe('Spread Sheet Tests', () => {

expect(hasScrollBar(container)).toBeFalsy();
});

test('should only mount container once in strict mode for React 18', async () => {
// eslint-disable-next-line no-console
console.table(process.env);
const onMounted = jest.fn();

renderComponent(
<React.StrictMode>
<SheetComponent
options={s2Options}
dataCfg={mockDataConfig}
onMounted={onMounted}
/>
,
</React.StrictMode>,
container,
);

await waitFor(() => {
expect(
Array.from(document.querySelectorAll('.antv-s2-container canvas')),
).toHaveLength(1);
expect(onMounted).toHaveBeenCalledTimes(1);
});
});
});
});
Loading

0 comments on commit 081eaea

Please sign in to comment.