Skip to content

fix(design-system): derive a valid color for every icon name - #3585

Merged
JammingBen merged 1 commit into
mainfrom
fix/hashed-color-padding
Oct 8, 2026
Merged

JammingBen merged 1 commit into
mainfrom
fix/hashed-color-padding

Conversation

@dschmidt

@dschmidt dschmidt commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Description

oc-application-icon without a colorPrimary derives a color from the icon name. For a number of icon names that throws while rendering, which takes the surrounding component with it. I ran into it with a dashboard of the external sites app that stayed blank because one site used the icon key without a color.

Two causes in helpers/colors.ts:

  • generateHashedColorForString did not pad its hex value. A name whose hash has leading zeros gives fewer than six digits (key gives #19E5F), hexToRgb returns null for it, and the contrast calculation throws on null.
  • setDesiredContrastRatio recurses until the ratio is within reach. It shades by one percent per step, which does not change a small channel value after rounding and cannot raise a channel above 255. For a dark color it should brighten, no channel moves, and it recurses until the stack overflows (bell gives #2E1503).

Of the 1681 icon names in the icon set, 155 hit the first problem and 40 the second.

The fix:

  • pads the hashed color to six digits,
  • makes setDesiredContrastRatio return the color as it is once a shading step no longer changes it.

Colors that worked before are unchanged (book is still #2e71ff, grid #308b46). With the fix all 1681 names give a valid color.

Related Issue

None.

How Has This Been Tested?

  • test environment: unit tests of the design system, and a script that runs the color derivation of oc-application-icon over every icon name in packages/design-system/src/assets/icons
  • test case 1: before the fix, 155 names throw on the short hex value and 40 overflow the stack; after it, all 1681 give a valid six digit color
  • test case 2: unit tests for the padding (key, upload, at) and for the two ways the contrast adjustment gets stuck (no channel can move, the only moving channel reaches 255)
  • not tested in a browser with this branch; the crash itself I saw in a browser on the external sites dashboard

Types of changes

  • Bugfix
  • Enhancement (a change that doesn't break existing code or deployments)
  • Breaking change (a modification that affects current functionality)
  • Technical debt (addressing code that needs refactoring or improvements)
  • Tests (adding or improving tests)
  • Documentation (updates or additions to documentation)
  • Maintenance (like dependency updates or tooling adjustments)

dschmidt added a commit to opencloud-eu/web-extensions that referenced this pull request Oct 7, 2026
Without a color, the application icon of the host derives one from the icon
name. Before opencloud-eu/web#3585 that throws while rendering for about one
icon name in nine, which takes the whole dashboard or app menu with it.

Until the app can rely on that fix it derives the color itself, the same way
the fixed host does, and passes it for dashboard tiles and app menu items.
generateHashedColorForString did not pad its hex value, so a name whose
hash has leading zeros gave fewer than six digits, hexToRgb returned null
and the contrast calculation threw. setDesiredContrastRatio also recursed
forever for a dark color it cannot brighten in one percent steps.

Both break the application icon without a primary color, which derives one
from the icon name: of the 1681 names in the icon set, 155 hit the first
problem and 40 the second.

@JammingBen JammingBen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@JammingBen
JammingBen merged commit e402bea into main Oct 8, 2026
31 of 32 checks passed
@JammingBen
JammingBen deleted the fix/hashed-color-padding branch October 8, 2026 07:27
openclouders pushed a commit that referenced this pull request Oct 8, 2026
fix(design-system): derive a valid color for every icon name
@openclouders openclouders mentioned this pull request Oct 8, 2026
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants