Open Bug 2065670 (tabbrowser-ts) Opened 3 months ago Updated 3 days ago

[meta] Enable TypeScript for browser/components/tabbrowser

Categories

(Firefox :: Tabbed Browser, task)

task

Tracking

()

ASSIGNED

People

(Reporter: dao, Assigned: dao)

References

(Depends on 5 open bugs)

Details

(Keywords: meta)

This effort puts Firefox's Tabbed Browser component under the tree's TypeScript setup and checks it in CI. The component manages Firefox's tabs — opening and closing them, pairing each tab with the browser element that displays its content, moving them between windows, and the tab strip they appear in. At its core sits one large class, Tabbrowser, which every part of the browser UI calls into, and it is the one piece the setup cannot check on day one. The lint rules require any JSDoc comment to list every parameter, but most of the class's members had no comment at all, and nothing checked the types in the ones that did.

None of the machinery is new. For the address bar, Mark Banner built the tree-wide TypeScript linter that checks every component, the compiler settings, and the convention for declaring types a checker cannot otherwise see. This effort reuses all three. The Tabbrowser class is larger than anything the address bar effort put under the checker.

A checked contract catches defects that tests do not. This code fails quietly. Moving tabs between windows, inheriting a container and attributing an action to its origin produce wrong state or wrong data, no error anyone reports, and no test asserts on them. The checker turns a mismatch on one of those paths into a review-time error; without it, the mismatch is a field nobody notices is wrong.

Those failures stayed invisible because nothing verified the documented contract. Option bags listed properties no caller passes, a parameter documented as a number was handed a string, and annotations named types that never existed. A reader trusts each of those, and a reviewer has no way to check them.

The second gain reaches other components. Nothing could describe a tab, a tab group or a split view to a type checker, so every component that touches them either guessed or went unchecked. Writing that contract down once unblocked work in Session Restore immediately, and three partial copies elsewhere in the tree now have one declaration to converge on.

What type checking has caught

This is a running list, not a comprehensive audit.

  • Bug 2065803 - pinMultiSelectedTabs hands pinTab a bare metrics context, so pinned_tabs.pin records source "unknown"
  • Bug 2066310 - Don't expose TaskbarTab registry entry to tabbedbrowser
  • Bug 2069198 - Give Glean event extras their declared types in the generated TypeScript declarations
  • Bug 2076547 - Tab group preview opens after keyboard focus has moved off the group label
  • Bug 2080406 - Pinned tab dragged in the expanded vertical tab strip isn't re-centered under the cursor
  • Bug 2098603 - Loading about:blank into a new browser is treated like loading an initial page such as about:newtab
  • Several suspects turned out to be documentation errors, not code. One closing method was documented as taking two flags while callers passed six more straight through it. The checker raises the question, and the answer is often that the comment was wrong.

Progress at a glance

Phase Goal Bug Status
0 Move the class into a system module bug 2049770 DONE
1 Repair a type definition a stray tag had truncated bug 2065656 DONE
2 Land the project file green and wire the CI check bug 2065668 DONE
3 Expose two modules the class hung off its instance bug 2065759 DONE
4 Make the annotations' type names resolve, and document the option bags bug 2065769 DONE
5 Declare the tab strip's custom elements bug 2065814 DONE
6 Fix the annotations that disagree with the code bug 2065813 DONE
7 Hold the tab strip's shared preferences on the class bug 2069200 DONE
8 Take the class to zero and put it under the CI check bug 2069199 DONE
9 Give the tab group, its label and the split view the members the class reads off them bug 2068697 DONE
10 Convert the tab group and split view elements to modules bug 2066073 DONE
11 Convert the tab strip element to a module and type it from its class bug 2070849 DONE
12 Convert the tab element the same way, retiring the component's last stand-in declaration bug 2071355 DONE
13 Point Search and Tab Notes at the tab's class instead of their own partial copies bug 2075018 DONE
14 Move the class's remaining window-independent members to statics bug 2075448 DONE
15 Relocate MozTabbrowserTab's semi-private, externally-set members bug 2075016 DONE
16 Check the tab strip's window modules and the remaining sibling modules bug 2076596 DONE
17 Declare a BrowserWindow type for code that reads globals off a window value bug 2081848 DONE
18 Import the session-restore and thumbnail modules where tab code reads them off a window bug 2082765 DONE
19 Import the system modules the tab strip's window modules use as globals bug 2082766 DONE
20a Convert the tab note menu script to a module bug 2080275 DONE
20b Convert the split view footer script to a module bug 2080288 DONE
20c Convert the tab group menu script to a module bug 2080287 DONE
20d Convert the tab drag-and-drop script to a module bug 2080286 DONE
20e Load converted sub scripts from 20a-d as actual modules bug 2080403 DONE
20f Convert the tab bar visibility script to a module bug 2080285 DONE
20g Convert the status panel script to a module bug 2080284 DONE
20h Convert the all tabs menu script to a module bug 2080283 DONE
20i Convert the tab context menu script to a module bug 2080282 DONE
20j Convert the Ctrl+Tab switcher script to a module bug 2080280 DONE
20k Convert the site-specific zoom script to a module bug 2080279 IN REVIEW
21 Resolve tab drag-and-drop type errors Not filed yet PLANNED
22 Survey properties still attached to elements after step 15, and type them where that pays off Not filed yet PLANNED
22a Move the browser properties that tab lookups expose out of expandos bug 2098549 IN REVIEW
23 Stop defining the new tab preloading module on the browser window, importing it in the tests that use it bug 2082780 PLANNED
24 Type the options that the URL-loading helpers take when system modules call them directly Not filed yet PLANNED

References

Depends on: 2065656
Alias: tabbrowser-ts
Duplicate of this bug: 2004963
Depends on: 2065759
Depends on: 2065769
Depends on: 2065813
Depends on: 2065814
Depends on: 2066073
Depends on: 2066310
Depends on: 2068697
Depends on: 2069199
Depends on: 2069200
Depends on: 2070849
Depends on: 2071355
Depends on: 2069198
Assignee: nobody → dao+bmo
Status: NEW → ASSIGNED
Depends on: 2075016
Depends on: 2075018
Blocks: 2075016
No longer depends on: 2075016
Depends on: 2075448
No longer blocks: 2075016
Depends on: 2075016
Depends on: 2076547
Depends on: 2076596
See Also: → 2065803
Depends on: 2065803
See Also: 2065803 →
Depends on: 2080275
Depends on: 2080279
Depends on: 2080280
Depends on: 2080282
Depends on: 2080283
Depends on: 2080284
Depends on: 2080285
Depends on: 2080286
Depends on: 2080287
Depends on: 2080288
Depends on: 2080403
Depends on: 2081848
Depends on: 2082765
Depends on: 2082766
Depends on: 2082780
Depends on: 2084412
Depends on: 2090000
Depends on: 2098608
Depends on: 2098549
You need to log in before you can comment on or make changes to this bug.