Skip to content

Guard against infinitely recursive theme key lookup #1332

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 23, 2025

Conversation

thecrypticace
Copy link
Contributor

When constructing the design system we compute color swatches for all classes. This process involves:

  • Computing the CSS for a utility
  • Inlining any values from the theme, recursively
  • Scanning for CSS color syntax that we can compute a swatch for

We guard against directly self-recursive replacements because of how the replacement itself functions. However, if you wrapped the variable in something then we would effectively recurse into the expression and try to replace the variable again. This caused the expansion to then be wrapped and then try again resulting in an infinite loop.

This fixes it by keeping track of seen variables during a replacement and if we've seen it and the expansion contains a var(…) anywhere we'll only replace it once. This logic is not perfect as the thing that matters is that the replacement itself results in a recursion but this is good enough for now.

Fixes #1329

@thecrypticace thecrypticace force-pushed the fix/guard-againstrecursive-theme-key-lookup branch from 91efadb to ed6a566 Compare April 23, 2025 15:14
@thecrypticace thecrypticace merged commit 5c82545 into main Apr 23, 2025
12 checks passed
@thecrypticace thecrypticace deleted the fix/guard-againstrecursive-theme-key-lookup branch April 23, 2025 15:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

IntelliSense silently fails when v4 theme color variable references itself using rgb channels
2 participants