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(useBattery): fake signal API support in some utilities #3634
Conversation
Hi, |
packages/core/useBattery/index.ts
Outdated
@@ -26,7 +26,7 @@ export function useBattery(options: ConfigurableNavigator = {}) { | |||
const { navigator = defaultNavigator } = options | |||
const events = ['chargingchange', 'chargingtimechange', 'dischargingtimechange', 'levelchange'] | |||
|
|||
const isSupported = useSupported(() => navigator && 'getBattery' in navigator) | |||
const isSupported = useSupported(() => navigator && typeof navigator.getBattery === 'function') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe pass the tests.
const isSupported = useSupported(() => navigator && typeof navigator.getBattery === 'function') | |
const isSupported = useSupported(() => navigator && 'getBattery' in navigator && typeof navigator.getBattery === 'function') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fixed it even though I didn't like it. Can we approach it in ts style instead of js too? I mean it's redundant to check an unimportant condition
const isSupported = useSupported(() => navigator && typeof (navigator as Navigator & {
getBattery?: () => unknown
}).getBattery === 'function')
Before submitting the PR, please make sure you do the following
fixes #123
).Description
when i tried to develop my app and use
useBattery
i soon realized some widgets that protect user privacy likeDuckDuckGo
cause spurious signal to Battery API which causes'getBattery ' in navigator === true
even though it is actuallyundefined
Additional context
This pr may not be necessary if the package targets standard browsers. But the more users the better so I created this pr