Skip to content

refactor: poll for git auth updates when creating a workspace #9804

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

Merged
merged 13 commits into from
Sep 26, 2023

Conversation

aslilac
Copy link
Member

@aslilac aslilac commented Sep 21, 2023

Closes #9536

  • Move gitAuth management out of xstate
  • Poll for updates for one minute (should be more than plenty) after clicking the "Login with [x]" button
  • Show a "check again" button in case one minute isn't long enough
  • Remove some dangling BroadcastChannel stuff that wasn't working (and didn't even seem fully implemented)

@aslilac
Copy link
Member Author

aslilac commented Sep 21, 2023

Remaining improvements I wanna do before merging:

  • Stop polling when all auth providers are connected
  • I think there might've been more BroadcastChannel stuff I can remove

Shouldn't be hard, but I wanted to get this PR up before I quit for the day

@aslilac aslilac requested a review from Parkreiner September 21, 2023 00:21
@BrunoQuaresma
Copy link
Collaborator

I will wait for the remaining work before approve it 👍

@BrunoQuaresma
Copy link
Collaborator

Also I'm missing tests to avoid any kind of regressions, do you think we could add some coverage to it?

Comment on lines -249 to -253
export const watchGitAuthRefresh = (callback: () => void) => {
const bc = new BroadcastChannel(REFRESH_GITAUTH_BROADCAST_CHANNEL);
bc.addEventListener("message", callback);
return bc;
};
Copy link
Member

Choose a reason for hiding this comment

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

I'm confused... this 100% was working, it's in fact how it worked until this entire time.

This removes the need to poll, and generally, we should avoid idle polling on pages. If users leave the "Create Workspace" page up, I don't think it's fair that an operator needs to consume more API requests.

This was a proper regression if it stopped working, not just existing code that didn't work!

Copy link
Member Author

Choose a reason for hiding this comment

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

This is a little different than that case, because it has a timeout where it will stop polling until the user interacts again, so this definitely won't be an "increases load by xx%" type of thing. I get the appeal of BroadcastChannel, but I've always found that it ends up being fragile for stuff like this.

@aslilac
Copy link
Member Author

aslilac commented Sep 26, 2023

I've spent a bit of time trying to figure out how the Broadcast channel was supposed to work, and it seems like a serious chunk of it is missing, and like it might've had a couple bugs anyway. (Namely, it didn't include any way to tell which GitAuth was completed. I can't tell if that triggered a refetch or if it all of the auth providers were supposed to assume the message was for them.)

There's also some other good cleanup stuff in this PR that I want to get merged, so I'm just gonna go with this as-is since it's tested and working. If we want to revisit BroadcastChannel stuff in the future, we can schedule some time for me to circle back.

@aslilac aslilac merged commit 6f0e2a7 into main Sep 26, 2023
@aslilac aslilac deleted the git-auth-polling branch September 26, 2023 17:39
@github-actions github-actions bot locked and limited conversation to collaborators Sep 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Git auth to create a workspace forces page refresh losing all fields
4 participants