Skip to content

refactor: remove unsafe type assertions from emoji, selection, and sound utilities - #98879

Merged
blimpich merged 8 commits into
Expensify:mainfrom
KJ21-ENG:seatbelt/c3-260818-r3
Sep 15, 2026
Merged

blimpich merged 8 commits into
Expensify:mainfrom
KJ21-ENG:seatbelt/c3-260818-r3

Conversation

@KJ21-ENG

@KJ21-ENG KJ21-ENG commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor

Explanation of Change

Removes 12 unsafe type assertions from emoji search, formatted selection copying, and native sound loading.

The change keeps the existing emoji and native sound type contracts. It also keeps transformed DOM parent and sibling links coherent before serialization. SVG foreignObject and MathML integration-point children now serialize with paired HTML tags. That is an intentional correction to malformed serialized output, not a claim that every previous byte of output is unchanged.

Fixed Issues

$ #94739
PROPOSAL: #94739 (comment)

Tests

Repeatable development test steps are below. The attached September 12 Chrome recording is partial evidence, not a completed retest of the latest main merge.

  1. Open a report and use the emoji picker to search for smile and thumbs up. Select a skin-tone variant and verify the selected emoji appears correctly in the composer.
  2. Send a message containing bold text, a link, and two lines. Select the rendered message, copy it, and paste into the composer. Verify text order, link, formatting, and line breaks are preserved.
  3. Repeat copying from the composer, including nested formatting and an email address. Verify content is retained without extra blank lines or zero-width breaks in the email address.
  4. On native Android and iOS with in-app sounds enabled, create and complete a task. Verify the completion sound plays and the app remains stable. Mute in-app sounds, repeat, verify no sound plays, then restore the setting.
  • Verify that no errors appear in the JS console

Offline tests

  1. Load the app and report while online, then disconnect the network.
  2. Repeat emoji selection and formatted copy/paste from Tests. Verify these local interactions match the online results.
  3. Reconnect and verify the composer remains usable.

QA Steps

Repeat Tests steps 1–4 on staging for the applicable web and native platforms. Compare any formatting or search failure against current main before attributing it to this PR.

  • Verify that no errors appear in the JS console

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.
  • 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

Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari

September 12 Chrome recording, before the latest main merge. It shows emoji selection and formatted copy/paste online and offline. Online smile search returned no results, and formatted paste lost bold formatting and changed line breaks; these observations have not been established as PR regressions. SVG/MathML fixtures and native sound behavior are not demonstrated in this recording.

17.Kush.J.you._2026-09-12_13-40-52.mp4

@codecov

codecov Bot commented Aug 18, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ Changes either increased or maintained existing code coverage, great job!

Files with missing lines Coverage Δ
...ibs/SelectionScraper/installTransformedChildren.ts 100.00% <100.00%> (ø)
src/libs/Sound/index.native.ts 64.70% <100.00%> (ø)
src/libs/EmojiTrie.ts 96.00% <80.00%> (ø)
src/libs/SelectionScraper/index.ts 82.53% <80.95%> (+82.53%) ⬆️
... and 9 files with indirect coverage changes

@KJ21-ENG KJ21-ENG changed the title Remove unsafe type assertions from emoji, selection, and sound utilities refactor: remove unsafe type assertions from emoji, selection, and sound utilities Aug 21, 2026
@KJ21-ENG
KJ21-ENG marked this pull request as ready for review August 22, 2026 07:22
@KJ21-ENG
KJ21-ENG requested review from a team as code owners August 22, 2026 07:22
@melvin-bot
melvin-bot Bot requested review from ikevin127 and trjExpensify and removed request for a team August 22, 2026 07:22
@melvin-bot

melvin-bot Bot commented Aug 22, 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 removed the request for review from a team August 22, 2026 07:22
Comment thread tests/unit/SelectionScraperTest.ts Outdated

// cspell:ignore mtext

// Selection scraping only exists in the web implementation; the native variant always returns an empty string.

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.

❌ CONSISTENCY-16 (docs)

This comment joins two independent clauses with a semicolon. Per the plain comment style guideline, prefer two separate sentences over a semicolon so the comment reads more naturally.

Split it into two sentences:

// Selection scraping only exists in the web implementation. The native variant always returns an empty string.

Reviewed at: c87258e | 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.

Addressed in bce709d. The comment now uses two sentences instead of joining the clauses with a semicolon.

@ikevin127

