QwikDev / qwik

Instant-loading web apps, without effort
https://qwik.dev
MIT License
20.77k stars 1.29k forks source link

[🐞] data is not persisted in `action.formData` #6653

Open shirotech opened 3 months ago

shirotech commented 3 months ago

Which component is affected?

Qwik Runtime

Describe the bug

From the documentation: https://qwik.dev/docs/action/#previous-form-state

The action.formData is especially useful for retaining user-filled form data even after a page refresh. This enables a seamless SPA experience, even with JS disabled.

This suggests, there is some kind of data persistence, after I refresh the page, the value does not populate, even if I navigate from the router back and forth, data is also gone. Any help would be greatly appreciated. Thank you.

Reproduction

https://stackblitz.com/edit/qwik-starter-r1ebkb?file=src%2Froutes%2Findex.tsx

Steps to reproduce

  1. Run npm install followed by npm run dev (should be automatic)
  2. Wait for packages to install
  3. Click on "Open Preview in new tab" from the preview panel on the right
  4. Click on button "Connect to project"
  5. input anything, click submit
  6. refresh page
  7. No data is persisted

System Info

System:
    OS: macOS 14.5
    CPU: (8) arm64 Apple M2
    Memory: 176.88 MB / 8.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.15.0 - ~/.nvm/versions/node/v20.15.0/bin/node
    Yarn: 1.22.22 - /opt/homebrew/bin/yarn
    npm: 10.7.0 - ~/.nvm/versions/node/v20.15.0/bin/npm
    pnpm: 9.4.0 - /opt/homebrew/bin/pnpm
    bun: 1.1.18 - /opt/homebrew/bin/bun
  Browsers:
    Safari: 17.5
  npmPackages:
    @builder.io/qwik: ^1.6.0 => 1.6.0
    @builder.io/qwik-city: ^1.6.0 => 1.6.0
    typescript: 5.5.3 => 5.5.3
    undici: ^6.19.2 => 6.19.2
    vite: ^5.3.3 => 5.3.3

Additional Information

No response

shirotech commented 3 months ago

Anyone from the team that has insights on this? Is it a bug or misleading documentation?

wmertens commented 3 months ago

So the formData is sent to the server, and that is when the persistence happens: when you serve a page, what you put in the formData is then provided to the next server POST.

So the persistence in the documentation only pertains to stepping through form pages.

If the user clicks on a link, there's no formData sent and then when they go to the form page again, it will be fresh.

During SPA, you can retain all the data in context so there is no problem.

But if you want to really persist data for no-js users, you'll have to use session cookies.

Is that clearer? Could you perhaps update the documentation so that it would have been clear to you from the start?