I opened an issue in github on that, but I wonder what is the possible workaround.
out-of-the-box generated modal re-renders when closing modal and clicking ‘back’ on browser. The modal was generated by the default generator phx.gen.live Everything works fine, but the modal re-rendering get’s stuck in a loop when using the browser’s back button. See gif
I changed the default JS.navigate to JS.patch but nothing changed either.
P.S I’m very new to Phoenix. Here is my actual repo. it’s not one page, but it comes with a SQLite DB saved in github too, so should work as is. When in the app, click on the Analysis in the main menu and then select one of Countries, States, Cities, Territories List . They all have the same issue and were all generated with the default phx.gen.live Thanks combobox repo
Hmm, are you clicking on the web page outside of the modal in between clicking the back button?
The default .modal core component sets the phx-click-away binding to close the modal when clicking outside the modal. The default generated LiveView also passes a JS.patch command to the .modal via its on_cancel data attribute which is run upon phx-click-away event. This means that clicking away will update the browser history.
Click on “Edit state” button => modal opens and “…/some_resource/show/edit” gets added to browser state
Click outside the modal => modal closes and “…/some_resource” gets added to browser state
Click back button => browser goes back to “…/some_resource/show/edit” and modal opens
the is where and how I added it. Maybe it’s a wrong syntax? In the post you linked the indication was to put it in the index.html.heex where the link to the modal is. In my case it’s when the edit option is clicked
If you’re testing the “show” LiveView for a single state record like in your screen recording, you need to update that LiveView instead of or in addition to the “index” LiveView for multiple state records. You’ll also want to update the modal core component with replace true too otherwise a duplicate entry will get added to the browser history when closing the modal.
Thanks, I stuck it everywhere where there were a new/edit button as well as on every ‘on_cancel’ for every modal and it seemed to have worked. Thanks a lot.