Skip to content

TypeError when ownerDocument.defaultView is null in offset() during onEnterPrepare #566

Description

@jeasonnow

复现场景

iOS Safari / App WebView
Modal 打开触发 onAppearPrepare
doc.defaultView || doc.parentWindow 为 null
访问 pageXOffset 崩溃

猜测修复方式

function getScroll(w?: Window | null, top?: boolean): number {
if (!w) return 0;
// ...
}

dialog/src/util.ts

Lines 11 to 22 in 3ebf65c

function getScroll(w: Window, top?: boolean): number {
let ret = w[`page${top ? 'Y' : 'X'}Offset`];
const method = `scroll${top ? 'Top' : 'Left'}`;
if (typeof ret !== 'number') {
const d = w.document;
ret = d.documentElement[method];
if (typeof ret !== 'number') {
ret = d.body[method];
}
}
return ret;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions