Guard against infinitely recursive theme key lookup #1332
Merged
+56
−4
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When constructing the design system we compute color swatches for all classes. This process involves:
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