refactor(browser): migrate Browser view to TypeScript#322
refactor(browser): migrate Browser view to TypeScript#322devin-ai-integration[bot] wants to merge 2 commits intomainfrom
Conversation
Co-Authored-By: shayan@cognition.ai <shayan@cognition.ai>
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
| updateTab: (id, url) => dispatch(updateTab(id, url)), | ||
| const mapDispatchToProps = (dispatch: Dispatch) => ({ | ||
| createNewTab: (url: string, linkType?: string) => | ||
| dispatch(createNewTabAction(url, linkType ?? '')), |
There was a problem hiding this comment.
🟡 linkType ?? '' coerces undefined to empty string, changing stored tab data
When createNewTab is called without a linkType (e.g., when opening a new blank tab at app/components/Views/Browser/index.tsx:304), the mapDispatchToProps wrapper now coerces undefined to '' before dispatching.
Root Cause and Impact
The original JS code at app/actions/browser/index.js:75-81 passed linkType through directly:
createNewTab: (url, linkType) => dispatch(createNewTab(url, linkType)),So the Redux action would contain linkType: undefined, and the tab in the store would have linkType: undefined.
The new code coerces undefined to '':
createNewTab: (url: string, linkType?: string) =>
dispatch(createNewTabAction(url, linkType ?? '')),Now the Redux action contains linkType: '', and the tab in the store has linkType: ''.
This means every tab created without an explicit link type (the common case—home page, user-initiated new tabs) now stores linkType: '' instead of linkType: undefined. Any downstream code that checks tab.linkType !== undefined or uses strict equality to distinguish "no link type" from "has link type" will behave differently. The ?? is unnecessary here since createNewTabAction (plain JS) happily accepts undefined.
| dispatch(createNewTabAction(url, linkType ?? '')), | |
| dispatch(createNewTabAction(url, linkType)), |
Was this helpful? React with 👍 or 👎 to provide feedback.
Co-Authored-By: shayan@cognition.ai <shayan@cognition.ai>
refactor(browser): migrate Browser view to TypeScript
Summary
app/components/Views/Browser/index.js→index.tsxwith explicit TS types forBrowserProps, tab shape, and route params.PropTypesand tightened a few runtime checks uncovered by TS (e.g., guardingactiveTablookup before screenshot, guardingcurrentSelectedAccountbefore Solana check).hasNoTimeoutfield.solanaLogostatic import inside the///: BEGIN:ONLY_INCLUDE_IF(keyring-snaps)conditional compilation block so it is stripped alongside its only usage — avoids unused-variable lint errors during non-keyring-snaps bundle builds.createNewTabAction, etc.) and local functions (handleShowTabs,handleCloseTab,handleCloseAllTabs) to satisfy ESLint no-shadow rules.BrowserTabPropsinapp/components/Views/BrowserTab/types.tsby making a few props optional (activeTab,defaultProtocol,addBookmark,searchEngine) to align with actual usage.timestamp: '987'→timestamp: 987.Review & Testing Checklist for Human
browserUrl as stringcasts (lines ~245, ~270) are safe —browserUrlisstring | undefined, and while there's a truthiness guard before one usage, confirm no edge case can reachURLParsewithundefined.linkType ?? ''inmapDispatchToPropsdoesn't change behavior vs. passingundefined— check ifcreateNewTabaction treats empty string andundefineddifferently.captureScreenoptions usewidth/height(notTHUMB_WIDTH/THUMB_HEIGHTas direct keys) — the old keys don't exist inCaptureOptions.BrowserTabPropsfields optional (activeTab,defaultProtocol,addBookmark,searchEngine) doesn't mask a real missing-prop issue inBrowserTab.solanaLogoimport now lives inside the conditional block.Notes
lint,lint:tsc, andtest:depcheckwere cancelled (not passed) because they share a workflow withaudit:ci, which fails due to pre-existing dependency vulnerabilities unrelated to this PR. Bothtsc --noEmitandeslintwere verified locally with no new errors. Unit tests (all 10 shards) andjs-bundle-size-checkpassed in CI.