ikevin127 commented Aug 22, 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.
  • 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

Android: HybridApp 🔊
screen-20260912-150000-1789250374652.mp4
MacOS: Chrome / Safari
Screen.Recording.2026-09-12.at.14.44.15.mov

@@ -12,6 +12,63 @@ import type GetCurrentSelection from './types';
const markdownElements = new Set(['h1', 'strong', 'em', 'del', 'blockquote', 'q', 'code', 'pre', 'a', 'br', 'li', 'ul', 'ol', 'b', 'i', 's', 'mention-user']);
const tagAttribute = 'data-testid';

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.

🟠 SelectionScraper/index.ts — roughly 60 lines of dom-serializer-internals machinery were added to preserve two invalid-HTML outputs, in order to delete 4 assertions.

The core refactor is right: replaceNodes used to return {...dom, ...} as Element & DataNode, a plain object spread that was not a real domhandler node and whose parent / prev / next still pointed into the original untransformed tree. Replacing that with real cloneNode() instances plus installTransformedChildren is a genuine improvement, and it is what removes the assertions.

But that fix also silently corrected a serialization bug, so the PR adds two shims to put the bug back.

I reproduced this with the repo's own htmlparser2 and dom-serializer:

1) coherent parse -> render     : <svg><foreignObject><div></div></foreignObject></svg>
2) foreignobject name BEFORE    : foreignobject
   foreignobject name AFTER     : foreignObject
3) old spread-style render      : <svg><foreignObject><div/></foreignObject></svg>

And for the editor-collapse case the PR's own test pins:

coherent (span parented to mtext) : <math><mtext><span></span></mtext></math>
stale parent (removed <div>)      : <math><mtext><span/></mtext></math>

What is happening: dom-serializer decides HTML vs foreign (SVG/MathML) mode by reading elem.parent.name, and it mutates elem.name in place during render (foreignobject becomes foreignObject). Under the old code the children's parent pointed at the original, never-renamed node, so the integration-point lookup missed and the children serialized in XML mode. With a coherent tree the lookup hits and they serialize as HTML, which is correct.

installForeignObjectRenderCompatibility recreates the miss by cloning the foreignObject and re-parenting its children onto an unattached lowercase copy. installEditorCollapseRenderCompatibility does the same for children hoisted out of a collapsed editor div.

Two problems with paying that cost:

  1. The preserved output is not valid HTML, and it reaches the clipboard. useCopySelectionHelper.ts:19 calls Clipboard.setHtml(selection, clipboardText), so this string is what lands in the user's clipboard as text/html. <div/> is not self-closing in HTML; every HTML parser treats it as an unclosed <div>. Paste a selection containing an SVG foreignObject into Gmail, Word, or Notion and the unclosed div can swallow the content that follows it. The new test preserves pinned SVG foreignObject serialization asserts that exact string, so the defect is now pinned by a green test.

  2. The shims depend on dom-serializer internals that are not public API: that it mutates elem.name in place, and the exact contents of its private foreignModeIntegrationPoints set. Nothing here would fail loudly if a patch bump changed either. The comments explain the mechanism carefully but never say the behavior being preserved is wrong.

Recommendation: delete both shims and let the coherent tree produce the correct output. That removes about 60 lines, removes the dom-serializer coupling, and still removes all 4 assertions. The two test expectations become <div></div> and <span></span>, and the PR description gains one line saying SVG foreignObject and MathML integration-point children now serialize as well-formed HTML.

If you would rather keep it strictly behavior-preserving, that is defensible for a refactor, but then the comments need to say so plainly:

/**
 * Reproduces a known-incorrect serialization: children of SVG `foreignObject` are emitted in XML
 * mode (`<div/>`) rather than HTML mode. This is invalid HTML that reaches the clipboard via
 * `Clipboard.setHtml`. Preserved deliberately to keep this PR behavior-neutral. See <issue link>.
 */

Right now a future reader has no way to tell this is bug-compatibility rather than a requirement.

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.

Addressed in bce709d. I removed both compatibility shims and kept the transformed domhandler tree coherent. SVG foreignObject and MathML integration-point children now serialize with paired HTML tags. The tests now assert the corrected clipboard output.

Comment thread src/types/global.d.ts
Comment on lines +15 to +19
declare module '*.mp3' {
const value: number;
export default value;
}

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/types/global.d.ts:15 — the *.mp3 declaration is a global claim that is only true for Metro.

