From b3bd49d6617e8dd84329db161e2902ad1cbfd5ed Mon Sep 17 00:00:00 2001 From: colder Date: Mon, 15 Dec 2025 22:13:26 +0800 Subject: [PATCH 1/3] fix: prevent error when nativeElement is not available --- src/Dialog/Content/index.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Dialog/Content/index.tsx b/src/Dialog/Content/index.tsx index 665de5bf..1eab3d02 100644 --- a/src/Dialog/Content/index.tsx +++ b/src/Dialog/Content/index.tsx @@ -52,6 +52,8 @@ const Content = React.forwardRef((props, ref) => { } function onPrepare() { + if (!dialogRef.current?.nativeElement) return; + const elementOffset = offset(dialogRef.current.nativeElement); setTransformOrigin( From 1ef532ee3b549e417db21e5a6c08d7bac21879e0 Mon Sep 17 00:00:00 2001 From: Yanlin Jiang Date: Mon, 15 Dec 2025 22:52:07 +0800 Subject: [PATCH 2/3] Update src/Dialog/Content/index.tsx Co-authored-by: afc163 --- src/Dialog/Content/index.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Dialog/Content/index.tsx b/src/Dialog/Content/index.tsx index 1eab3d02..f3313d53 100644 --- a/src/Dialog/Content/index.tsx +++ b/src/Dialog/Content/index.tsx @@ -52,7 +52,9 @@ const Content = React.forwardRef((props, ref) => { } function onPrepare() { - if (!dialogRef.current?.nativeElement) return; + if (!dialogRef.current?.nativeElement) { + return; + } const elementOffset = offset(dialogRef.current.nativeElement); From 3dad7dc13e30ef6e0f5f4d4c8dea20afb8758bd1 Mon Sep 17 00:00:00 2001 From: colder Date: Mon, 15 Dec 2025 23:13:40 +0800 Subject: [PATCH 3/3] test: add check to prevent error when nativeElement is not available --- tests/index.spec.tsx | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/index.spec.tsx b/tests/index.spec.tsx index a00c5c4a..9ab2d51b 100644 --- a/tests/index.spec.tsx +++ b/tests/index.spec.tsx @@ -278,6 +278,18 @@ describe('dialog', () => { document.querySelector('.rc-dialog').style['transform-origin'], ).toBeTruthy(); }); + + it('should not throw error when nativeElement is not available', () => { + expect(() => { + global.onAppearPrepare?.(); + }).not.toThrow(); + + render(); + + expect(() => { + global.onAppearPrepare?.(); + }).not.toThrow(); + }); }); it('can get dom element before dialog first show when forceRender is set true ', () => {