Skip to content

fix(react-form): restore optional selector in re-exported useStore#2083

Open
mixelburg wants to merge 2 commits intoTanStack:mainfrom
mixelburg:fix/useStore-selector-optional
Open

fix(react-form): restore optional selector in re-exported useStore#2083
mixelburg wants to merge 2 commits intoTanStack:mainfrom
mixelburg:fix/useStore-selector-optional

Conversation

@mixelburg
Copy link

@mixelburg mixelburg commented Mar 15, 2026

Summary

Fixes #2074

Problem

Prior to @tanstack/react-store@0.9.1, useStore could be called with just a store reference:

const formState = useStore(form.store) // ✅ worked before

The 0.9.1 update to react-store made the selector argument required in its TypeScript types. Because @tanstack/react-form re-exported useStore directly:

export { useStore } from '@tanstack/react-store'

…any project that had previously used the single-argument form now sees a TypeScript build error:

error TS2554: Expected 2-3 arguments, but got 1.

Fix

Instead of re-exporting useStore verbatim, this PR adds a thin overload wrapper in packages/react-form/src/useStore.ts that:

  1. No selector – returns the full atom snapshot (restores pre-1.28.4 behaviour)
  2. With selector – passes through to the underlying @tanstack/react-store implementation

At runtime the identity function (s) => s is used as the default selector, which matches what the underlying implementation would have done before.

Summary by CodeRabbit

  • Refactor
    • Improved the useStore hook with stronger typing, overloads for returning full snapshots or selector-derived slices, and preserved comparison behavior for selectors.
  • Chore
    • Switched the public export source of useStore to the package's local implementation (no public API name changes).

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
@changeset-bot
Copy link

changeset-bot bot commented Mar 15, 2026

⚠️ No Changeset found

Latest commit: 51a7555

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai
Copy link

coderabbitai bot commented Mar 15, 2026

📝 Walkthrough

Walkthrough

A local useStore wrapper was added to the react-form package and the public export was redirected from @tanstack/react-store to ./useStore. The wrapper provides TypeScript overloads to support calling useStore with an atom-only signature or with selector/compare parameters.

Changes

Cohort / File(s) Summary
Export Source Migration
packages/react-form/src/index.ts
Replaced re-export export { useStore } from '@tanstack/react-store' with export { useStore } from './useStore'.
Type-Safe Hook Wrapper
packages/react-form/src/useStore.ts
New file: introduces AtomSnapshot<TAtom> type and three useStore overloads (atom-only returns snapshot; atom+selector(+compare) returns selected value). Implementation delegates to upstream _useStore with a default identity selector to preserve prior single-arg behavior.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I hopped in with types, neat and spry,
One-arg or many, I won't cry.
A local wrap, tidy and sure,
Old calls still work — that's my lure. ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: restoring the optional selector parameter in useStore to fix backward compatibility issues.
Description check ✅ Passed The description provides clear context: the problem (selector became required in react-store 0.9.1), the fix (adding overload wrapper), and explains runtime behavior. However, the checklist items are not marked as completed.
Linked Issues check ✅ Passed The PR fully addresses issue #2074 by restoring backward compatibility for single-argument useStore(form.store) calls while maintaining support for selector-based usage.
Out of Scope Changes check ✅ Passed All changes are within scope: the useStore.ts wrapper and index.ts export redirection directly address the backward compatibility requirement from issue #2074.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
📝 Coding Plan
  • Generate coding plan for human review comments

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@LeCarbonator
Copy link
Contributor

Apart from the TypeScript error, does it cause errors at runtime when omitted?

@nx-cloud
Copy link

nx-cloud bot commented Mar 17, 2026

View your CI Pipeline Execution ↗ for commit 68b42a6

Command Status Duration Result
nx affected --targets=test:sherif,test:knip,tes... ✅ Succeeded 1m 7s View ↗
nx run-many --target=build --exclude=examples/** ✅ Succeeded 12s View ↗

☁️ Nx Cloud last updated this comment at 2026-03-18 08:15:28 UTC

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
packages/react-form/src/useStore.ts (1)

1-2: Three internal files import useStore directly from @tanstack/react-store instead of using the local wrapper.

The files useForm.tsx, useField.tsx, and useFieldGroup.tsx all import useStore directly from @tanstack/react-store rather than from the local ./useStore module. 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

📥 Commits

Reviewing files that changed from the base of the PR and between 51a7555 and 68b42a6.

📒 Files selected for processing (1)
  • packages/react-form/src/useStore.ts

@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 18, 2026

More templates

@tanstack/angular-form

npm i https://pkg.pr.new/@tanstack/angular-form@2083

@tanstack/form-core

npm i https://pkg.pr.new/@tanstack/form-core@2083

@tanstack/form-devtools

npm i https://pkg.pr.new/@tanstack/form-devtools@2083

@tanstack/lit-form

npm i https://pkg.pr.new/@tanstack/lit-form@2083

@tanstack/react-form

npm i https://pkg.pr.new/@tanstack/react-form@2083

@tanstack/react-form-devtools

npm i https://pkg.pr.new/@tanstack/react-form-devtools@2083

@tanstack/react-form-nextjs

npm i https://pkg.pr.new/@tanstack/react-form-nextjs@2083

@tanstack/react-form-remix

npm i https://pkg.pr.new/@tanstack/react-form-remix@2083

@tanstack/react-form-start

npm i https://pkg.pr.new/@tanstack/react-form-start@2083

@tanstack/solid-form

npm i https://pkg.pr.new/@tanstack/solid-form@2083

@tanstack/solid-form-devtools

npm i https://pkg.pr.new/@tanstack/solid-form-devtools@2083

@tanstack/svelte-form

npm i https://pkg.pr.new/@tanstack/svelte-form@2083

@tanstack/vue-form

npm i https://pkg.pr.new/@tanstack/vue-form@2083

commit: 68b42a6

@sentry
Copy link

sentry bot commented Mar 18, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 57.20%. Comparing base (6892ed0) to head (68b42a6).
⚠️ Report is 158 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Type error in useStore when upgrading from 1.28.0 to 1.28.4

2 participants