Metro resolves asset imports to a numeric registry ID, so number is right on native. Web bundlers resolve them to a URL string. The neighbouring declarations avoid this: *.png and *.jpg both use ImageSourcePropType, which is honest on both platforms.

Today only src/libs/Sound/index.native.ts imports an .mp3, and the web sound path builds string URLs by hand (index.ts:53), so nothing is broken. But this is a global declaration, and the first web-side import x from './foo.mp3' will be typed number while holding a string, with no error anywhere.

AudioSource is string | number | null | {...} (expo-audio/build/Audio.types.d.ts:16), so the honest declaration costs nothing and needs no other change:

declare module '*.mp3' {
    // Metro resolves assets to a numeric registry ID; web bundlers resolve them to a URL string.
    const value: number | string;
    export default value;
}

Worth naming what this change actually is: the hand-written module declaration is the type claim that replaced require(...) as AudioSource. Nothing verifies it. That is the same shape as the overload trick from #98759, though far more defensible here since it matches four existing declarations in the same file.

Making it honest for both bundlers is the difference between a convention and a cast in disguise.

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.

Addressed in bce709d. The *.mp3 declaration now uses number | string, which covers Metro asset IDs and web URLs. The native sound map still narrows each entry to the scalar variants accepted by AudioSource.

Comment thread tests/unit/SelectionScraperTest.ts Outdated
Comment on lines +47 to +52
const documentCloneSpy = jest.spyOn(Document.prototype, 'cloneNode');
selectFixture('<math><mtext><div>first</div><span>middle</span><p>last</p></mtext></math>');

expect(SelectionScraper.getCurrentSelection()).toBe('<math><mtext><div>first</div><span>middle</span><p>last</p></mtext></math>');

const firstCloneResult = documentCloneSpy.mock.results.at(0);

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.

🟡 tests/unit/SelectionScraperTest.ts:52-64 — the MathML test asserts on implementation internals.

const documentCloneSpy = jest.spyOn(Document.prototype, 'cloneNode');
...
const firstCloneResult = documentCloneSpy.mock.results.at(0);

This reaches into the transformed document by grabbing the return value of the first Document.prototype.cloneNode call. It encodes how many times the implementation clones and in what order. Reorder parsedDom.cloneNode() and domRepresentation.cloneNode(true) in getCurrentSelection, and this test fails without any behavior changing.

Since the other three tests already assert on rendered output, this one is the odd one out.

The parent/prev/next wiring it checks is worth testing, but it belongs on installTransformedChildren directly. Export it and test it as a pure function, and the spy disappears.

Separately, line 1:

import type * as SelectionScraperModule from '@libs/SelectionScraper/index.native';
...
jest.requireActual<typeof SelectionScraperModule>('@libs/SelectionScraper/index.ts').default;

This types the web module using the native module's type. They happen to match today, and index.native.ts is a four-line stub returning ''. If the web module ever gains an export, the test's type silently lies. src/libs/SelectionScraper/types.ts already exports GetCurrentSelection, so use that:

jest.requireActual<{default: {getCurrentSelection: GetCurrentSelection}}>('@libs/SelectionScraper/index.ts').default;

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.

Addressed in bce709d. The test no longer spies on Document.prototype.cloneNode. It tests installTransformedChildren directly and derives the web module type from the actual web implementation, so export-shape changes remain type-checked.

Comment thread src/libs/SelectionScraper/index.ts Outdated
Comment on lines +16 to +21
const transformedParent = parent;
transformedParent.children = children;

