Skip to content
Source
Sign inSign up
TanStack/form

Component-level Suspense for Solid Form #910

Openoscartbeaumont(GitHub profile, opens in a new tab) opened this issue 2 comments

Describe the bug

Depending on async data within defaultValues causes the Suspense above the component to trigger as opposed to a suspense wrapped around the fields/form.

Component-level suspense would be fine in React where it always is, but in Solid this is a pretty unexpected behavior.

This is probally being triggered by a useMemo wrapping the arguments. I'm not certain of what the expected behavior should be but I don't think this is it.

I'm fairly sure this can currently be worked around by doing something like:

const [default, setDefault] = createSignal({});

// `createComputed` over `createEffect` so that it runs straight away.
//
// by using `createComputed`/`createEffect` over memo we avoid the component-level suspense behavior
createComputed(() => {
    setDefault({
       firstName: somAsyncValue?.firstName,
    });
});

const form = createForm(() => ({ defaultValues: default() }));

but this is pretty annoying and for a newer user to Solid they would have no clue.

Your minimal, reproducible example

https://stackblitz.com/edit/tanstack-form-bxce9x?file=src%2Findex.tsx

Steps to reproduce

See that the page says "App suspense" not "Form suspense" while loading the async data (a 2 second timeout).

Expected behavior

I would expected either:

  • The suspense to be triggered as a field level.
  • A suspense not to be trigger and instead the data is just lazily populated. For a good UX this would probally need to be while the fields are disabled.
    • I don't know if this fits into Tanstack's Form's model but it's what I recon the ultimate DX is because dealing with per-field suspense would likely be more annoying than just having an disabled={form.isDefaultLoading} placeholder={form.isDefaultLoading ? "loading..." : ""}

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

Reproduced in Stackblitz on latest Tanstack Form.

TanStack Form adapter

solid-form

TanStack Form version

v0.29.1

TypeScript version

No response

Additional context

No response

  1. crutchcorn(GitHub profile, opens in a new tab) added labelstype: enhancement

  2. LeCarbonator(GitHub profile, opens in a new tab) added labelsv2: needs investigation

  3. LeCarbonator(GitHub profile, opens in a new tab) removed labelsv2: needs investigation

  4. LeCarbonator(GitHub profile, opens in a new tab) added labelsarea: runtime

  5. LeCarbonator(GitHub profile, opens in a new tab) added labelsscope: solid

  6. LeCarbonator(GitHub profile, opens in a new tab) added labelstype: undecided

  7. LeCarbonator(GitHub profile, opens in a new tab) removed labelstype: enhancement

  8. I'm not sure if that's truly supportable. You can access form values right after its creation. How would that be manageable while also ensuring the suspense doesn't trigger?

    form.state.values -> Needs the resource -> Triggers Suspense

  9. oscartbeaumont(GitHub profile, opens in a new tab)commented

    For SolidJS you could use getters like:

    defaultValues: {
      get fieldOne() {
          return fieldOne();
      }
    }

    With Tanstack's Store approach though you would need nested reactivity which could be more challenging.

Sign in to join this conversation.