Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

fix: 修复 React 18 StrictMode 同时挂载两个表格的问题 #2432

Merged
merged 1 commit into from
Nov 28, 2023
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: 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
Loading