Github Spark Bug: useKV hook throws TypeError on undefined prevDeps during component lifecycle #175542
Replies: 1 comment
-
|
💬 Your Product Feedback Has Been Submitted 🎉 Thank you for taking the time to share your insights with us! Your feedback is invaluable as we build a better GitHub experience for all our users. Here's what you can expect moving forward ⏩
Where to look to see what's shipping 👀
What you can do in the meantime 💻
As a member of the GitHub community, your participation is essential. While we can't promise that every suggestion will be implemented, we want to emphasize that your feedback is instrumental in guiding our decisions and priorities. Thank you once again for your contribution to making GitHub even better! We're grateful for your ongoing support and collaboration in shaping the future of our platform. ⭐ |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Select Topic Area
Bug
Copilot Feature Area
Copilot in GitHub
Body
Summary
The
useKVhook from the@github/spark/hookspackage can cause a hard crash in a React application. During the component render lifecycle, it attempts to access thelengthproperty of a variable namedprevDeps, which is sometimesundefined. This results in an unhandledTypeError: can't access property "length", prevDeps is undefined.This issue makes the
useKVhook unreliable in certain component lifecycle scenarios (e.g., re-renders or unmounting) and forces a fallback to alternative state management.Steps to Reproduce
@github/spark/hooksinto a standard React 19 + Vite application.useKVhook within a component to manage a piece of state.Error and Stack Trace
The key part of the stack trace points directly to an internal error within the
useKVimplementation.Expected Behavior
The
useKVhook should handle its internal dependency arrays safely and should not crash ifprevDepsisundefinedat any point during the React render cycle. It should be resilient to standard component re-renders.Actual Behavior
The hook throws an unhandled TypeError, crashing the entire React application.
Environment
19.0.06.3.5^0.39.0Workaround Implemented
As a temporary fix, we have wrapped the call to
useKVin atry...catchblock to prevent the application from crashing. If an error is caught, we fall back to using auseLocalStoragehook instead.This workaround ensures the application remains stable, but it highlights a potential robustness issue within the hook itself.
Beta Was this translation helpful? Give feedback.
All reactions