🐛 fix(data-grid): 兼容无 navigator 的服务端渲染

- 通过 globalThis 安全注入浏览器 navigator,避免 Node 20 渲染期抛错
- 补充无 navigator 环境下的 DataGrid 服务端渲染回归测试
- 保持浏览器剪贴板行为不变
This commit is contained in:
Syngnat
2026-07-19 00:22:02 +08:00
parent 7913811549
commit e404fa3ac0
2 changed files with 32 additions and 1 deletions

View File

@@ -149,6 +149,37 @@ const zhObjectDesignLabel = zhCnCatalog['data_grid.secondary.object_design'];
const enUndoCellChangeLabel = enUsCatalog['data_grid.context_menu.undo_cell_change'];
describe('DataGrid layout', () => {
it('renders without navigator in server-side environments', () => {
const navigatorDescriptor = Object.getOwnPropertyDescriptor(globalThis, 'navigator');
Reflect.deleteProperty(globalThis, 'navigator');
try {
expect(() => renderDataGridWithI18n(
<DataGrid
data={[]}
columnNames={[]}
loading={false}
tableName="users"
dbName="main"
connectionId="conn-1"
readOnly
pagination={{
current: 1,
pageSize: 100,
total: 0,
}}
onPageChange={() => {}}
/>,
)).not.toThrow();
} finally {
if (navigatorDescriptor) {
Object.defineProperty(globalThis, 'navigator', navigatorDescriptor);
} else {
Reflect.deleteProperty(globalThis, 'navigator');
}
}
});
it('renders a secondary action strip for view switching and auxiliary actions', () => {
const markup = renderDataGridWithI18n(
<DataGrid

View File

@@ -3407,7 +3407,7 @@ const DataGrid: React.FC<DataGridProps> = ({
isQueryResultExport,
mergedDisplayData,
modal,
navigator,
navigator: globalThis.navigator,
objectType,
pagination,
pickDataGridOutputRows,