Skip to content

Remove unsafe assertions from badge and theme style defaults - #100026

Merged
blimpich merged 3 commits into
Expensify:mainfrom
KJ21-ENG:seatbelt/c1-260901-r1
Oct 19, 2026
Merged

blimpich merged 3 commits into
Expensify:mainfrom
KJ21-ENG:seatbelt/c1-260901-r1

Conversation

@KJ21-ENG

@KJ21-ENG KJ21-ENG commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

Explanation of Change

Remove unsafe assertions from StatusBadge color styles and replace the default theme-style context Proxies with explicit lazy styles and StyleUtils getters. The getters retain cached values and the existing default theme; badge appearance still needs visual QA.

Changed files: src/components/StatusBadge.tsx, src/components/ThemeStylesContextProvider/default.ts.

Fixed Issues

$ #94739
PROPOSAL: #94739 (comment)

Tests

At the current PR head, upstream TypeScript, ESLint, Oxfmt, React Compiler, Storybook tests, and all eight Jest jobs passed.

QA Steps

  • 1. Badge theme changes.

    • In Search > Reports, find a row with a visible status badge.
    • Switch light → dark → light, returning to the row after each switch.
    • Expected: the badge remains visible and readable, its label and spacing remain stable, and its text/background colors update with the selected theme.

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • If new assets were added or existing ones were modified, I verified that:
    • The assets are optimized and compressed (for SVG files, run npm run compress-svg)
    • The assets load correctly across all supported platforms.
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • If the PR adds or modifies the UI:
    • I asked an AI agent to review the changes for accessibility issues and addressed its findings.
    • I tested with a screen reader (VoiceOver on macOS) and verified all new/changed elements are reachable with a logical focus order.
    • I verified all new/changed elements have meaningful accessible names and roles.
    • I verified state changes are announced (e.g. checked/unchecked, expanded/collapsed, selected).
  • I added unit tests for any new feature or bug fix in this PR to help automatically prevent regressions in this user flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

Recordings (1)
pr100026-report-badge-theme-desktop.mp4

Seatbelt-Operation: main-update-100026-20261016-sign-5b2aba3a
@KJ21-ENG
KJ21-ENG marked this pull request as ready for review October 16, 2026 21:22
@KJ21-ENG
KJ21-ENG requested review from a team as code owners October 16, 2026 21:22
@melvin-bot
melvin-bot Bot requested review from ikevin127 and removed request for a team October 16, 2026 21:22
@melvin-bot

melvin-bot Bot commented Oct 16, 2026

Copy link
Copy Markdown

@ikevin127 Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@melvin-bot
melvin-bot Bot requested review from dylanexpensify and removed request for a team October 16, 2026 21:22
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-16T21:34:26.405791Z fdf5b40 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Comment thread src/components/StatusBadge.tsx Outdated
const bgColor = (backgroundColor ?? theme.transparent) as string;
const txtColor = (textColor ?? theme.text) as string;
const textColorStyle: TextStyle = {color: textColor ?? theme.text};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

❌ UI-5 (docs)

This hand-builds {color: textColor ?? theme.text} as a TextStyle, but an existing StyleUtils helper already produces exactly this shape: getColorStyle(color: string) returns {color}. Duplicating the helper's logic inline bypasses the shared style system and means future changes to how a color style is produced won't reach this call site.

Reuse the existing helper, keeping the previous usage:

<Badge
    text={text}
    isCondensed
    badgeStyles={[styles.ml0, styles.borderNone, StyleUtils.getBackgroundColorStyle(backgroundColor ?? theme.transparent), badgeStyles]}
    textStyles={StyleUtils.getColorStyle(textColor ?? theme.text)}
/>

If the goal was to drop the as string cast, prefer widening getColorStyle's parameter to ColorValue over rebuilding the object literal here, so the helper stays the single source of truth.


Reviewed at: fdf5b40 | Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Reused StyleUtils.getColorStyle in StatusBadge. Updated the shared helper and TextColorStyle to accept React Native ColorValue, so no string cast is needed.

@ikevin127

ikevin127 commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Reviewer Checklist

  • I have verified the author checklist is complete (all boxes are checked off).
  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
  • I checked that screenshots or videos are included for tests on all platforms
  • I included screenshots or videos for tests on all platforms
  • I verified that the composer does not automatically focus or open the keyboard on mobile unless explicitly intended. This includes checking that returning the app from the background does not unexpectedly open the keyboard.
  • I verified tests pass on all platforms & I tested again on:
    • Android: HybridApp
    • Android: mWeb Chrome
    • iOS: HybridApp
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
  • I verified proper code patterns were followed (see Reviewing the code)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I verified that this PR follows the guidelines as stated in the Review Guidelines
  • I verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar have been tested & I retested again)
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG)
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • If the PR adds or modifies the UI:
    • I asked an AI agent to review the changes for accessibility issues and addressed its findings.
    • I tested with a screen reader (VoiceOver on macOS) and verified all new/changed elements are reachable with a logical focus order.
    • I verified all new/changed elements have meaningful accessible names and roles.
    • I verified state changes are announced (e.g. checked/unchecked, expanded/collapsed, selected).
  • For any bug fix or new feature in this PR, I verified that sufficient unit tests are included to prevent regressions in this flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.
  • I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

