Avatar: getAvatarColor collides on anagrams; add color seed + palette subset
メンテナーはふだん 2 日以内に返信
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 52/100
- issue の種類
- 機能追加
- 明瞭さ
- おおむね明確
- 活発さ
- 静か
- 技術スタック
- react, typescript
調査の方向性
まず components/avatar/utils.tsx を読み、Avatar の自動カラーの処理経路を追跡します。任意のカラーシードとパレットのサブセットに関する API の決定を確認し、その後、ハッシュが順序の変更を区別しながらフォールバックの動作を維持することを検証します。自動カラーが安定した独立シードと制限されたパレットをサポートし、#650 で説明されている明示的なカラーに関する作業に影響を与えなければ完了です。
索引モデルが issue の本文から書いたものです。
説明
Summary
getAvatarColor picks an avatar color from a name using a char-code sum, which collides on anagrams and clusters on similar strings. There is also no way to seed the color independently of the display name, and no way to restrict the palette to a subset. Consumers with a specific color language end up re-implementing the whole function.
The hashing bug
components/avatar/utils.tsx:
export function getAvatarColor(str: string): AVATAR_COLORS {
const hash = str.split('').reduce((acc, char) => acc + char.charCodeAt(0), 0);
const index = hash % COLORS.length;
return COLORS[index];
}
Summing char codes is order-insensitive, so any anagram maps to the same color — "Ravi" and "Vira", "Amy Lee" and "Ely Mae" collide. Names that differ by one adjacent-letter swap also collide, and sequences like "User 1" / "User 2" / "User 3" land on adjacent (often visually close) palette entries instead of spreading out.
A small change fixes the distribution — a polynomial (order-sensitive) hash:
let hash = 0;
for (let i = 0; i < str.length; i++) {
hash = (hash * 31 + str.charCodeAt(i)) | 0;
}
const index = Math.abs(hash) % COLORS.length;
Two API gaps
1. No color seed. The color is derived from the string passed in — which is the display name — so a rename changes a person's color, and two people with the same name always share one. A separate, stable seed (e.g. an id) would keep colors stable across renames and distinct for namesakes. Suggest an optional colorSeed/seed prop on Avatar (falling back to the name today).
2. No palette subset. COLORS is a fixed 13-entry list including warm tones (orange, crimson, gold) and neutral. A product with a cooler or brand-restricted identity language can't say "only pick from these." Suggest letting getAvatarColor (and Avatar's auto-color) accept an optional palette subset.
Relationship to #650
#650 (item 3) proposes propagating an explicit color prop to Avatar. This issue is about the automatic color path — hash quality and seeding — which is orthogonal: even with an explicit-color prop, the auto-assigned fallback should distribute well and stay stable.
Willing to contribute
Happy to open a PR — the hash change alone is a one-liner, and the seed/palette props are additive.
- 主要言語
- TypeScript
- スター
- 69
- フォーク
- 13
- 平均マージ
- 3日 15時間
- マージ済み PR(30日)
- 24
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
raystack/apsara のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
メンテナーはふだん 2 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
メンテナーはふだん 2 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
メンテナーはふだん 2 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
メンテナーはふだん 2 日以内に返信
-
DataView: don't offer select/multiselect filters with empty filterOptions対応中かも @rohanchkrabrty が 5 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
メンテナーはふだん 2 日以内に返信
raystack/apsara の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
cameri/nostream#811 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
bug p3 triaged
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
メンテナーはふだん 1 日以内に返信
-
bug javascript P2-medium python release:v3.1
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
adrirubio/claude-deck#546 ·
メンテナーはふだん 1 日以内に返信
-
area: desktop area: website priority: P2 type: feature
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
appandflow/stim#3411 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
needs triage
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
rjsf-team/react-jsonschema-form#5485 ·
メンテナーはふだん 2 日以内に返信