Client side script seems to not work on page change
-
@baris I seem to have the same issues. And the browser console seems to come up blank for errors. I've also tested on multiple browsers to see if it was a just a browser specific issue but that doesn't seem to be the case. I actually got a very botched way of making it work currently with the code below.
$(window).on('action:ajaxify.end', function(ev, data) { if (data.url !== 'login' && data.url !== 'register' && !app.user.uid) { ajaxify.go('login'); } setTimeout(function (){ if (data.url !== 'login' && data.url !== 'register' && !app.user.uid) { ajaxify.go('login'); } }, 500); });
I just do the function again after a slight delay and it seems to be working. Which is really odd and not ideal.
-
You can add a console.log and see if it is getting triggered at all.
$(window).on('action:ajaxify.end', function(ev, data) { console.log('action:ajaxify.end'); if(ajaxify.data.template.name !== 'login' && ajaxify.data.template.name !== 'register'){ if (!app.user.uid || app.user.uid === 0) { ajaxify.go('login'); } } });
-
So it is always going into the
action:ajaxify.end
handler? Can you try the below and see if it works?$(window).on('action:ajaxify.end', function(ev, data) { console.log('action:ajaxify.end'); if(ajaxify.data.template.name !== 'login' && ajaxify.data.template.name !== 'register'){ if (!app.user.uid || app.user.uid === 0) { $('#content, #footer').removeClass('ajaxifying'); ajaxify.go('login'); } } });
-
@baris This specific function is currently on a mostly blank slate, which makes it more confusing as well. I've tried putting in an console log after each if statement as well and it all goes through. It even goes to the
ajaxify.go('login')
but that just seems to do nothing. -
Hmm, can you try putting some more console.logs in
ajaxify.go
there are some cases where that function will not do anything. For example if there is already an ajaxify in progress it returns early.Maybe you are getting caught by the ajaxify timer which prevents quick ajaxifies. https://github.com/NodeBB/NodeBB/blob/master/public/src/ajaxify.js#L41-L43.
In that case try it on the
develop
branch. Looks like @julian fixed that on that branch https://github.com/NodeBB/NodeBB/commit/b4297cd8f065a94e7de5a3ad4b992e61c9234ca0 -
@baris I copied the the code from the 2nd link into my version of Nodebb and that fixed the issue! Seems like there must've been an already ajaxify in progress which killed
ajaxify.go('login')
Thank you so much! The issue is resolved!