Double live_patch and URL shown in the browser

I have a handle_params/3 clause that sends a live_patch down the socket. Assume the first path is PATH_A and the second path is PATH_B, I found the following discrepancy:

  • If I load PATH_A from scratch, it will patch itself to PATH_B correctly and the browser’s location bar shows PATH_B.
  • If something else live_patch to PATH_A, the end result is both handle_params/3 are executed and the page is rendered with the content of PATH_B, however, the url in the location bar is showing PATH_A.

I don’t think this is right. Somehow the double live_patch make the content and URL disagree: the server side is patched twice and renders the correct content but the client side patch the location only once. How do I fix or work around this?

I think you should make your handle_params/3 function as lean as possible with a single responsibility: deserializing state from URL params to your socket assigns.

Can you move the piece of code that needs to transform PATH_A to PATH_B before the url is patched? (so that you can directly patch to PATH_B)

If possible, give us a real life example so we can understand why you need to rewrite PATH_A to PATH_B and what it involves

1 Like

This is a bug. Please isolate it in a small app and open up an issue. It should point to PATH_B.

1 Like

Will do that within today. Thanks

bug filed with a minimal test case:

I can work around the issue by using a button instead of a live_patch for the first action for sure. However what I wanted to do is not horribly inefficient. handle_event or handle_params, it is roughly the same amount of work. In my case I already have a portal link, which can patch the LV depends on several factors. The portal link works as an entry point to my app, and it should be reasonable to expect the portal link work within my app as a live_patch, right?