Repository navigation
Re-resolve beta overrides once the environment settles - #103188
luacmartins merged 5 commits into
Conversation
Permissions kept the environment in a mutable module variable, seeded from CONFIG.ENVIRONMENT and corrected asynchronously. Android ships staging and production from the same binary, so the flag started as production and the correction, being a plain module variable, never reached React. Every beta check made before the native check resolved kept its answer for the session. Replace it with canApplyBetaOverrides(environment), take the environment as a required parameter of isBetaEnabled, and read it in usePermissions from the environment context so the memo invalidates when it settles.
…verride-environment-race
|
@MelvinBot review |
Review: looks good, with one CI fix neededThe approach is sound. Making the environment an argument removes the stale module variable. Adding it to the Blocking:
Nit (optional):
What I checked
|
cspell rejects the British spelling. The var was guarding against an import-time getEnvironment call, which this change removes.
|
@MelvinBot review |
Re-review: ready for human reviewBoth points from my last review are fixed, and all CI checks pass except
Optional nit: Several modules call |
Reviewer Checklist
Screenshots/VideosAndroid: HybridAppScreen.Recording.2026-10-07.at.17.08.31.movAndroid: mWeb ChromeiOS: HybridAppiOS: mWeb SafariMacOS: Chrome / SafariScreen.Recording.2026-10-07.at.17.07.46.mov |
|
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
|
🚧 luacmartins has triggered a test Expensify/App build. You can view the workflow run here. |
|
🧪🧪 Use the links below to test this adhoc build on Android, iOS, and Web. Happy testing! 🧪🧪
|
|
🚀 Deployed to staging by https://github.com/luacmartins in version: 9.5.5-0 🚀
|
|
No help site update is needed. This PR fixes how beta overrides apply on internal non-production builds, and no article in |
|
🚀 Deployed to production by https://github.com/puneetlath in version: 9.5.5-2 🚀
Bundle Size Analysis (Sentry): |
Explanation of Change
Fixes a beta override being silently dropped on any Android staging cold start.
Permissions.tskept the environment in a mutable module variable, seeded fromCONFIG.ENVIRONMENTand corrected asynchronously byisProduction(). Android ships staging and production from the same binary, so that flag startstrueand blocks overrides. The correction mutates a plain module variable, so React never learns about it:usePermissionsmemoized on[betas, betaConfiguration, betaOverrides], none of which changed.Why the staleness was permanent.
NavigationTabBarcomputes the beta inline on every render, so "computed once at mount" is not the mechanism. The component is React Compiler memoized and that cache is keyed on the identity ofisBetaEnabled, which never changed when the flag flipped — so neither theuseMemonor the compiler cache was invalidated.The fix deletes the module state and makes the environment explicit data:
canApplyBetaOverrides(environment)— new pure named export, true unless the build config and the resolved environment both say production.isBetaEnabledtakesenvironmentas a required fifth parameter and applies the gate itself, so no caller can skip it.usePermissionsreadsenvironmentfromuseEnvironment(), so it lives in React state and the memo invalidates when it settles — which invalidates the compiler cache too.DynamicBetaOverridesPagegates its not-found view with the same helper. The page and the behaviour could previously disagree: the page required both signals,Permissions.tsonly the resolved one.On the
environmentdependency. This is the same dependency array that2a13d7d718added and069c7cd218reverted over areact-hooks/exhaustive-deps"unnecessary dependency" error. It is now used inside the memo body, passed toisBetaEnabled, so it is a genuine dependency. Lint is clean.One intentional semantic change. Requiring both signals means a build compiled as
staging/qathat resolves toproductionnow honours overrides. No App build config produces that combination, and if it ever did, a test build would start honouring overrides — the desired direction.Tests.
BetaOverridesProductionTest.tstested the module flag and is replaced byBetaOverridesEnvironmentTest.tsx, which drives the hook through the realEnvironmentProviderwith a deferredgetEnvironment. It pins the behaviour rather than reproducing the original failure: against the pre-fix code the suite cannot load at all, because the old import-timeisProduction()runs before the mock exists. It does guard the regression, including an assertion thatisBetaEnabled's identity changes once the environment settles — a fix returning the right boolean from a stable callback would still leave the tab missing.Fixed Issues
$ #102787
PROPOSAL:
Tests
Which builds can show this. The symptom only exists on a build compiled as production whose resolved environment is staging — an Android staging APK installed outside the Play Store, or an iOS TestFlight build. That combination is what makes
CONFIG.ENVIRONMENTreportproductionwhile the native beta check later reportsstaging. A debug build setsENVIRONMENT=developmentand an ad-hoc build setsadhoc, andgetEnvironmentshort-circuits on both before it reaches the beta checker, so neither ever enters the state where the bug exists — before or after this change.Tested on a debug build and it behaves as expected: overrides apply immediately and clear correctly. That is the expected result either way, since the production gate is never engaged there.
Why there are no screenshots or a video. No build available to us reaches the state where the bug exists. Producing one would mean hand-building a signed
productionReleaseand installing it outside the Play Store. Steps 1–3 are the actual regression and need a staging build — we'd be grateful if someone with staging access could run them.InsightsPageadds a visible tab./beta-overridesby deep link shows the not-found page.Offline tests
Same as Tests. The environment is resolved locally.
QA Steps
Steps 4–6 only. Steps 1–3 need a staging build, which the ad-hoc build attached to this PR is not — see the note above.
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectionAvatar, I verified the components usingAvatarare working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))npm run compress-svg)Avataris modified, I verified thatAvataris working as expected in all cases)Designlabel and/or tagged@Expensify/designso the design team can review the changes.mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.Screenshots/Videos
Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
Details