Fixed Expiry date when using XF.ToggleStorageData is not adhered

Affected version
2.1.4

NixFifty

Well-known member
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);
 

Xon

Well-known member
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.
 

Jeremy P

Well-known member
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.
 

XF Bug Bot

XenForo bug fixer bot
Staff member
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.
 

romubebs

Member
"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
 

Chris D

XenForo developer
Staff member
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.
 

romubebs

Member
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
 
Top