Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Statsig] Slightly block the UI on gates #3608

Merged
merged 1 commit into from
Apr 18, 2024
Merged

[Statsig] Slightly block the UI on gates #3608

merged 1 commit into from
Apr 18, 2024

Conversation

gaearon
Copy link
Collaborator

@gaearon gaearon commented Apr 18, 2024

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:

  • When you sign up
  • When you log in
  • When you switch accounts
  • When you resume session

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:

  • Login (with credentials) and signup have a longer timeout (1500 ms).
  • All other operations have a very short timeout (250 ms).

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:

  1. Opt yourself into some feature flag.
  2. Open incognito mode and log into your account with credentials.
  3. Observe the gate passing immediately after login.

Registration:

  1. Add some code to check the value of test_logged_in_gate during onboarding. (I set it up so that it only passes for logged-in users.)
  2. Create an account
  3. Observe the gate passing immediately after registration.

Finally, you can play with replacing Statsig.prefetchUsers([toStatsigUser(did)]) with a never-resolving Promise like new Promise(resolve => {}) or an always-failing Promise like new Promise(resolve => { throw Error('no') }). Verify that you're still able to create an account, log in, or switch between the accounts.

Copy link

render bot commented Apr 18, 2024

@@ -283,6 +287,7 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
)

__globalAgent = agent
await fetchingGates
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pattern I'm using here is to kick it off as soon as we have the DID, but to await just before the state change.

Copy link

Old size New size Diff
6.42 MB 6.42 MB 432 B (0.01%)

Copy link
Collaborator

@pfrazee pfrazee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. (Didnt test)

@gaearon gaearon merged commit bef7d8a into main Apr 18, 2024
6 checks passed
@gaearon
Copy link
Collaborator Author

gaearon commented Apr 18, 2024

Have gone through all flows, seems to work.

@gaearon gaearon deleted the statsig-blocking branch April 18, 2024 16:54
estrattonbailey added a commit that referenced this pull request Apr 18, 2024
* origin/main:
  [Statsig] Slightly block the UI on gates (#3608)
  [Statsig] Prefetch configs for other accounts (#3607)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants