Skip to content
Source
Sign inSign up
TanStack/form

`form.state` isn't reactive (Svelte) #1738

Send to my agent
ClosedTyler-Petrov(GitHub profile, opens in a new tab) opened this issue 3 comments

Describe the bug

The state property for the form isn't reactive. Here's a StackBlitz that shows the error. I'll explain my example here as well. After calling createForm the state.isDirty property is accessed from the created form inside the markup. I also access the isDirty from the first name field. The error comes in when a field is updated (thus set to dirty), and form.state.isDirty doesn't reflect this change and stays false. I could be missing something here, but at the very least it's confusing

Update: field.form.state.isDirty reacts as it should. It's included in the StackBlitz example, but not the screen capture

Your minimal, reproducible example

https://stackblitz.com/edit/tanstack-form-rcp3ph5y?file=src%2FApp.svelte&preset=node

Steps to reproduce

Type anything in the "First Name" field

Expected behavior

Form Dirty doesn't update with Field Dirty

How often does this bug happen?

Every time

Screenshots or Videos

https://github.com/user-attachments/assets/1ab71899-6a1b-4305-85a2-cdf651a5570f

Platform

  • OS: Windows 11
  • Browser: Chrome & Zen (Firefox)

TanStack Form adapter

svelte-form

TanStack Form version

1.20.0

  1. The form hook itself is not reactive. If you want to subscribe to form state reactively, you can check the Reactivity section in the Basic Concepts docs

    <form.Subscribe selector={state => state.isDirty}>
      {#snippet children(isDirty)}
        Form Dirty (Changes if isDirty updates): {isDirty}
      {/snippet}
    </form.Subscribe>

    The reason why the state worked in the field callback is because it runs on every change, which will affect the isDirty state that is being read.

  2. Okay, that makes sense. Am I correct in thinking that the form.state is from TanStack form core, so it can't be reactive in Svelte using runes?

  3. Closing just to keep our triage closer knit

Sign in to join this conversation.