fix(react-form): restore optional selector in re-exported useStore#2083
fix(react-form): restore optional selector in re-exported useStore#2083mixelburg wants to merge 2 commits intoTanStack:mainfrom
Conversation
Prior to @tanstack/react-store 0.9.1, useStore could be called with just a store reference and no selector, which returned the full atom snapshot: const formState = useStore(form.store) The 0.9.1 update made the selector argument required in TypeScript types, causing a build error in existing code using the single-argument form. Instead of re-exporting useStore directly, add a thin overload wrapper in packages/react-form/src/useStore.ts that makes the selector optional and preserves backward-compatible types while delegating to the underlying @tanstack/react-store implementation. Fixes TanStack#2074
|
📝 WalkthroughWalkthroughA local Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Apart from the TypeScript error, does it cause errors at runtime when omitted? |
|
View your CI Pipeline Execution ↗ for commit 68b42a6
☁️ Nx Cloud last updated this comment at |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/react-form/src/useStore.ts (1)
1-2: Three internal files importuseStoredirectly from@tanstack/react-storeinstead of using the local wrapper.The files
useForm.tsx,useField.tsx, anduseFieldGroup.tsxall importuseStoredirectly from@tanstack/react-storerather than from the local./useStoremodule. While all current usages include a selector argument and work correctly, using the local wrapper would ensure consistency across the package and provide better future-proofing against potential selector-less calls. Consider updating these imports to use the local module.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/react-form/src/useStore.ts` around lines 1 - 2, Replace direct imports of useStore from '@tanstack/react-store' in the internal modules that currently consume it (the useForm.tsx, useField.tsx, and useFieldGroup.tsx modules) with the local wrapper export from ./useStore; specifically, update any import statements that reference useStore to import from './useStore' instead of '@tanstack/react-store' so calls to useStore (and any related type imports like AnyAtom if still needed) consistently go through the local wrapper.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@packages/react-form/src/useStore.ts`:
- Around line 1-2: Replace direct imports of useStore from
'@tanstack/react-store' in the internal modules that currently consume it (the
useForm.tsx, useField.tsx, and useFieldGroup.tsx modules) with the local wrapper
export from ./useStore; specifically, update any import statements that
reference useStore to import from './useStore' instead of
'@tanstack/react-store' so calls to useStore (and any related type imports like
AnyAtom if still needed) consistently go through the local wrapper.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 3f4c6ae3-31a9-4c6e-8865-f03113ae77ee
📒 Files selected for processing (1)
packages/react-form/src/useStore.ts
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2083 +/- ##
===========================================
- Coverage 90.35% 57.20% -33.16%
===========================================
Files 38 19 -19
Lines 1752 250 -1502
Branches 444 48 -396
===========================================
- Hits 1583 143 -1440
+ Misses 149 92 -57
+ Partials 20 15 -5 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Summary
Fixes #2074
Problem
Prior to
@tanstack/react-store@0.9.1,useStorecould be called with just a store reference:The
0.9.1update toreact-storemade theselectorargument required in its TypeScript types. Because@tanstack/react-formre-exporteduseStoredirectly:…any project that had previously used the single-argument form now sees a TypeScript build error:
Fix
Instead of re-exporting
useStoreverbatim, this PR adds a thin overload wrapper inpackages/react-form/src/useStore.tsthat:@tanstack/react-storeimplementationAt runtime the identity function
(s) => sis used as the default selector, which matches what the underlying implementation would have done before.Summary by CodeRabbit