LiveView in root layout doesn't update when using push_redirect (possible liveview bug)

I run into a problem where a liveview set in root layout won’t update when I use push_redirect. You can see the minimal example of it in this github repo, relevant files being revealed in this commit (Bug · asprecic/elixir-buggy-sidebar@74c7150 · GitHub) - [root.html.heex, live/Bug.ex and live/Sidebar.ex]
GitHub - asprecic/elixir-buggy-sidebar: Possible bug with phoenix

Basically, the liveview rendered inside the root layout doesn’t update because of push_redirect. If you remove the push_redirect, then it will update the view.

The odd thing here is that if you look at the network traffic or enable debugging in app.js, you will see that the diff is done correctly, the update comes over the network, it is logged correctly in the console, but it never gets applied to the DOM. Sometimes it does get applied, sometimes not, I can’t reliably tell when.

I know I can fix this problem by moving the sidebar into live.html.heex, which will remount it when redirecting, but I’m interested as to why this is not working? In theory, it should, and in practice, we get the good diff, but it’s just not being applied, leading me to believe this might be a liveview bug?

Can someone shed more light on this issue? Is this a problem with liveview itself, or am I doing something wrong or expecting too much from a redirect?

Screenshot: https://i.imgur.com/YJbOw6S.png

Thanks!

Hey,

Can you try updating to latest version of Live View?

Because in latest version, push_redirect has been deprecated!!

See: redirect_to/2 documentation

Ah, you are absolutely right. I’ve upgraded LiveView to 0.18.2, and it worked right away. I didn’t even need to change push_redirect to push_navigate, so it works either way.

I had this problem in a production app, so I generated this smaller app as a minimum example, I thought using the project generator would also use the latest version but it looks like it didn’t.

In any case, thank you for the help!

1 Like

The project generator hasn’t been updated, based on few posts in Elixir forum.

Once Phoenix 1.7 is released, everything the generator outputs will be latest LiveView code, I guess. :smiley: