You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Canonicalization: reuse dynamic utility lookups across candidate collapse groups - #20698
In canonicalizeCandidates, collapseGroup previously initialized a new dynamicUtilities map for each variant group being collapsed. For inputs containing multiple candidate groups, this caused redundant lookups across functional utility roots for identical candidates.
This change caches the dynamic utility lookups on designSystem.storage keyed by signatureOptions, matching the pattern used by UTILITY_PROPERTIES_KEY and STATIC_UTILITIES_KEY.
Test plan
Ran the test suite via pnpm exec vitest run --project tailwindcss packages/tailwindcss/src/canonicalize-candidates.test.ts (1,898 passed).
Added a test case verifying that candidate collapsing across multiple variant groups produces identical results while reusing lookups.
Verified code style via pnpm prettier --check packages/tailwindcss/src/canonicalize-candidates.ts packages/tailwindcss/src/canonicalize-candidates.test.ts.
It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.
No actionable comments were generated in the recent review.
Walkthrough
The design system now caches dynamic utility matches by signature options and candidate. During collapsing, the code uses those matches, generated by checking other functional roots and recording relevant property/value matches. A regression test checks that margin candidates collapse across base, hover, and focus variants, and that later collapse work reuses utility-key lookups.
Merge Risk: Minimal · previous review 4f6bf
This change reuses dynamic utility lookups when candidates are collapsed, which improves canonicalization performance. No concrete merge-blocking risk was identified.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title names the main change: dynamic utility lookups are reused across candidate collapse groups in canonicalization. The raw summary confirms that the lookup moved to DesignSystem.storage and col…
Description check
The description states the problem (collapseGroup rebuilding dynamicUtilities per variant group), the fix (caching lookups on designSystem.storage keyed by signatureOptions), and a test plan. These ma…
Linked Issues check
Issue #20634 asks that dynamic-utility alternatives be reused across collapse groups, scoped to the design system, SignatureOptions, and candidate string. At the reviewed head (4f6bfe3), canonicalize-…
Out of Scope Changes check
The whole-PR change set, per the supplied summary, touches canonicalize-candidates.ts, canonicalize-candidates.test.ts, and a changelog entry. The source change moves the dynamic-utilities factory int…
Full details: Title check
Explanation
The title names the main change: dynamic utility lookups are reused across candidate collapse groups in canonicalization. The raw summary confirms that the lookup moved to DesignSystem.storage and collapseGroup reads the cached lookup. The title is 80 characters, which is long, but it stays specific and accurate.
Full details: Description check
Explanation
The description states the problem (collapseGroup rebuilding dynamicUtilities per variant group), the fix (caching lookups on designSystem.storage keyed by signatureOptions), and a test plan. These match the changes in canonicalize-candidates.ts and its test file.
Full details: Linked Issues check
Explanation
Issue #20634 asks that dynamic-utility alternatives be reused across collapse groups, scoped to the design system, SignatureOptions, and candidate string. At the reviewed head (4f6bfe3), canonicalize-candidates.ts declares DYNAMIC_UTILITIES_KEY in DesignSystem.storage as a DefaultMap keyed by SignatureOptions and then by candidate. prepareDesignSystemStorage initializes it with createDynamicUtilitiesCache(designSystem). collapseGroup reads it once per signature group through designSystem.storage[DYNAMIC_UTILITIES_KEY].get(signatureOptions). The cache lives on the design-system object, so it is not process-global. The change does not alter the property intersection, linked-candidate, combination, or signature-equivalence logic. The added test in canonicalize-candidates.test.ts covers reuse across variant groups. The issue's persistent-editor, reload, and autofix validation notes are validation recommendations, not coding requirements of this PR. Verification was limited to the head file read; the changed-blob diff was unavailable in this checkout, so the prior whole-PR diff result is carried forward and consistent with the current file content.
Full details: Out of Scope Changes check
Explanation
The whole-PR change set, per the supplied summary, touches canonicalize-candidates.ts, canonicalize-candidates.test.ts, and a changelog entry. The source change moves the dynamic-utilities factory into a storage-backed cache initialized in prepareDesignSystemStorage and read in collapseGroup. The test covers reuse of that cache. The changelog entry describes the same performance fix. The head file read shows no prefix-handling, stylesheet-invalidation, or process-global cache changes in the inspected sections. The full diff could not be read in this checkout, so unchanged regions outside the inspected sections rely on the supplied summary.
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
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.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
2038-2055: Trivial · Maintainability & Code Quality · Low value
The test checks output only. It does not check that lookups are reused.
The test name claims reuse of dynamic utility lookups. The assertion verifies only the collapsed result. A regression that stops caching would still pass.
Optionally, assert on the cache directly, for example by checking that designSystem.storage holds the dynamic cache entry for the signature options after the call. Alternatively, rename the test to describe the behavior it verifies.
Review info
Run configuration
Source mode: Auto
Repository: Unavailable
Branch: Unavailable
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: 93efce6d-8837-4fcb-80a6-5cdd6f4471ad
Commits
Reviewing files that changed from the base of the PR and between 1615f72 and 32275ac.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
Require the first collapse to exercise dynamic lookups.
The precomputed lookup can supply my-2 without dynamic enumeration. It also calls keys('functional'), so a positive count alone is not sufficient. Warm the precomputed lookup before starting the spy, then require a positive count.
Suggested fix
- using keysSpy = vi.spyOn(designSystem.utilities, 'keys')-
let options: CanonicalizeOptions = {
collapse: true,
logicalToPhysical: true,
rem: 16,
}
+ // Warm the precomputed utility lookup without collapsing a group.+ designSystem.canonicalizeCandidates(['mt-2'], options)+ using keysSpy = vi.spyOn(designSystem.utilities, 'keys')+
@@
let functionalKeysCalls = keysSpy.mock.calls.filter((args) => args[0] === 'functional').length
+ expect(functionalKeysCalls).toBeGreaterThan(0)
expect(functionalKeysCalls).toBeLessThanOrEqual(3)
Review info
Run configuration
Source mode: Auto
Repository: Unavailable
Branch: Unavailable
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: a6cc4328-17c5-4454-ac4b-ef1473902e11
Commits
Reviewing files that changed from the base of the PR and between 32275ac and fb399a2.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Fixes #20634
Summary
In
canonicalizeCandidates,collapseGrouppreviously initialized a newdynamicUtilitiesmap for each variant group being collapsed. For inputs containing multiple candidate groups, this caused redundant lookups across functional utility roots for identical candidates.This change caches the dynamic utility lookups on
designSystem.storagekeyed bysignatureOptions, matching the pattern used byUTILITY_PROPERTIES_KEYandSTATIC_UTILITIES_KEY.Test plan
pnpm exec vitest run --project tailwindcss packages/tailwindcss/src/canonicalize-candidates.test.ts(1,898 passed).pnpm prettier --check packages/tailwindcss/src/canonicalize-candidates.ts packages/tailwindcss/src/canonicalize-candidates.test.ts.[ci-all]