[Statsig] Slightly block the UI on gates #3608
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This adds a
tryFetchGates
method which can be used to optimistically prefetch gates for some user. We are using this method to kick off the fetching in these situations:Then, by the time we ready the UI, we may already have the gates. This lets them kick in immediately instead of after a refresh. That's particularly important for signup since otherwise we have no ability to AB test onboarding.
There are some nuances. If the gate service goes down or if it's too slow, we don't want to block important operations. So there is a timeout. Also, a delay on rare operations (e.g. signup) is more acceptable than, say, a delay every time you start the app. Especially considering that if you're an existing user, you already have polling.
So I divided our cases into two groups:
If the Statsig call is fast (it generally is — unless the user has a bad connection), we always get fresh gates before we render the UI. If the Statsig call is lagging, we're willing to tolerate it a bit more during account creation and login, but not for longer than 1500 ms. And we're not willing to tolerate slow calls during everyday usage (so 250ms is the limit).
Test Plan
First, go through the same flows as in #3607. The last flow should now work even without steps 5 and 6 if your connection is fast enough (despite polling being commented out). You can artificially inflate the
timeoutMs
from 250 to 1000 for easier testing.Next, try these flows. (For these, you can disable polling to keep testing cleaner. But it's also worth testing them at least once with polling set to 5 seconds.)
Incognito login:
Registration:
test_logged_in_gate
during onboarding. (I set it up so that it only passes for logged-in users.)Finally, you can play with replacing
Statsig.prefetchUsers([toStatsigUser(did)])
with a never-resolving Promise likenew Promise(resolve => {})
or an always-failing Promise likenew Promise(resolve => { throw Error('no') })
. Verify that you're still able to create an account, log in, or switch between the accounts.