From 573d573f43371de5e69d1e31881f9497adf8ca7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8C=E8=B4=A7=E6=9C=BA=E5=99=A8=E4=BA=BA?= Date: Sun, 24 Sep 2023 21:05:29 +0800 Subject: [PATCH 1/2] fix: run in node --- src/Table.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Table.tsx b/src/Table.tsx index 28f3b86d2..a52901bd0 100644 --- a/src/Table.tsx +++ b/src/Table.tsx @@ -443,7 +443,7 @@ function Table(tableProps: TableProps { let mergedWidth = fullTableRef.current ? fullTableRef.current.offsetWidth : width; - if (useInternalHooks && getContainerWidth) { + if (useInternalHooks && getContainerWidth && fullTableRef.current) { mergedWidth = getContainerWidth(fullTableRef.current, mergedWidth) || mergedWidth; } @@ -669,7 +669,7 @@ function Table(tableProps: TableProps )} - {isSticky && scrollBodyRef.current instanceof Element && ( + {isSticky && scrollBodyRef.current && scrollBodyRef.current instanceof Element && ( Date: Sun, 24 Sep 2023 21:15:33 +0800 Subject: [PATCH 2/2] test: add test case --- tests/Node.spec.jsx | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 tests/Node.spec.jsx diff --git a/tests/Node.spec.jsx b/tests/Node.spec.jsx new file mode 100644 index 000000000..f4d59f2f7 --- /dev/null +++ b/tests/Node.spec.jsx @@ -0,0 +1,23 @@ +import React from 'react'; +import { renderToString } from 'react-dom/server'; +import Table from '../src'; + +describe('Table.Node', () => { + // Remove env variables + window.Element = null; + global.Element = null; + + it('not crash in node', () => { + console.log(Element); + + const html = renderToString( + , + ); + + expect(html).toContain('rc-table'); + }); +});