phoenixframework / phoenix_live_view

Rich, real-time user experiences with server-rendered HTML
https://hex.pm/packages/phoenix_live_view
MIT License
6.18k stars 930 forks source link

push_patch just query changes #1013

Closed LostKobrakai closed 4 years ago

LostKobrakai commented 4 years ago

Environment

Actual behavior

When doing {:noreply, push_patch(socket, to: "?page=1")} in a liveview callback I get an raised error:

** (ArgumentError) the :to option in push_patch/2 expects a path but was "?page=1"
    (phoenix_live_view 0.13.3) lib/phoenix_live_view.ex:2177: Phoenix.LiveView.raise_invalid_local_url!/2
    …

Expected behavior

The same href works when used with live_patch in my pagination template so it should work for push_patch as well. Given query strings can't change the mounted liveview module I can't see the need for knowing the path and consulting the router.

Additionally I'm wondering if there's merit in an api to only update a single key in the current query. E.g. when a page and search term are in the query just update the page without affecting the search term. That way abstracted components like paginations don't need to be aware of other query params.

josevalim commented 4 years ago

Please give the whole path for now. The reason we don't provide partial updates is because we never store all parameters. This is to avoid attacks where people would inflate LiveView sessions by sending really large payloads. So it is up to you to store the bits that you need.

LostKobrakai commented 4 years ago

I'm wondering how live_patch works then? It seems to do fine with just ?page=1.

josevalim commented 4 years ago

That's because the browser is the one doing the URL manipulation. It is the one that merges ?page=1 to the current URL.