Skip to content

Use globalEnvironment$ on environment selector#20495

Open
trmartin4 wants to merge 1 commit intomainfrom
auth/use-global-environment
Open

Use globalEnvironment$ on environment selector#20495
trmartin4 wants to merge 1 commit intomainfrom
auth/use-global-environment

Conversation

@trmartin4
Copy link
Copy Markdown
Member

@trmartin4 trmartin4 commented May 4, 2026

🎟️ Tracking

https://bitwarden.atlassian.net/browse/PM-30715

📔 Objective

We currently subscribe to the environment$ observable on the EnvironmentSelector.

The environment$ makes decisions based on whether the user is logged in or not, which may result in race conditions on logout, when the application is transitioning from an authenticated to unauthenticated state.

This added complexity is not necessary on the EnvironmentSelector, as by definition when you're selecting an environment to log into, you're not logged in, and therefore user-scoped state is not in play. The EnvironmentSelector should only care about the "global" (non-user-scoped) environment.

The screenshot below shows that login and logout work as expected, and the environment does change correctly. The issue this is trying to reproduce does not occur consistently on any environment, and only on environments that use MDM for setting the environment.

📓 Note that follow-up work will be done to deprecate environment$ and replace with an accountEnvironment$ that is explicitly scoped to the logged-in user. This will be done separately and by the Platform team. This is tracked in https://bitwarden.atlassian.net/browse/PM-36480.

📸 Screenshots

Screen.Recording.2026-05-04.at.1.29.27.PM.mov

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented May 4, 2026

@trmartin4 trmartin4 added the ai-review Request a Claude code review label May 4, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 4, 2026

🤖 Bitwarden Claude Code Review

Overall Assessment: APPROVE

Reviewed a one-line change in EnvironmentSelectorComponent that switches the selectedRegion$ source from environmentService.environment$ to environmentService.globalEnvironment$. The change is well-scoped: the environment selector is used during the unauthenticated login flow, so the user-aware environment$ stream introduces unnecessary complexity (and a potential logout race condition documented in the PR). globalEnvironment$ is the correct stream because setEnvironment() writes to global state, which this observable reflects, and libs/auth/src/angular/login/login.component.ts already follows this pattern.

No findings.

Code Review Details

No issues found.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 4, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 47.11%. Comparing base (7f895d6) to head (f6f443f).
⚠️ Report is 2 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #20495      +/-   ##
==========================================
- Coverage   47.11%   47.11%   -0.01%     
==========================================
  Files        3950     3951       +1     
  Lines      119726   119732       +6     
  Branches    18348    18349       +1     
==========================================
+ Hits        56408    56410       +2     
- Misses      59081    59086       +5     
+ Partials     4237     4236       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@trmartin4 trmartin4 marked this pull request as ready for review May 4, 2026 21:54
@trmartin4 trmartin4 requested a review from a team as a code owner May 4, 2026 21:54
@trmartin4 trmartin4 requested review from JaredSnider-Bitwarden and removed request for JaredSnider-Bitwarden May 4, 2026 21:54
Copy link
Copy Markdown
Contributor

@JaredSnider-Bitwarden JaredSnider-Bitwarden left a comment

Choose a reason for hiding this comment

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

This makes perfect sense to me. Thank you for the in depth explanation. As this is an unflagged change, please talk to QA about testing on the feature or in main. Also, please ask for testing on both desktop and the extension as both use this shared component (web has its own, older implementation).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-review Request a Claude code review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants