QwikDev / qwik

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

[🐞] Qwik 1.9.0 holds onto searchParams when redirecting from a server action #6926

Closed brandonpittman closed 1 month ago

brandonpittman commented 1 month ago

Which component is affected?

Qwik City (routing)

Describe the bug

Through 1.8.0, our app would successfully redirect from server actions to some URL like /profile from the front page of the app. The front page takes an ?id=XXX param to get some data and then after tapping a consent button, it runs an action, saves data to a cookie and throws a redirect.

It used to drop the search params when redirecting. Since 1.9.0, it holds onto the search params.

Reproduction

https://stackblitz.com/edit/github-cv95eb?file=src%2Froutes%2Findex.tsx

Steps to reproduce

No response

System Info

System:
    OS: macOS 15.1
    CPU: (10) arm64 Apple M1 Pro
    Memory: 63.16 MB / 16.00 GB
    Shell: 3.7.1 - /opt/homebrew/bin/fish
  Binaries:
    Node: 18.20.3 - ~/Library/pnpm/node
    Yarn: 1.22.19 - ~/Library/pnpm/yarn
    npm: 10.7.0 - ~/Library/pnpm/npm
    pnpm: 9.4.0 - ~/Library/pnpm/pnpm
  Browsers:
    Chrome: 129.0.6668.60
    Safari: 18.1
    Safari Technology Preview: 18.0
  npmPackages:
    @builder.io/qwik: 1.9.0 => 1.9.0
    @builder.io/qwik-city: 1.9.0 => 1.9.0

Additional Information

No response

brandonpittman commented 1 month ago

Seems related to this:

https://github.com/QwikDev/qwik/pull/6778/files#diff-6c570481bf47bb1dae75e8d12166dc67e7ed94954b9714816b7378813b20a24d

But if this is what the team thinks should be the correct behavior, how can I drop the searchParams?

wmertens commented 1 month ago

@brandonpittman can you provide a repro so we're talking about the same things? I thought that change was to provide search parameters when calling actions?

brandonpittman commented 1 month ago

@wmertens

The Stackblitz link above shows this behavior:

If you submit a form from a page with searchParams and redirect in the action, the page you get redirected to has the previous page’s searchParams even though the redirect was to a route with no searchParams.

This only started with 1.9.0.

Here's a recording showing the problem (includes audio).

https://github.com/user-attachments/assets/eacb88b4-f272-49b4-8317-e7c3b2f4d57a

brandonpittman commented 1 month ago

@wmertens Just for completeness, here's another Stackblitz (with recording) pinned at 1.8.0 where redirects don't hold onto the submitting page's searchParams.

https://stackblitz.com/edit/github-cv95eb-7l9fik?file=package.json

https://github.com/user-attachments/assets/11bff795-3abf-4121-bbde-6c763f10184c

brandonpittman commented 1 month ago

Pretty sure this is what broke things:

https://github.com/QwikDev/qwik/pull/6778

brandonpittman commented 1 month ago

Another problem is that if you redirect to a URL with searchParams, Qwik drops the params in the URL you try to redirect to.

brandonpittman commented 1 month ago

I created a PR. Can someone take a look at it, please?

https://github.com/QwikDev/qwik/pull/6927