Fixed Expiry date when using XF.ToggleStorageData is not adhered

Naz

XenForo developer
Staff member
Affected version
2.1.4
Unless I'm missing something, using the set function on XF.ToggleStorageData and passing an expiry seconds value has no effect for cookies. It looks syncToStorage in XF.ToggleStorageDataInstance does not include it when writing.

JavaScript:
let storage = XF.ToggleStorageData.getInstance('cookie');
storage.set('x', 'y', 'z', 315360000);
 
The problem is all 'toggle' instances are written to a single cookie which results in the expiry being ignored. The XF framework then defaults to a session cookie which is likely unexpected.
 
The problem is all 'toggle' instances are written to a single cookie which results in the expiry being ignored. The XF framework then defaults to a session cookie which is likely unexpected.
The expiry isn't actually ignored (though, for some reason, there's no support for setting an expiry from XF.ToggleStorage, even though the underlying XF.ToggleStorageData objects fully support it).

Since multiple togglers with different expiries can be stored in a single data container, expiry is handled by storing expiry values together with the toggler values, and pruning expired items when the values are read from the container. The expiry is not meant to effect the lifetime of the container itself (especially considering local storage has no native expiry mechanism).

Still, having the cookie lifetime default to a single session definitely feels unexpected since local storage typically sticks around for longer. This issue is compounded by the fact that using the cookie container is the only way to achieve server-side rendering of togglers (via the is_toggled template function). Otherwise there is a noticeable flicker since togglers can't be applied until JS is initialized.
 
Thank you for reporting this issue. It has now been resolved and we are aiming to include it in a future XF release (2.1.6).

Change log:
Store the master Toggle cookie data for a set time, rather than per session (1 year). Support being able to specify the expiry date of each storage item and default it to 1 day. Fix some bugs which may have prevented entries from expiring when needed.
Any changes made as a result of this issue being resolved may not be rolled out here until later.
 
"Support being able to specify the expiry date of each storage item and default it to 1 day. "

Where can this be adjusted? We are trying to figure out why hiding nodes with toggle resets after some time (1 day?)

@Chris D
 
You would have to ask whoever implemented the node hiding functionality. It would be them who would have to override the toggle expiry in their implementation.
 
You would have to ask whoever implemented the node hiding functionality. It would be them who would have to override the toggle expiry in their implementation.

Thanks.

@Steve F we are using Pixel Exit Flat Awesome+ theme (Xenforo 2.1.7) and our users are experiencing node toggle setting to reset after 1 day or so(?). Any help to keep this toggle selection longer in cookie? Thanks
 
If I’m not mistaken our next update will include an expiry option. Feel free to post over at Pixel Exit for help on applying it now.
 
Top Bottom