Fix (telemetry): guard __moduleInitTimes access to prevent ReferenceError#84265
Conversation
src/setup/telemetry/index.web.ts
Outdated
| @@ -14,6 +14,7 @@ export default function (): void { | |||
| requestAnimationFrame(() => { | |||
| // webpack module timing path (ModuleInitTimingPlugin injected __moduleInitTimes). | |||
| // In dev mode, keys are relative file paths; in production they are numeric IDs. | |||
| reportModuleInitTimes(__moduleInitTimes as Record<string, number> | undefined, undefined, 1); | |||
| // Use typeof guard — bare identifier throws ReferenceError if ModuleInitTimingPlugin didn't run (e.g. Storybook, stale cache) | |||
| reportModuleInitTimes(typeof __moduleInitTimes !== 'undefined' ? __moduleInitTimes as Record<string, number> | undefined : undefined, undefined, 1); | |||
There was a problem hiding this comment.
Please also fix native
Codecov Report✅ Changes either increased or maintained existing code coverage, great job!
|
Reviewer Checklist
Screenshots/VideosAndroid: HybridAppAndroid: mWeb ChromeiOS: HybridAppbefore: Screen.Recording.2026-03-05.at.11.52.01.am.movafter: Screen.Recording.2026-03-05.at.11.53.40.am.moviOS: mWeb SafariMacOS: Chrome / Safari |
|
🎯 @aimane-chnaif, thanks for reviewing and testing this PR! 🎉 An E/App issue has been created to issue payment here: #84270. |
|
Codex Review: Didn't find any major issues. Swish! ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback". |
|
PR doesn’t need product input as a performance PR. Unassigning and unsubscribing myself. |
grgia
left a comment
There was a problem hiding this comment.
Added @roryabraham to final review.
|
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
|
🚧 @roryabraham 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/roryabraham in version: 9.3.32-0 🚀
|
|
Hi @elirangoshen, the storybook page doesn't open for the QA team — it shows a blank page. We noticed this comment.
|
Hi, its internal in my opinion, what do you think @roryabraham ? |
|
Storybook's not been working for ages. I think we can skip that. |
|
@aimane-chnaif Can we check it off then? |
yes |
|
🚀 Deployed to production by https://github.com/blimpich in version: 9.3.32-3 🚀
|


Explanation of Change
index.web.tswas accessing__moduleInitTimesas a bare identifier. A bare identifier lookup throwsReferenceError:__moduleInitTimesis not defined when theModuleInitTimingPluginhasn't run — for example inStorybook(which uses its own webpack config without the plugin) or when a user has a stale browser-cached runtime bundle that predates this feature.The fix wraps the access in a typeof guard so that if the global was never injected, it safely resolves to undefined rather than crashing:
// Before — throws ReferenceError if plugin didn't run
reportModuleInitTimes(__moduleInitTimes as ..., undefined, 1);// After — safe: undefined if plugin didn't inject the global
reportModuleInitTimes(typeof __moduleInitTimes !== 'undefined' ? __moduleInitTimes as ... : undefined, undefined, 1);Note: typeof
undeclaredVaris the one JS operation that never throws aReferenceError, making it the correct guard here.Fixed Issues
$#82975
Tests
Offline tests
QA Steps
// TODO: These must be filled out, or the issue title must include "[No QA]."
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectiontoggleReportand notonIconClick)src/languages/*files and using the translation methodSTYLE.md) were followedAvatar, 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.ScrollViewcomponent to make it scrollable when more elements are added to the page.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
MacOS: Chrome / Safari