denoland / fresh

The next-gen web framework.
https://fresh.deno.dev
MIT License
12.15k stars 619 forks source link

[bug] partial on form submit #2409

Closed emilbillberg closed 2 months ago

emilbillberg commented 4 months ago

When using partial with forms the url is updated in the browser to the url of the partial value (f-partial).

Example:

<div f-client-nav>
  <form method="get" action="/search" f-partial="/partials/test">
    <input type="text" name="q" />
    <button type="submit">Search</button>
  </form>
</div>

On submit event the url in the browser is updated to /partials/test?q=<query>. I would expect the url in the browser to be updated to /search?q=<query>.

When digging through the code I can see the function maybeUpdateHistory with the url of the partial location is called. https://github.com/denoland/fresh/blob/main/src/runtime/entrypoints/main.ts#L1096

A solution would be to create two different url variables, one from f-partial and one from action. Both of them need to contain the new search params from the form. That approach seems to be done for the click event https://github.com/denoland/fresh/blob/main/src/runtime/entrypoints/main.ts#L958-L960

adamgreg commented 2 months ago

This has been affecting my app too. Thanks @emilbillberg!