Screenshots/Videos

Screen.Recording.2026-10-16.at.19.30.36.mov

Comment thread src/components/StatusBadge.tsx Outdated

const bgColor = (backgroundColor ?? theme.transparent) as string;
const txtColor = (textColor ?? theme.text) as string;
const textColorStyle: TextStyle = {color: textColor ?? theme.text};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

src/components/StatusBadge.tsx L28

🟡 Echoing the UI-5 bot comment here, but going back to getColorStyle(txtColor) would need the as string again, because getColorStyle only accepts string while textColor is a ColorValue.

The real fix is to widen the helper so it matches getBackgroundColorStyle(backgroundColor: ColorValue):

// src/styles/utils/types.ts
type TextColorStyle = {color: ColorValue};

// src/styles/utils/index.ts
function getColorStyle(color: ColorValue): TextColorStyle {
    return {color};
}
textStyles={StyleUtils.getColorStyle(textColor ?? theme.text)}

This works for every current caller (they all pass the result into a style array), and it means the next ColorValue caller won't need another cast or another inline object.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated getColorStyle and TextColorStyle to use React Native ColorValue, then reused the helper in StatusBadge. Kept getTextColorStyle's inferred string-only result for its web CSS consumers. The focused type check includes the actual MapView consumer and passes.

Comment on lines +15 to +31
get styles() {
if (!cachedState) {
cachedState = {styles: styles(defaultTheme)};
}
return cachedState[prop];
return cachedState.styles;
},
});
};

const defaultThemeStylesActionsContextValue = new Proxy({} as ThemeStylesActionsContextType, {
get(_, prop: keyof ThemeStylesActionsContextType) {
const defaultThemeStylesActionsContextValue: ThemeStylesActionsContextType = {
get StyleUtils() {
if (!cachedActions) {
if (!cachedState) {
cachedState = {styles: styles(defaultTheme)};
}
cachedActions = {StyleUtils: createStyleUtils(defaultTheme, cachedState.styles)};
}
return cachedActions[prop];
return cachedActions.StyleUtils;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

src/components/ThemeStylesContextProvider/default.ts L15-31

🟢 The cachedState lazy init is copied into both getters. Can we pull it into one helper so the two can't drift apart ?

function getDefaultState(): ThemeStylesStateContextType {
    if (!cachedState) {
        cachedState = {styles: styles(defaultTheme)};
    }
    return cachedState;
}

const defaultThemeStylesStateContextValue: ThemeStylesStateContextType = {
    get styles() {
        return getDefaultState().styles;
    },
};

const defaultThemeStylesActionsContextValue: ThemeStylesActionsContextType = {
    get StyleUtils() {
        if (!cachedActions) {
            cachedActions = {StyleUtils: createStyleUtils(defaultTheme, getDefaultState().styles)};
        }
        return cachedActions.StyleUtils;
    },
};

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Extracted the lazy initialization into one private getDefaultState helper used by both getters. Checks confirm that initialization stays lazy and both getters share the same cached objects.

@ikevin127 ikevin127 left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

PR is clean, with 2 small comments ☝️. It removes two as string casts from StatusBadge and replaces the two Proxy-based default contexts with lazy getters. The getters also fix an old problem: spreading the empty-object Proxy used to return {}.

Tag me once comments are addressed.

@dylanexpensify dylanexpensify left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

refactor, product review not required

Seatbelt-Operation: reviewer-fix-100026-3f8e0fc5-ff3c-4842-b116-95ff6d1d7cdb
@KJ21-ENG
KJ21-ENG requested a review from a team as a code owner October 19, 2026 16:57
@KJ21-ENG

Copy link
Copy Markdown
Contributor Author

@ikevin127 Could you please check this once you get a chance, Thanks!

@ikevin127 ikevin127 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 LGTM - Both of your comments (and the UI-5 bot comment) are addressed in 8380a90, ready to merge!

@melvin-bot
melvin-bot Bot requested a review from blimpich October 19, 2026 22:40
@blimpich
blimpich merged commit 5c91ce6 into Expensify:main Oct 19, 2026
38 of 41 checks passed
@OSBotify

Copy link
Copy Markdown
Contributor

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@github-actions

Copy link
Copy Markdown
Contributor

🚧 blimpich has triggered a test Expensify/App build. You can view the workflow run here.

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to staging by https://github.com/blimpich in version: 9.5.15-1 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

@MelvinBot

Copy link
Copy Markdown
Contributor

No help site update is needed. This PR only removes TypeScript type assertions in status badge and theme style code, so nothing users see or do changes.


view run

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to production by https://github.com/grgia in version: 9.5.15-3 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

Bundle Size Analysis (Sentry):

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.

6 participants