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(form): DrawerForm ssr 错误 : window is not defined #8244

Merged
merged 2 commits into from
Mar 27, 2024
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
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();
});
Loading