Skip to content
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

TanStack Store Internals Refactor #1038

Merged
merged 43 commits into from
Dec 29, 2024
Merged

TanStack Store Internals Refactor #1038

merged 43 commits into from
Dec 29, 2024

Conversation

crutchcorn
Copy link
Member

@crutchcorn crutchcorn commented Nov 25, 2024

This PR should be merged with the message

fix: useStore should cause fewer (if any) update depth issues in React

TODOs

Copy link

nx-cloud bot commented Nov 25, 2024

View your CI Pipeline Execution ↗ for commit 1c360a6.

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

☁️ Nx Cloud last updated this comment at 2024-12-29 16:10:48 UTC

@crutchcorn crutchcorn mentioned this pull request Nov 29, 2024
11 tasks
crutchcorn and others added 10 commits November 29, 2024 01:12
# Conflicts:
#	docs/framework/angular/reference/classes/tanstackfield.md
#	docs/framework/react/reference/functions/useform.md
#	docs/framework/react/reference/interfaces/reactformapi.md
#	docs/framework/react/reference/type-aliases/fieldcomponent.md
#	docs/framework/react/reference/type-aliases/reactformextendedapi.md
#	docs/framework/vue/reference/functions/usefield.md
#	docs/framework/vue/reference/functions/useform.md
#	docs/framework/vue/reference/interfaces/vuefieldapi.md
#	docs/framework/vue/reference/interfaces/vueformapi.md
#	docs/framework/vue/reference/type-aliases/fieldcomponent.md
#	docs/framework/vue/reference/type-aliases/usefield.md
#	docs/framework/vue/reference/variables/field.md
#	docs/reference/classes/fieldapi.md
#	docs/reference/classes/formapi.md
#	docs/reference/type-aliases/fieldmeta.md
#	docs/reference/type-aliases/fieldstate.md
#	packages/form-core/src/FieldApi.ts
#	packages/form-core/src/FormApi.ts
#	pnpm-lock.yaml
Copy link

pkg-pr-new bot commented Nov 30, 2024

Open in Stackblitz

More templates

@tanstack/angular-form

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

@tanstack/form-core

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

@tanstack/react-form

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

@tanstack/lit-form

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

@tanstack/solid-form

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

@tanstack/valibot-form-adapter

npm i https://pkg.pr.new/@tanstack/valibot-form-adapter@1038

@tanstack/vue-form

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

@tanstack/yup-form-adapter

npm i https://pkg.pr.new/@tanstack/yup-form-adapter@1038

@tanstack/zod-form-adapter

npm i https://pkg.pr.new/@tanstack/zod-form-adapter@1038

commit: 1c360a6

@crutchcorn
Copy link
Member Author

OK, I figured out what the problem was:

batch sends out prevDepVals in one single update. Meaning that when we end up receiving the new value, it will inevitably be === consistent. By removing all instances in form for batch by doing:

function batch(fn: () => void) {
  return fn()
}

It works as-intended and all tests pass.

This isn't ideal tho, so I'll try to patch it in store instead if possible

crutchcorn and others added 7 commits December 26, 2024 10:39
# Conflicts:
#	docs/reference/classes/fieldapi.md
#	docs/reference/classes/formapi.md
#	docs/reference/type-aliases/fieldmeta.md
#	docs/reference/type-aliases/fieldstate.md
#	docs/reference/type-aliases/formstate.md
#	examples/react/next-server-actions/package.json
#	examples/react/remix/package.json
#	examples/react/tanstack-start/package.json
#	packages/angular-form/package.json
#	packages/form-core/package.json
#	packages/form-core/src/FieldApi.ts
#	packages/form-core/src/FormApi.ts
#	packages/react-form/package.json
#	packages/solid-form/package.json
#	packages/vue-form/package.json
#	pnpm-lock.yaml
@crutchcorn crutchcorn changed the title chore: WIP migration to derived state fix: useStore should cause fewer (if any) update depth issues in React Dec 28, 2024
@crutchcorn crutchcorn changed the title fix: useStore should cause fewer (if any) update depth issues in React TanStack Store Internals Refactor Dec 28, 2024
Copy link
Member

@Balastrong Balastrong left a comment

Choose a reason for hiding this comment

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

I see there are also some failing tests on Solid which seem to be related to the initial form state, I couldn't see if it's something on the solid-form adapter or even from solid-store

packages/form-core/src/FormApi.ts Outdated Show resolved Hide resolved
packages/form-core/src/FormApi.ts Outdated Show resolved Hide resolved
!prevBaseStore ||
currBaseStore.errorMap !== prevBaseStore.errorMap
) {
errors = Object.values(currBaseStore.errorMap).reduce(
Copy link
Member

Choose a reason for hiding this comment

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

Can we check earlier if onMount errors have to be removed? So that we avoid pushing them now and then filtering them out on lines 515-521

Something like moving up this block

let errorMap = currBaseStore.errorMap
if (shouldInvalidateOnMount) {
    errorMap = Object.assign(errorMap, { onMount: undefined })
}

and then using the local errorMap on Object.values

Copy link
Member Author

Choose a reason for hiding this comment

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

Let's make a follow-up PR on this, seeing that it works today and I'm struggling to think of an easy way to move this around ATM

Copy link
Member

Choose a reason for hiding this comment

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

Sure!

Copy link

codecov bot commented Dec 29, 2024

Codecov Report

Attention: Patch coverage is 92.18750% with 10 lines in your changes missing coverage. Please review.

Project coverage is 86.60%. Comparing base (91eb9ab) to head (1c360a6).
Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
packages/form-core/src/FormApi.ts 91.50% 8 Missing and 1 partial ⚠️
packages/solid-form/src/createField.tsx 90.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1038      +/-   ##
==========================================
- Coverage   86.61%   86.60%   -0.02%     
==========================================
  Files          29       29              
  Lines        1158     1172      +14     
  Branches      301      290      -11     
==========================================
+ Hits         1003     1015      +12     
- Misses        142      144       +2     
  Partials       13       13              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@crutchcorn crutchcorn merged commit be7f9bf into main Dec 29, 2024
7 checks passed
@crutchcorn crutchcorn deleted the derived-state-refactor branch December 29, 2024 16:11
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.

2 participants