-
Notifications
You must be signed in to change notification settings - Fork 795
fix(use-external-store-runtime): use-effects dependency #2610
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
|
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.
Pull Request Overview
This PR fixes a dependency issue in the useExternalStoreRuntime hook by adding the store parameter to the useEffect dependency array. This ensures that runtime.setAdapter is properly re-executed when the store reference changes, preventing potential stale closure issues.
- Added
storeto the useEffect dependency array inuseExternalStoreRuntime
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
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.
1 file reviewed, no comments
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.
No issues found across 1 file
Pull Request ReviewSummaryThis PR fixes a React hooks dependency issue in useExternalStoreRuntime where the useEffect was missing dependencies. Positive Aspects
Issues Identified1. Missing Changeset (Required)This PR modifies @assistant-ui/react which is a published package (v0.11.29). According to CONTRIBUTING.md, every pull request that changes packages must include a changeset. Action Required: Run 'pnpm changeset' to create a changeset file. This should be a patch version bump. 2. Cleanup Function RegressionThe second useEffect change (lines 23-27) removes the cleanup return statement. The original code returned the cleanup function from registerModelContextProvider. The new code does not return anything, which means the cleanup will not run when the component unmounts or dependencies change. Impact: This could lead to memory leaks or stale registrations. Recommendation: Keep the return statement to ensure proper cleanup. Additional ObservationsTest Coverage: No tests were found in the external-store directory. Consider adding tests for store reference changes, proper cleanup when component unmounts, and model context registration lifecycle. Documentation: No API surface changes, so documentation updates are not required. Code Quality AssessmentRating: Good - The main fix is correct and addresses a real bug, but the cleanup function removal needs to be addressed. Security: No security concerns Recommended Actions
VerdictThe core fix for the dependency array is excellent and necessary. However, two issues must be addressed before merging:
Once these are resolved, this will be a solid bug fix! |
This commit ensures that `runtime.setAdapter` is called again if the reference to `store` or `runtime` changes. The return value to the use-effect callback should be a teardown function
|
This commit does not change the behavior of the code. I am unable to reproduce the error you are specifying. Thank you nevertheless for the PR :) |
This commit ensures that
runtime.setAdapteris called again if the reference tostorechanges.Important
Fixes
useEffectdependency inuseExternalStoreRuntimeto updateruntime.setAdapterwhenstorechanges.useEffectdependency inuseExternalStoreRuntimeto includestore, ensuringruntime.setAdapteris called whenstorechanges.This description was created by
for ecd1b10. You can customize this summary. It will automatically update as commits are pushed.