You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
PR #153 was intended to make it easier to mock globals that Ky relies on.
But it actually broke my app's mocking...
In fact, in environments that have globalThis (including Node.js), the logic for determining which global object to use is completely broken. It will always choose globalThis no matter what. Anyone using an artificial window or self (e.g. with jsdom), which is necessary in React projects, is no longer able to put things there and have Ky pick up on them. They just get ignored.
This is happening because the return statements were removed from here. Instead, the if statements now "fall through" here until it hits globalThis, which doesn't have the same properties as window in my case, yet Ky chooses to use globalThis anyway, even though the property doesn't exist there.
Another consequence of falling through like this, even if your environment doesn't have globalThis, is that the order of precedence is reversed from what it was previously. Before it would stop at the earliest match found, now it stops at the last match found.
I would prefer to revert this commit and rethink how it works, but a simple temporary fix for the first problem would be to check that the property exists on globalThis before setting the parent to globalThis.
// cc @luxferresum
The text was updated successfully, but these errors were encountered:
PR #153 was intended to make it easier to mock globals that Ky relies on.
But it actually broke my app's mocking...
In fact, in environments that have
globalThis
(including Node.js), the logic for determining which global object to use is completely broken. It will always chooseglobalThis
no matter what. Anyone using an artificialwindow
orself
(e.g. with jsdom), which is necessary in React projects, is no longer able to put things there and have Ky pick up on them. They just get ignored.This is happening because the
return
statements were removed from here. Instead, theif
statements now "fall through" here until it hitsglobalThis
, which doesn't have the same properties aswindow
in my case, yet Ky chooses to useglobalThis
anyway, even though the property doesn't exist there.Another consequence of falling through like this, even if your environment doesn't have
globalThis
, is that the order of precedence is reversed from what it was previously. Before it would stop at the earliest match found, now it stops at the last match found.I would prefer to revert this commit and rethink how it works, but a simple temporary fix for the first problem would be to check that the
property
exists onglobalThis
before setting theparent
toglobalThis
.// cc @luxferresum
The text was updated successfully, but these errors were encountered: