Repository navigation
fix(sourcelist): take a middle click without a ui.Handle per row (B2) - #9
Conversation
OnMiddleClick bound a ui.Handle made with ui.Local on each row. ui.Local belongs to the element, so a row that stopped being built (scrolled out of view, or its section or parent closed) lost it, and its next mount made a new Handle. Each new Handle's first Bind appends a registration to the window's refs, which nothing removes until the window closes and which applyFocusRequests walks every build pass: memory and per-frame work grew without a limit for the life of the window. The list now keeps the middle press in its own fields (the row's key), and the row's ObserveInput, which MyGo runs before the pressed row's handler gets the release, records that the release is over that row by MyGo's own hit test. The handler fires OnMiddleClick only for a release that is not canceled, whose key matches and that came over the row, and clears the press on every release. Using the hit test instead of the row's box also stops a release over a section header pinned above the row from clicking the row under it, which the old box check allowed. The new test scrolls a 2000-note list far down and back and closes and opens both sections, five times each, then checks that middle clicks fire exactly once over their own row, and not over the next row, outside the list, over the pinned header or when canceled. Refs: #7 (review) (B2)
A test cannot see MyGo's per-window handle registrations, so the guard for finding B2 reads the kit's source: TestKitMakesNoHandleInAView parses every kit file, tests included, and fails on a ui.Handle (or Ref) made in a view (a function or closure that takes the build's *ui.Context or a ui.Element, and every closure inside one) as a literal, new, make or a variable, and on a ui.Local that keeps one, by its type argument or its init's result. TestHandleFixtures proves the check fails on the old SourceList code and its variants and passes handles kept in structs. AGENTS.md gains the rule under MyGo's rules: never create a ui.Handle in a view or with ui.Local; keep handles in structs. The design docs say the same, and .memory/corrections.jsonl records the correction. Refs: #7 (review) (B2)
frostyard-machines
left a comment
There was a problem hiding this comment.
Review of head 1de9b192ba4175821621339f314ec290c48a5687 (base 23f37ce): no findings. B2 from #7 is fixed.
- The fix:
sourcelist.gokeeps the middle press inmiddle,middleSetandmiddleOver, and no row makes aui.Handle. I checked the order of events in MyGo v0.9.0.pointerUpcallsobservePointeron the hit chain under the pointer first (ui/input.go:716), and thendelivers the release to the pressed element (:750). So the row'sObserveInputsees a release over that row before itsHandleInputdecides. - A row that goes away while the button is down:
endPressgives the pressed element's handler a canceled release (ui/input.go:629-636), so the stored press clears. - The pinned header: the hit test puts it above the row, so a release there does not count as a click on the row. This is more correct than the old box check.
- The guards:
TestKitMakesNoHandleInAViewparses the kit's views andui.Localcalls, andTestHandleFixturesholds 10 fixtures.TestSourceListMiddleClickSurvivesRowsBuiltAgainscrolls the list and closes and opens its sections 5 times. Then it checks the click itself: a release over the same row fires once, and the next row, outside the list, a canceled press and the pinned header fire none.- The new
AGENTS.mdrule includesHandlein the MyGo bump check, and there is 1 corrections line withpromoted_toset to the guard.
- API:
api.txtdoes not change. - Risk tier: the section names
internal/repocheck/**(L2) and gives the reason.
Checks:
- Local
GOTOOLCHAIN=local make ci BASE=origin/mainwith go1.27.4 passes at this head. - Revert test: with
sourcelist.gofrommain,TestKitMakesNoHandleInAViewfails atsourcelist.go:623(both theui.Localand theHandleliteral), andTestSourceListMiddleClickSurvivesRowsBuiltAgainfails at the pinned-header release. With this head, both pass. - GitHub: the 7
cross-buildjobs are green, andverifyis still running.
The next step is the independent cross-review. The label waits for a green verify.
frostyard-machines
left a comment
There was a problem hiding this comment.
Cross-review at head 1de9b192ba4175821621339f314ec290c48a5687 (base 23f37ce2a71513b098d3ea747dd382dd785641a1). Reviewer: openai/gpt-6.1-sol, which reviewed all 8 changed paths. Result: Ready, Blocking: none.
It confirmed these points about the middle-click logic:
- MyGo shows the release to the elements under the pointer before it gives the release to the row that holds the press.
- A release over another row, outside the list or over a pinned header does not count as a click.
- A canceled release clears the state, also when MyGo stops building the pressed row.
- Each list has its own state.
- A new middle press resets the state of a release that was lost.
- The state clears before
OnMiddleClickruns. - MyGo starts value drags only for the primary button.
- No row makes a handle.
2 low findings, not blocking. A follow-up can take them:
internal/repocheck/handles_test.go:70: the guard checks the syntax only. It does not see aui.Handleinside a named struct thatui.Localinitializes as a zero value (for examplerowState{}with a fieldh ui.Handle, and thenBind(&state.h)). Fix: add a fixture for this case, and resolve such struct types, or say in the guard's comment that it checks direct syntax only.AGENTS.md:97: "one per item in a map pruned as items go" is not enough when items change all the time. Pruning the map removes only the kit's reference. The window keeps each registration until it closes, so items that are removed and added again still add registrations. Fix: say that pruning does not release the window's registration, and recommend stable handle identities with a bound, not a handle for each item of a set that changes without limit. (This option came from my B2 comment, so the correction is mine.)
Checks: the head, the base and CI have not changed since the review. CI is green (verify and the 7 cross-build jobs). The revert test is in my earlier review: both guards fail without the fix.
frostyard/frostui#9 makes no handle per row: a middle click counts when the release lands on the same row by MyGo's own hit test. The pin holds until frostui v0.3.0. Files' middle click still opens a file in a new tab, and a release over another row, or on a folder, opens nothing.
The tag is the merge of frostyard/frostui#9: the source list's middle click is the same as at 1de9b19. Files has one untitled section, so a release over a pinned section header cannot happen there.
Summary
Fixes B2, the Blocking finding that #7 merged with:
SourceList's middle click leaked a MyGo handle registration each time a row was built again.OnMiddleClickset, each row made aui.Handlewithui.Localand bound it.ui.Localbelongs to the element, so a row that scrolls out of view, or whose section or parent closes, loses it, and its next mount makes a new handle. Each new handle's firstBindappends arefStateto the window'srt.refs. MyGo removes none until the window closes, andapplyFocusRequestswalks them all every build pass, so memory and per-frame work grew for the life of the window, even with no middle click. Frostnotes' Files pane setsOnMiddleClick.SourceList. The row'sObserveInputmarks a release that MyGo's own hit test puts over that row; it sees the release before the pressed row's handler does. The handler callsOnMiddleClickonly when the release isn't canceled, the key matches, and the release came over the row, and it clears the press on every release. Because it uses the hit test, a release over a section header pinned above the row no longer counts as a click on the row; the old box check counted it.TestKitMakesNoHandleInAViewininternal/repocheckparses the kit and fails when a source file makes aui.Handlewithui.Localor in a view.TestHandleFixturesholds 10 fixtures that fail and pass.TestSourceListMiddleClickSurvivesRowsBuiltAgainscrolls far and back and closes and reopens a section several times, then checks that a middle click fires once, and that a release outside the row or a canceled one doesn't.ui.Handlein a view or withui.Local..memory/corrections.jsonl.sourcelist.gowas the only instance: grepping the kit forui.Local(andBind(found no other.The exported API is unchanged;
OnMiddleClick's doc now says what counts as a click.Risk tier
Level: L2, from
internal/repocheck/**(a new guard and its fixtures) and the template governance files it touches. The guard only adds a failing check.Risk tier: 3 — a
risk:highPR. It fixes an unbounded memory and per-frame-work growth in a shipped widget.Docs housekeeping
Verification
make verifygreen, andmake ci BASE=origin/maingreen on this head: lint, js/wasm tests, the race detector and all 7 cross-targets.sourcelist.go,TestKitMakesNoHandleInAViewfails atsourcelist.go:623, andTestSourceListMiddleClickSurvivesRowsBuiltAgainfails on the pinned-header release..memory/corrections.jsonlline added.Not covered: no test can see
rt.refs, so the leak itself is guarded by the source check rather than measured.