Repository navigation
icons: Apply the decoration border color the icon lookup finds - #61
Conversation
d4167ef to
44e81f9
Compare
506f8b3 to
ee89e91
Compare
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
The new async then(...) write can race with subsequent renderTo() calls and overwrite a newer border color unless guarded (e.g., with a per-element request id).
Review effort: Lite
Findings: 1
Open (1)
What changed in this PR
Fixes icon decoration border rendering when the decoration/background contrast is low by applying the asynchronously computed dominant icon color directly to the decoration element instead of mutating a no-longer-used style object.
Changes:
- Apply
borderColordirectly on the decoration element inside the_findIconColor()promise resolution. - Continue the jQuery-to-DOM refactor in
renderTo()by usingclassList,childreniteration, and directstyleassignments.
| File | Description |
|---|---|
| js/icons/multi-state-sprites-icon.js | Applies async-resolved border color directly to the decoration element during render. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
The callback wrote into a style object that had already been applied, so in the low-contrast branch the border color never reached the element. The canvas work behind that lookup was already being done; only its result was dropped. The element outlives a render, so each one stamps it with a token and a lookup resolving after a newer render is ignored.
ee89e91 to
c808d95
Compare
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The change directly fixes the described async style-application bug and includes a verified guard against stale promise resolutions overwriting newer renders.
Review effort: Lite
Findings: None

Stacked on #60, which kept this behaviour as it was so that it could be fixed on its own.
The bug
An icon decoration picks a border colour to separate it from what is behind it. When the decoration contrasts well with the background it borrows the background colour; otherwise it asks
_findIconColor()for the icon's dominant colour, which is resolved asynchronously off a canvas.Before #60 the styles were collected into an object and applied at the end:
.css(css)runs synchronously; the callback runs later. It wrote into an object nobody looked at again, so in that branch the border colour never reached the element. #60 kept that as-is, with a comment. This assigns to the element instead.Shown on a device
The branch is not reachable on the port list, where the contrast test always goes the other way, so I forced it with a temporary build and loaded the same 448-port list. Same page, same icons, only this commit differing:
border-color(none)on all 236rgb(98, 171, 234)on all 236So the lookup resolves, and the value now lands. The temporary build was only for the test; nothing of it is in this PR.
Cost
None.
_findIconColor()was already called and already did its canvas work in this branch — decode the sprite sheet, sample every pixel, count colours. Only the answer was thrown away.Worth knowing
_findIconColor()resolves fromimg.onloadand has noonerror, so if the sprite ever fails to load the promise never settles. That is unchanged here, but it now means a missing border rather than a discarded value.