Comment on Do posts from instances that don't allow downvotes have an unfair advantage?
Anafroj@sh.itjust.works 1 year agoThanks, that’s a good idea.
The reason why it only works on page reload is because Lemmy is a SPA : it makes it look like you’re browsing several pages, but it’s actually always the same, and it uses javascript to change the url and load new content. So the “load” event, triggered when the current page is done loading, is only triggered once because the page is only changed once. If you wonder why : SPA became commonplace in the 2010s because javascript applications started to get way bigger than previously, and it was helping with page load speed. For a time… because when you make page load faster, people just make it load more things until it’s slow again. :)
My first reaction was that additionally to binding to the load
event, we probably just can bind to the popstate
event, which happens when the url is programmatically changed. But my first tests were not successful in doing that. I’ll have a quick look at the source code of Lemmy in the morning to see if I can solve this.
CloverSi@lemmy.comfysnug.space 1 year ago
Thank you for the explanation! That’s wild, I’ve certainly visited SPA sites but I’ve never given much thought to what must be happening under the hood there. I guess it has its use cases but from a user’s pov the quirks can be kinda annoying. Case in point, I see why
load
wouldn’t do the trick - hope you can find whypopstate
wouldn’t either (and thanks again)!Anafroj@sh.itjust.works 1 year ago
You’re welcome. :) Oh yeah, you probably use a lot of them, they are everywhere, although it’s not obvious to the user. One way to figure it out is to open the browser inspector (usually control + shift + i, same to close it) and look on the “network” tab, which lists all network requests made by the page, to see if this list gets emptied when you click a link (if it’s a real new page, the list is emptied and new requests appear).
My apologies, I spent an hour on the popstate problem before losing interest and calling it a day. Lemmy uses the
inferno
frontend framework (a clone ofreact
), which uses theinferno-router
router to handle page changes, which uses thehistory
lib to do it, which… usespushState
as I expected it would. And yet, binding on popstate won’t work. 🤷 Maybe I’ll have an other look at it one day if it bugs me enough. :)