-
Notifications
You must be signed in to change notification settings - Fork 41
fix(react): memoize event listener #1142
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
Conversation
Claude finished @jog1t's task —— View job PR Review: fix(react): memoize event listenerTodo List
SummaryThis PR improves performance by memoizing event listener handlers in the React integration and adds a type alias to reduce code duplication in the framework base. Review Feedback✅ Code Quality & Best PracticesFramework Base (
React Integration (
✅ Performance ConsiderationsExcellent performance improvements:
Dependency array optimization:
|
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
@rivetkit/actor
@rivetkit/core
@rivetkit/db
rivetkit
@rivetkit/cloudflare-workers
@rivetkit/redis
@rivetkit/framework-base
@rivetkit/react
commit: |
Fixes KIT-142
TL;DR
Fixed event handler reference issues in React framework and improved type definitions for actor state.
What changed?
ActorsStateDerived
type to improve type safety and reduce code duplicationuseEvent
hook where handler references weren't being properly maintained between rendersuseRef
to store the latest handler functionactorState.hash
for proper cleanupHow to test?
useEvent
hook with a handler that depends on props or stateWhy make this change?
The previous implementation of
useEvent
had a closure issue where the handler function would capture variables from the render it was defined in, not updating when those variables changed in subsequent renders. This could lead to stale data being used in event handlers.Additionally, the type improvements make the codebase more maintainable by centralizing the actor state derived type definition and removing redundant code.