Skip to content

Commit

Permalink
fix(form): DrawerForm ssr 错误 : window is not defined (#8244)
Browse files Browse the repository at this point in the history
* test(form): add ssr test

* fix(form): DrawerForm ssr 错误 : window is not defined
  • Loading branch information
edram authored Mar 27, 2024
1 parent 6dbbd1f commit 351faec
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/form/src/layouts/DrawerForm/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
isBrowser,
omitUndefined,
openVisibleCompatible,
useRefFunction,
Expand Down Expand Up @@ -112,7 +113,7 @@ function DrawerForm<T = Record<string, any>, U = Record<string, any>>({
const resizeInfo: CustomizeResizeType = React.useMemo(() => {
const defaultResize: CustomizeResizeType = {
onResize: () => {},
maxWidth: window.innerWidth * 0.8,
maxWidth: isBrowser() ? window.innerWidth * 0.8 : undefined,
minWidth: 300,
};
if (typeof resize === 'boolean') {
Expand Down
10 changes: 10 additions & 0 deletions tests/form/ssr.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// @vitest-environment node

import ProForm, { DrawerForm, ModalForm } from '@ant-design/pro-form';
import { renderToString } from 'react-dom/server';

test('ssr', () => {
expect(renderToString(<ProForm />)).toBeDefined();
expect(renderToString(<ModalForm />)).toBeDefined();
expect(renderToString(<DrawerForm />)).toBeDefined();
});

0 comments on commit 351faec

Please sign in to comment.