django-unicorn icon indicating copy to clipboard operation
django-unicorn copied to clipboard

LocationUpdate() not working properly

Open saarrooiii opened this issue 3 years ago • 1 comments

When calling this method form a component the url changes as expected, but somehow the changes are not saved in the search history, because when clicking on the navigation arrows (next-page / previous-page) the url changes according to the changes it's gone through (as expected) but the page doesn't change accordingly, the last page sits still until visiting a page previous to the one using LocationUpdate.

I'll try to fix this error myself, but any help is welcome !

P.S I love this framework !!! Using it really does seem like magic.

saarrooiii avatar Jul 28 '22 18:07 saarrooiii

Thanks for the kind words! I'm not sure what is happening with LocationUpdate not updating the history. I am using pushState in the JS here: https://github.com/adamghill/django-unicorn/blob/a9a69e44e363beb9883781635e2b6d8936cef986/django_unicorn/static/unicorn/js/messageSender.js#L105. Is this only happening in a particular browser or on everything you have tried?

adamghill avatar Jul 29 '22 13:07 adamghill

@saarrooiii I added some example code to make sure I understood how the redirects are working in https://github.com/adamghill/django-unicorn/pull/424 in case that's useful. One thing that is...confusing is that the URLs go back if you use the back button after updating them with LocationUpdate, but the page won't reflect that change. Take a look at this movie to see what I mean.

https://user-images.githubusercontent.com/317045/183311984-0af003c4-e070-43bb-a3a9-05c0e5a472a9.mp4

adamghill avatar Aug 07 '22 21:08 adamghill

I see, that's what was happening to me, that the page didn't reflect the changes while the urls did go back, and that's what I though was broken... Thanks a lot for the explanation and examples !

I actually decided to just implement full page reloads at the moment and come back to this approach (feth just parts of the page while refleting the changes in the url) later once my project is more advanced.

I'm sure I'll come up with a clever and convenient way to implement this, and I'll then make a commit to implement this functionality in unicorn (if people are interested).

Again, thanks a lot for the support !!!

saarrooiii avatar Aug 07 '22 22:08 saarrooiii

I'll then make a commit to implement this functionality in unicorn (if people are interested).

I'm interested! That would be awesome. :)

I wonder if the state parameter could include the component data (right now I just pass {} every time) and https://developer.mozilla.org/en-US/docs/Web/API/Window/popstate_event could be used?

I'm going to close this issue for now since I think it's working as expected, but feel free to make a new issue/PR in the future for new functionality. 👍

adamghill avatar Aug 08 '22 01:08 adamghill