Skip to content

Prefs.blocked_total is set before the value was read

This causes the following issue: https://gitlab.com/eyeo/adblockplus/abpui/adblockplusui/-/issues/684

The problem: Prefs.blocked_total++ is basically Prefs.blocked_total = Prefs.blocked_total + 1. What happens here is that when reading Prefs.blocked_total very soon after starting ABP we haven't read the actual saved value from browser.storage. So we fallback to the default value of 0. On the other hand when assigning we actually use Prefs.set, which will write to browser.storage. This means we are basically starting to count from zero.

My solution is to use the Prefs.untilLoaded promise to make sure we have (potentially) loaded a the real blocked_total from the storage. Sadly we can't just fix this by somehow changing the getter, because we can't wait for promises there. I looked through the other Prefs and it didn't look to me like any of them should be set often or very early.