fix: prevent initialFormState from overriding client values during merge#2096
fix: prevent initialFormState from overriding client values during merge#2096Mishra-coder wants to merge 1 commit intoTanStack:mainfrom
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
The
initialFormStateexported by the Next.js and Remix adapters contained avalues: undefinedproperty. During the server-client state merge process (specifically inmutateMergeDeep), this undefined value was being merged into the client's form state, causing existing field values to be reset toundefinedafter initial mount or during route transitions.This fix removes the
valuesproperty from theinitialFormStateobject in both adapters. By omitting the property entirely, the merge logic no longer overwrites existing client values when no server-side values are provided.This approach is safe because:
values: undefinedexplicitly overrides client statevaluespreserves existing client valuesvalues(e.g. after validation) will still correctly override client state as expectedTo maintain type compatibility, a TypeScript cast is used:
as unknown as ServerFormState<any, undefined>This resolves the issue where forms using server actions would have their fields set to
undefinedafter initial render or during client-side navigation.Closes #2089
Summary by CodeRabbit