Fix canonicalize crash with plugin component values#20052
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
✅ Files skipped from review due to trivial changes (1)
WalkthroughThis PR wraps the AST compilation/canonicalization and declaration-walking used to build utility property/value lookups in createUtilityPropertiesCache with a try/catch to ignore errors during collapse, adds a regression test that registers a plugin whose matchComponents throws to ensure canonicalizeCandidates(collapse: true) does not crash, and updates CHANGELOG.md with a Fixed entry. 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint skipped: no ESLint configuration detected in root package.json. To enable, add Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. 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. Comment |
Confidence Score: 5/5Safe to merge — the change is a targeted try/catch around an already-isolated speculative lookup, backed by a focused regression test. The fix is minimal and directly parallels the existing error-handling pattern in No files require special attention. Reviews (2): Last reviewed commit: "Merge branch 'main' into canonicalize-pl..." | Re-trigger Greptile |
This way all callers benefit from it
Summary
Fixes #20051.
The collapse canonicalization pass speculatively checks compatible functional utility roots. When one of those roots comes from a plugin registered with
matchComponents/matchUtilities, the speculative candidate can call the plugin callback with an arbitrary value that is not present in the configuredvaluesmap. Plugins such as the Phoenix Heroicons helper expect the mapped value shape and can throw while canonicalize is only probing possible replacements.This change skips speculative replacement utilities whose property lookup throws, matching the best-effort behavior already used by utility signature generation. The original candidates are preserved instead of crashing canonicalization.
Test plan
source ~/.nvm/nvm.sh && nvm use 22.14.0 && pnpm vitest run packages/tailwindcss/src/canonicalize-candidates.test.ts -t "does not crash when plugin matchComponents rejects speculative values during collapse"source ~/.nvm/nvm.sh && nvm use 22.14.0 && pnpm vitest run packages/tailwindcss/src/canonicalize-candidates.test.tssource ~/.nvm/nvm.sh && nvm use 22.14.0 && pnpm prettier --check packages/tailwindcss/src/canonicalize-candidates.ts packages/tailwindcss/src/canonicalize-candidates.test.ts