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: react-native don't support global and Document #115

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion packages/page-spy-base/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export function isHeaders(value: unknown): value is Headers {
}

export function isDocument(value: unknown): value is Document {
return value instanceof Document;
return typeof globalThis.Document !== 'undefined' && value instanceof globalThis.Document;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

理论上这个函数不应该被 rn 打包进来,这个bug 会另外修掉。
不过这里 typeof 一下也没问题

}

export function isURL(value: unknown): value is URL {
Expand Down
4 changes: 2 additions & 2 deletions packages/page-spy-react-native/src/plugins/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ export default class ErrorPlugin implements PageSpyPlugin {
return;
}
// @ts-ignore
this.originPromise = global.Promise;
global.Promise = LocalPromise;
this.originPromise = globalThis.Promise;
globalThis.Promise = LocalPromise;
RejectTracking.enable({
allRejections: true,
onUnhandled: (id: any, error: any) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/page-spy-react-native/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ export const getGlobal = () => {
foundGlobal = globalThis;
} else if (typeof window !== 'undefined') {
foundGlobal = window;
} else if (typeof global === 'object' && Object.keys(global).length > 1) {
foundGlobal = global;
} else if (typeof globalThis === 'object' && Object.keys(globalThis).length > 1) {
foundGlobal = globalThis;
}
if (customGlobal) {
Object.assign(foundGlobal, customGlobal);
Expand Down