fix(useRafFn): resolve reactive null fpsLimit not being handled#5284
Conversation
When fpsLimit is passed as a ref(null), the truthiness check evaluates the ref object itself (always truthy) rather than the unwrapped value. This causes 1000 / null = Infinity, so the interval limit is never satisfied and the callback never fires. Unwrap fpsLimit with toValue() before the truthiness check so that reactive null/0/false values correctly resolve to no fps limit. Closes vueuse#5273
|
Thank you for your PR 🙏🏽! Can you briefly explain why we should handle |
Oh, I confirmed this as a bug in #5273. I hadn't noticed the type restriction before.🤦♂️ But if someone turns off const fpsLimit = ref<number>(null)
useRafFn(() => {
}, { fpsLimit }) |
|
You're right that the types only accept As @9romise mentioned, this also surfaces with |
Honestly, I don't think we should allow |
|
That's a fair point. That said, I think the runtime fix itself still stands on its own. It's not really about supporting null, it's about fixing the The fix just moves |
|
From my perspective, the core need here seems to be the ability to control the limit reactively (enable/disable). However, while we treat |
|
change makes sense to me but i agree, i would be explicit. is note that this is just a typescript decision, the underlying code outside of TS will handle null and undefined still |
I'll cast my vote for |
215601c to
059d159
Compare
@vueuse/components
@vueuse/core
@vueuse/electron
@vueuse/firebase
@vueuse/integrations
@vueuse/math
@vueuse/metadata
@vueuse/nuxt
@vueuse/router
@vueuse/rxjs
@vueuse/shared
commit: |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #5284 +/- ##
==========================================
- Coverage 65.46% 65.46% -0.01%
==========================================
Files 344 344
Lines 8039 8040 +1
Branches 2483 2471 -12
==========================================
Hits 5263 5263
- Misses 2257 2258 +1
Partials 519 519 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Fixes #5273
When you pass
fpsLimitas aref(null)(so you can toggle the limit on/off later), the callback never fires.The problem is that the truthiness check is on the ref object itself, which is always truthy — so
toValue()resolves tonulland1000 / nullgivesInfinity. The interval limit is never satisfied and the loop just skips every frame.The fix is simple — unwrap with
toValue()first, then check:Also added a test for this case. All 12 tests passing.