Skip to content

fix(web): bound OKLCH gamut mapping - #6485

Open
Lucenx9 wants to merge 1 commit into
pingdotgg:mainfrom
Lucenx9:agent/fix-oklch-gamut-mapping
Open

fix(web): bound OKLCH gamut mapping#6485
Lucenx9 wants to merge 1 commit into
pingdotgg:mainfrom
Lucenx9:agent/fix-oklch-gamut-mapping

Conversation

@Lucenx9

@Lucenx9 Lucenx9 commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

What Changed

Theme color gamut mapping now calculates its binary-search iteration count by subtracting base-2 logarithms instead of dividing chroma by the target resolution. This keeps the count finite for every finite OKLCH chroma accepted by the theme parser.

A focused regression imports a theme containing oklch(0.5 1e303 0), verifies that parsing preserves the magnitude, and checks the mapped sRGB result.

Verified with the 31-test themePalette suite, the web package typecheck, and focused lint and formatting checks.

Why

The previous chroma / resolution calculation could overflow to Infinity even when chroma itself was finite. That made the loop bound infinite and could hang the web or desktop renderer when an imported theme with extreme chroma was converted for the color editor.

The logarithm subtraction is algebraically equivalent for ordinary colors, preserves the existing chroma resolution, and avoids the overflowing intermediate value.

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • UI screenshots are not applicable
  • UI motion video is not applicable

Made with GPT-5.6 using the Codex harness in T3 Code.

Note

Fix overflow in mapThemeOklchToSrgbGamut for extremely large OKLCH chroma values

The bisection step count in themePalette.ts previously computed log2(C / chromaResolution), which overflows to Infinity when C is extremely large (e.g. 1e303). This is fixed by computing log2(C) - log2(chromaResolution) instead, which avoids intermediate overflow while preserving the same effective resolution.

Macroscope summarized 335b00b.


Note

Low Risk
Localized numeric fix in theme color conversion with a targeted test; no auth, storage, or API surface changes.

Overview
Fixes a hang when imported themes contain OKLCH colors with astronomically large but finite chroma (e.g. oklch(0.5 1e303 0)).

mapThemeOklchToSrgbGamut now computes the bisection iteration count as log2(C) - log2(chromaResolution) instead of log2(C / chromaResolution). That avoids intermediate overflow to Infinity (which made the loop unbounded) while keeping the same effective resolution for normal colors.

A regression test parses extreme chroma through parseThemeFile, asserts the canonical OKLCH string is preserved, and checks themeColorToHex returns #b5005e.

Reviewed by Cursor Bugbot for commit 335b00b. Bugbot is set up for automated code reviews on this repo. Configure here.

@coderabbitai

coderabbitai Bot commented Aug 13, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 879bba2b-731f-4235-971b-2d74b4930d61

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added vouch:unvouched PR author is not yet trusted in the VOUCHED list. size:XS 0-9 changed lines (additions + deletions). labels Aug 13, 2026
@Lucenx9
Lucenx9 marked this pull request as ready for review August 13, 2026 15:43
@macroscopeapp

macroscopeapp Bot commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Approved 335b00b

This is a straightforward numerical bug fix that prevents overflow when processing extreme OKLCH chroma values. The change uses an equivalent mathematical formulation (log(a/b) = log(a) - log(b)) that avoids division overflow, with a test confirming the fix.

You can customize Macroscope's approvability policy. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XS 0-9 changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant