'bp-activity-oldestpage' cookie behavior, when more than a single browser's tab is op

Hi,

In the Social Theme’s global.js file, there is a function that handles the activity’s ‘load-more’ button, and it uses the cookie ‘bp-activity-oldestpage’. This cookie determines the current activity page, and the next page that should be loaded. (The relevant code is attached below).

jq('div.activity').click( function(event) {
var target = jq(event.target);
.......

/* Load more updates at the end of the page */
if ( target.parent().hasClass('load-more') ) {
jq("#content li.load-more").addClass('loading');

if ( null == jq.cookie('bp-activity-oldestpage') ) //what if this cookie has already been set on a different tab?
jq.cookie('bp-activity-oldestpage', 1, {
path: '/'
} );

var oldest_page = ( jq.cookie('bp-activity-oldestpage') * 1 ) + 1;

jq.post( ajaxurl, {
action: 'activity_get_older_updates',
'cookie': encodeURIComponent(document.cookie),
'page': oldest_page
},
function(response)
{
jq("#content li.load-more").removeClass('loading');
jq.cookie( 'bp-activity-oldestpage', oldest_page, {
path: '/'
} );
jq("#content ul.activity-list").append(response.contents);

target.parent().hide();
}, 'json' );

return false;
}
});

My question is:

Do you handle, (and if so, how do you handle) multiple user tabs on the same browser?

For example:

If a user opens an activity page, and clicks the load more button several times. (the ‘bp-activity-oldestpage’ will then have a value that is greater than 1). Then, the user may open a different activity page, and click the ‘load-more’ bottom on that page also.

What will happen then?

Best,

Roei.

  • Patrick
    • Support Monkey

    Hi @rbahumi

    Then, the user may open a different activity page, and click the ‘load-more’ bottom on that page also. What will happen then?

    On my test sites, activity streams that are opened in different tabs of the browser load the next pages normally.

    Have you tried it? What behavior do you see?

  • rbahumi
    • Site Builder, Child of Zeus

    Yes, I have tried that.

    You can test that in the Chrome Development Tools:

    1. Open 2 different activity pages, on which the load more is shown.

    2. On the resources tab – you can see how the local Cookie value changes: Click load-more on one page, and refresh (F5) the second page’s cookie view. (highlighted on the attached resources.png). This will demonstrate how the 2 pages are using the same cookie.

    3. On the Network tab, checking the Header submenu of the AJAX request’s ( the Form Data section, highlighted on the attached network_tab.png ) shows the page parameter value that is sent to the server. Click the load-more button of the second page and see the value it sends to the server. This will demonstrate how the Paging changes on the two pages, as if they were the same page.

    Hopefully, my website will be up at the time you read this, so you will be able to use these first & second pages, instead of creating your own example.

    Regards,

    Roei.

  • Patrick
    • Support Monkey

    Hi again @rbahumi

    The bp-activity-oldestpage function is actually a BuddyPress function that really has nothing to do with the theme.

    According to Google, the BP team has been struggling with this for quite some time :slight_frown:

    If all those wise heads have not yet found a way to keep this from happening, I wouldn’t bet much on my ability to solve it.

    My recommendation is to try to obtain clarification over at the forums at http://buddypress.org

    As this is as far as we can go on this issue, I’m going to go ahead and mark this thread as resolved

  • rbahumi
    • Site Builder, Child of Zeus

    Hi @patrick,

    According to Google, the BP team has been struggling with this for quite some time :slight_frown:

    My recommendation is to try to obtain clarification over at the forums at http://buddypress.org

    I have found many issues with that cookie, but not the one I was pointing. Can you please give me a link to that discussion? (I would like to suggest a solution)

    As this is as far as we can go on this issue, I’m going to go ahead and mark this thread as resolved

    Please don’t mark this as resolved just yet. This problem is caused by an implementation that uses a cookie (shared between all the website’s open tabs), for a variable that should be unique for each Tab (Holding that specific tab’s page number).

    I have a suggested solution for this issue, and want the developer’s opinion:

    1. First, need to hold the page number locally, can be implemented in 2 ways:

    * Holding a global JavaScript variable that will keep track with the paging numbers.

    * Keep the page number in an invisible HTML element (display:none).

    2. Read that number and set the cookie at the beginning of the ‘Load More’ button’s click listener :

    jQuery.cookie('bp-activity-oldestpage', pagenum)

    3. Update the new paging value value on success.

    This way, there is no need to do too many changes, as the cookie usage remains the same – it still indicates the page number.

  • Patrick
    • Support Monkey

    BP team struggle is documented here:

    https://buddypress.trac.wordpress.org/ticket/2000

    …and here:

    http://msoftware17bypass.appspot.com/buddypress.trac.wordpress.org/ticket/4535

    You can see that similar issues were marked as resolved 2 years ago, but they’re still around :slight_smile:

    And the core devs seem to be at a loss as to how to fix it for now; it’s been bumped to BP1.8

    BTW, that 1st link may provide some more insight into a possible solution for your issue.

    I’ll also flag the developer on this thread.

  • Patrick
    • Support Monkey

    As the original poster is no longer an active member, I’m marking this thread resolved simply to remove it from the active ticket system.

    The solution proposed earlier is noted and will be considered for possible inclusion in a future update:

    https://premium.wpmudev.org/forums/topic/bp-activity-oldestpage-cookie-behavior-when-more-than-a-single-browsers-tab-is-open#post-349616

    Important to note however that we are dealing with native BuddyPress functions, not theme functions, and it may not be feasible to override them in a theme.

    Should the member reactivate their account, they should feel free to re-open this thread if their issue persists.

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.