Skip to content

Commit 65f9ce2

Browse files
authored
fix: run in node before not ready (#1029)
* fix: run in node * test: add test case
1 parent 269ef15 commit 65f9ce2

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

src/Table.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ function Table<RecordType extends DefaultRecordType>(tableProps: TableProps<Reco
443443

444444
const onFullTableResize = ({ width }) => {
445445
let mergedWidth = fullTableRef.current ? fullTableRef.current.offsetWidth : width;
446-
if (useInternalHooks && getContainerWidth) {
446+
if (useInternalHooks && getContainerWidth && fullTableRef.current) {
447447
mergedWidth = getContainerWidth(fullTableRef.current, mergedWidth) || mergedWidth;
448448
}
449449

@@ -669,7 +669,7 @@ function Table<RecordType extends DefaultRecordType>(tableProps: TableProps<Reco
669669
</FixedHolder>
670670
)}
671671

672-
{isSticky && scrollBodyRef.current instanceof Element && (
672+
{isSticky && scrollBodyRef.current && scrollBodyRef.current instanceof Element && (
673673
<StickyScrollBar
674674
ref={stickyRef}
675675
offsetScroll={offsetScroll}

tests/Node.spec.jsx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import React from 'react';
2+
import { renderToString } from 'react-dom/server';
3+
import Table from '../src';
4+
5+
describe('Table.Node', () => {
6+
// Remove env variables
7+
window.Element = null;
8+
global.Element = null;
9+
10+
it('not crash in node', () => {
11+
console.log(Element);
12+
13+
const html = renderToString(
14+
<Table
15+
columns={[{ title: 'Name', dataIndex: 'name', key: 'name' }]}
16+
data={[{ key: 'key0', name: 'Lucy' }]}
17+
sticky
18+
/>,
19+
);
20+
21+
expect(html).toContain('rc-table');
22+
});
23+
});

0 commit comments

Comments
 (0)