From 9fbe571f27a9ff791d29154eadcad0dafb077ed8 Mon Sep 17 00:00:00 2001 From: "santree.g" Date: Wed, 10 Jun 2026 22:57:22 +0800 Subject: [PATCH 1/4] fix: #556 guard against undefined window in getScroll --- src/util.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/util.ts b/src/util.ts index 07ec4199..fee74252 100644 --- a/src/util.ts +++ b/src/util.ts @@ -9,6 +9,7 @@ export function getMotionName(prefixCls: string, transitionName?: string, animat // =============================== Offset =============================== function getScroll(w: Window, top?: boolean): number { + if (!w) return 0; let ret = w[`page${top ? 'Y' : 'X'}Offset`]; const method = `scroll${top ? 'Top' : 'Left'}`; if (typeof ret !== 'number') { From 099a14e3a2b8ab6925263d188201a03c1ce4de41 Mon Sep 17 00:00:00 2001 From: "santree.g" Date: Wed, 10 Jun 2026 23:01:59 +0800 Subject: [PATCH 2/4] fix: #556 fix typescript --- src/util.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util.ts b/src/util.ts index fee74252..d01a3535 100644 --- a/src/util.ts +++ b/src/util.ts @@ -8,7 +8,7 @@ export function getMotionName(prefixCls: string, transitionName?: string, animat } // =============================== Offset =============================== -function getScroll(w: Window, top?: boolean): number { +function getScroll(w: Window | null | undefined, top?: boolean): number { if (!w) return 0; let ret = w[`page${top ? 'Y' : 'X'}Offset`]; const method = `scroll${top ? 'Top' : 'Left'}`; From 4a6bc4d34e48139446f0ada77eb55f4b9da50815 Mon Sep 17 00:00:00 2001 From: "santree.g" Date: Wed, 10 Jun 2026 23:04:10 +0800 Subject: [PATCH 3/4] fix: #556 add tests for undefined window in getScroll Cover offset() when defaultView and parentWindow are missing or null. Co-authored-by: Cursor --- tests/util.spec.tsx | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tests/util.spec.tsx b/tests/util.spec.tsx index d136d099..17a4f762 100644 --- a/tests/util.spec.tsx +++ b/tests/util.spec.tsx @@ -48,6 +48,33 @@ describe('Dialog.Util', () => { top: 1128, }); }); + + it('returns zero offset when defaultView and parentWindow are missing', () => { + const element = { + ownerDocument: {}, + getBoundingClientRect: () => ({ left: 0, top: 0 }), + } as any; + + expect(offset(element)).toEqual({ + left: 0, + top: 0, + }); + }); + + it('returns zero offset when defaultView and parentWindow are null or undefined', () => { + const element = { + ownerDocument: { + defaultView: null, + parentWindow: undefined, + }, + getBoundingClientRect: () => ({ left: 0, top: 0 }), + } as any; + + expect(offset(element)).toEqual({ + left: 0, + top: 0, + }); + }); }); describe('getMotionName', () => { From a8869743727842799a653f98852f55037a602dae Mon Sep 17 00:00:00 2001 From: afc163 Date: Thu, 11 Jun 2026 01:21:52 +0800 Subject: [PATCH 4/4] Update src/util.ts --- src/util.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/util.ts b/src/util.ts index d01a3535..48cf06db 100644 --- a/src/util.ts +++ b/src/util.ts @@ -9,7 +9,9 @@ export function getMotionName(prefixCls: string, transitionName?: string, animat // =============================== Offset =============================== function getScroll(w: Window | null | undefined, top?: boolean): number { - if (!w) return 0; + if (!w) { + return 0; + } let ret = w[`page${top ? 'Y' : 'X'}Offset`]; const method = `scroll${top ? 'Top' : 'Left'}`; if (typeof ret !== 'number') {