for (const [index, child] of children.entries()) {
child.parent = transformedParent;
child.prev = index > 0 ? (children.at(index - 1) ?? null) : null;

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.

🟢 installTransformedChildren has a no-op alias and a dead fallback.

const transformedParent = parent;
transformedParent.children = children;
...
child.prev = index > 0 ? (children.at(index - 1) ?? null) : null;

transformedParent is the same object as parent, so the alias only obscures that the function mutates its argument. And for index > 0, children.at(index - 1) is always defined, so ?? null never fires.

Same phantom-fallback pattern that got fixed in #98846 by destructuring with a default.

const installTransformedChildren = (parent: ParentNode, children: ChildNode[]) => {
    parent.children = children;
    for (const [index, child] of children.entries()) {
        child.parent = parent;
        child.prev = children[index - 1] ?? null;
        child.next = children[index + 1] ?? null;
    }
};

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.

Addressed in bce709d. I removed the transformedParent alias and now update parent.children directly. The sibling assignments use indexed neighbors with ?? null, so the dead conditional fallback is gone.

@ikevin127

Copy link
Copy Markdown
Contributor

@KJ21-ENG Dropped (4) code review comments that should be addressed before approval.

@KJ21-ENG
KJ21-ENG marked this pull request as draft August 24, 2026 18:48
@trjExpensify
trjExpensify removed their request for review August 24, 2026 19:41
@trjExpensify

Copy link
Copy Markdown
Contributor

PR doesn’t need product input as a refactor PR. Unassigning and unsubscribing myself.

@KJ21-ENG

Copy link
Copy Markdown
Contributor Author

Addressed all four review findings in bce709d. Ready for another look.

@ikevin127

Copy link
Copy Markdown
Contributor

@KJ21-ENG LGTM, but PR is in draft mode so I can't approve.

@KJ21-ENG

KJ21-ENG commented Sep 7, 2026

Copy link
Copy Markdown
Contributor Author

@ikevin127 Could you please take a look at this when you get a chance? Thanks!

@KJ21-ENG
KJ21-ENG marked this pull request as ready for review September 7, 2026 14:27
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 7, 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 ⚠️ Failed 2026-09-07T14:58:45.109620Z bce709d 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.

@KJ21-ENG
KJ21-ENG marked this pull request as draft September 11, 2026 23:17
@KJ21-ENG

Copy link
Copy Markdown
Contributor Author

@ikevin127 Ah my bad! It looks like some generated GitHub Actions files were unintentionally included while I was testing locally (they were for my fork, I messed up heads) . I’ve removed them, confirmed the PR contains only the intended changes.

@KJ21-ENG

Copy link
Copy Markdown
Contributor Author

FYI, failing Jest tests are unrelated to this PR. They are still on the latest main as well. I will keep an eye on it. Once it's fixed on main, I will merge it here.

@KJ21-ENG

Copy link
Copy Markdown
Contributor Author

@KJ21-ENG PR looks good, thanks for addressing the review comments.

❌ There are two blockers at the moment:

  1. Looks like you pushed changes to ‎.github/actions/javascript/ which should not be pushed as this PR has no business in that area, CI is 🔴.
  2. The PR Author Checklist is incomplete, CI is 🔴.

Let me know once the blockers are resolved and I'll do a final pass 🙌

Both Done BTW

@KJ21-ENG
KJ21-ENG marked this pull request as ready for review September 12, 2026 11:40
Comment thread tests/unit/SelectionScraperTest.ts Outdated
@@ -0,0 +1,80 @@
import type * as SelectionScraperModule from '@libs/SelectionScraper/index.native';

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.

🟡 tests/unit/SelectionScraperTest.ts:1 - The native-type-for-web-module problem is back

This is the exact defect from the first pass, which he fixed in bce709d and has now reverted:

-import type * as SelectionScraperWebModule from '@libs/SelectionScraper/index';
+import type * as SelectionScraperModule from '@libs/SelectionScraper/index.native';

The requireActual call still loads @libs/SelectionScraper/index.ts, so the web module is once again typed with the native module's type.

It compiles today only because moving the helper out made the two surfaces identical again, which is precisely what makes it fragile: the next export added to index.ts puts the test's type silently out of sync with what it loads, and index.native.ts is a four-line stub returning ''.

There was no reason to revert it, probably AI mishap. I confirmed TS resolves @libs/SelectionScraper/index to the web file (no moduleSuffixes in tsconfig.json or in the inherited expo/tsconfig.base), and ESLint was green on the previous form.\

One-line fix, back to what he already had:

import type * as SelectionScraperWebModule from '@libs/SelectionScraper/index';
...
const {default: SelectionScraper} = jest.requireActual<typeof SelectionScraperWebModule>('@libs/SelectionScraper/index.ts');

@ikevin127

Copy link
Copy Markdown
Contributor

🟡 The ### Tests section was dropped from the description.

The rewrite replaced it rather than adding to it. The body now runs Explanation, Fixed Issues, Count change, QA Steps, Offline tests, with no ### Tests anywhere, while .github/PULL_REQUEST_TEMPLATE.md:32 requires it and line 41 of his own checklist is ticked for "I added steps for local testing in the Tests section". The previous version had it:

### Tests
- `npm test -- tests/unit/SelectionScraperTest.ts` - 4 tests passed.
- `npm run typecheck` - passed.

Worth restoring before merge so the section order matches the template and the ticked box is true.

Comment thread tests/unit/SelectionScraperTest.ts Outdated

installTransformedChildren(parent, children);

expect(parent.children).toBe(children);

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.

🟢 tests/unit/SelectionScraperTest.ts:54 - expect(parent.children).toBe(children) still asserts array identity. Carried over from the last pass. It pins that the helper assigns the caller's array rather than copying it, so a defensive copy would fail the test with every DOM relationship still correct.

toEqual is the assertion that matches the intent. The nine toBe calls below it are correct, those really are node identity checks.

Comment thread src/libs/Sound/index.native.ts Outdated
@@ -6,12 +11,12 @@ import {createAudioPlayer, setAudioModeAsync} from 'expo-audio';
import {getIsMuted, SOUNDS, withMinimalExecutionTime} from './BaseSound';

// Sound assets must be required at compile time

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/libs/Sound/index.native.ts:13 - comment is still stale. "Sound assets must be required at compile time" predates the switch to static imports.

@ikevin127

Copy link
Copy Markdown
Contributor

@KJ21-ENG Completed PR Reviewer Checklist, tests well. Dropped (4) more comments above after the final-pass review, these should be addressed before we merge - including the unrelated failing jest unit test.

Tag me once done 🙌

@KJ21-ENG

KJ21-ENG commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor Author

@ikevin127 Addressed the four comments in 95407e7:

  • The test now imports the web module type used by jest.requireActual.
  • The children-array assertion uses toEqual; the parent/sibling node identity assertions remain.
  • Updated the sound comment to match static imports.
  • Restored ### Tests and the template section order in the PR body, preserving the existing recording and clarifying its coverage.

Also merged latest main

@KJ21-ENG
KJ21-ENG requested a review from ikevin127 September 13, 2026 23:40

@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 - Thanks for addressing all comments 🙌

@melvin-bot
melvin-bot Bot requested a review from blimpich September 15, 2026 00:45

@blimpich blimpich 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.

Looks good. Nice job @KJ21-ENG and @ikevin127 👍

@blimpich
blimpich merged commit 197a3a4 into Expensify:main Sep 15, 2026
35 of 37 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.4.80-0 🚀

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

@MelvinBot

Copy link
Copy Markdown
Contributor

🤖 No help site changes are required. No draft PR was created.

This PR is an internal type-safety refactor. It removes unsafe type assertions and adds a DOM-linking helper plus unit tests. It does not add, rename, or remove any feature, setting, tab, or button, so nothing in App/docs/articles goes stale.

How I checked

Files changed (all src/ and tests/, none under docs/):

  • src/libs/EmojiTrie.ts — replaces as HeaderEmoji / as Emoji casts with an in narrowing and a typed Trie<EmojiMetaData>. Emoji search results are unchanged.
  • src/libs/SelectionScraper/index.ts and installTransformedChildren.ts — clones nodes instead of spreading them into a cast object literal, and restores parent/prev/next links before serialization. The one behavior change is that SVG foreignObject and MathML integration-point children now serialize with paired tags, which corrects malformed output. Copying formatted chat text is not documented in the help site.
  • src/libs/Sound/index.native.ts and src/types/global.d.ts — swaps require(...) as AudioSource for static imports with a new *.mp3 module declaration. Which sound plays, and when, is unchanged.

Articles I checked for staleness:

Neither article documents emoji search internals, clipboard serialization, or sound asset loading, which is all this PR touches.

Since no help site PR exists, there is nothing to review or mark Ready for review. @KJ21-ENG, if you believe a user-visible behavior did change here — for example the corrected SVG/MathML copy output is something you want documented — reply with @MelvinBot and the detail, and I'll draft the docs PR.


view run

@jponikarchuk

Copy link
Copy Markdown

The Deploy Blocker issue #101346 is repro on all PRs. Could you please double check if it's not introduced by #98879

@KJ21-ENG

KJ21-ENG commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor Author

Nah, I checked #98879’s diff and the attached logs. This points to #100800: browser Back restores the Insights route without params, and route.params.dashboardID throws the reported error. That code was already present before #98879 merged, and our PR doesn’t modify Insights or navigation.

cc: @blimpich @ikevin127

@blimpich

Copy link
Copy Markdown
Contributor

Agreed

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to production by https://github.com/luacmartins in version: 9.4.80-0 🚀

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

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.

7 participants