Skip to content

Commit e5625e3

Browse files
cncolderafc163
andauthored
fix: prevent error when nativeElement is not available (#537)
Co-authored-by: afc163 <[email protected]>
1 parent c3bbe74 commit e5625e3

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/Dialog/Content/index.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ const Content = React.forwardRef<ContentRef, ContentProps>((props, ref) => {
5252
}
5353

5454
function onPrepare() {
55+
if (!dialogRef.current?.nativeElement) {
56+
return;
57+
}
58+
5559
const elementOffset = offset(dialogRef.current.nativeElement);
5660

5761
setTransformOrigin(

tests/index.spec.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,18 @@ describe('dialog', () => {
278278
document.querySelector<HTMLElement>('.rc-dialog').style['transform-origin'],
279279
).toBeTruthy();
280280
});
281+
282+
it('should not throw error when nativeElement is not available', () => {
283+
expect(() => {
284+
global.onAppearPrepare?.();
285+
}).not.toThrow();
286+
287+
render(<Dialog visible />);
288+
289+
expect(() => {
290+
global.onAppearPrepare?.();
291+
}).not.toThrow();
292+
});
281293
});
282294

283295
it('can get dom element before dialog first show when forceRender is set true ', () => {

0 commit comments

Comments
 (0)