`@effect/ui-native` (Effect-TS/ui): `NativeHost` color cache checks `out === undefined`, causing repeated cache misses when `device.color` returns `undefined`

オープン
#11,081 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@effect-bot がすでに取り組んでいます。

2026年11月29日 から。

  • #645 @effect-bot による — オープン

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
25/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
停滞
技術スタック
react-native, typescript
領域
mobile

調査の方向性

Read packages/ui-native/src/NativeHost.ts around lines 205–214 and compare the cache lookup with the reproduction test linked in the issue. Run the reproduction’s pnpm test to confirm repeated calls when device.color returns undefined. Done when repeated uses of the same color invoke device.color once; an open linked pull request already addresses this issue.

索引モデルが issue の本文から書いたものです。

説明

partially generated with help of my ai friend - neon 4.4

Hi effect team,
I was trying out this package and wanted to report some bugs encountered while porting a library to effect native

What version of Effect is running?
  • effect: 4.1.7
  • @effect/ui & @effect/ui-native: Effect-TS/ui main at 77391ee50ae3d3175d670facbf675e9a819ba6a6
  • react-native: 0.88.1
What steps can reproduce the bug?
  1. Clone the minimal reproduction repository:
    git clone https://github.com/cliffordfajardo/effectui-native-error-reproductions.git
    cd effectui-native-error-reproductions
    pnpm install
    pnpm test
    
  2. Create a NativeHost via NativeHost.make({ ui, rootTag: 1, device }) where device.color returns undefined for an unparsed string color (matching React Native's processColor behavior for unsupported/invalid color strings), and apply that same color string to multiple views:
const unparsed = "oklch(0.6204 0.195 253.83)"

for (let i = 0; i < 3; i++) {
  const node = host.createElement("view")
  host.setProp(node, "backgroundColor", unparsed)
  host.insertBefore(root, node, undefined)
}
host.commit?.()
  1. Observe how many times device.color is invoked (see 03-nativehost-color-cache-misses-on-undefined/repro.test.ts).
What is the expected behavior?

NativeHost's internal colors map should cache the result of device.color(value) on the first lookup even when the result is undefined, so subsequent nodes using the same string color hit the cache (device.color called 1 time, matching the behavior for resolved colors).

What do you see instead?

packages/ui-native/src/NativeHost.ts:205-214 writes undefined into the cache map, but checks out === undefined to detect a cache miss:

const colors = new Map<string, unknown>()
const color = (value: unknown) => {
  if (typeof value !== "string") return processColor(value)
  let out = colors.get(value)
  if (out === undefined) {
    if (colors.size > 255) colors.clear()
    colors.set(value, out = processColor(value))
  }
  return out
}

Because colors.get(value) returns undefined both when the key is absent and when processColor(value) returned undefined, every prop assignment with that string misses the cache and re-runs processColor(value) (3 calls instead of 1 in the repro).

Additional information

Checking if (!colors.has(value)) (or storing a sentinel for undefined) ensures unparsed string colors are cached consistently alongside parsed colors and avoids redundant processColor calls across re-renders/lists.

主要言語
TypeScript
スター
16.7k
フォーク
808
平均マージ
21時間 22分
マージ済み PR(30日)
486

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

Effect-TS/effect のほかの issue

Effect-TS/effect の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。