Skip to content

Fix canonicalize crash with plugin component values#20052

Merged
RobinMalfait merged 5 commits into
tailwindlabs:mainfrom
yudin-s:canonicalize-plugin-values
May 14, 2026
Merged

Fix canonicalize crash with plugin component values#20052
RobinMalfait merged 5 commits into
tailwindlabs:mainfrom
yudin-s:canonicalize-plugin-values

Conversation

@yudin-s

@yudin-s yudin-s commented May 14, 2026

Copy link
Copy Markdown
Contributor

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 configured values map. 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.ts
  • source ~/.nvm/nvm.sh && nvm use 22.14.0 && pnpm prettier --check packages/tailwindcss/src/canonicalize-candidates.ts packages/tailwindcss/src/canonicalize-candidates.test.ts

@yudin-s yudin-s requested a review from a team as a code owner May 14, 2026 08:34
@coderabbitai

coderabbitai Bot commented May 14, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: e45c888b-a99a-4e46-a7ad-6f918e74ef82

📥 Commits

Reviewing files that changed from the base of the PR and between e2870eb and 2b68bcc.

📒 Files selected for processing (3)
  • CHANGELOG.md
  • packages/tailwindcss/src/canonicalize-candidates.test.ts
  • packages/tailwindcss/src/canonicalize-candidates.ts
✅ Files skipped from review due to trivial changes (1)
  • CHANGELOG.md

Walkthrough

This 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)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main fix: preventing crashes when canonicalize processes plugin component values during the collapse pass.
Description check ✅ Passed The description is well-related to the changeset, explaining the root cause, the fix, and providing comprehensive test instructions aligned with the code changes.
Linked Issues check ✅ Passed The PR fully addresses issue #20051 by wrapping the property lookup in a try/catch block to prevent crashes when plugins throw during speculative canonicalization probes, and includes a regression test.
Out of Scope Changes check ✅ Passed All changes are directly scoped to the linked issue: test file additions, try/catch wrapper in canonicalization logic, and changelog entry documenting the fix.

✏️ 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

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint skipped: no ESLint configuration detected in root package.json. To enable, add eslint to devDependencies.

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.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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 and usage tips.

@greptile-apps

greptile-apps Bot commented May 14, 2026

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5

Safe 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 createUtilitySignatureCache. The catch block returns an empty lookup, which is the correct no-op result for a speculative probe that fails. The regression test directly reproduces the reported crash and confirms the candidates are preserved. No existing behavior for non-throwing plugins is affected.

No files require special attention.

Reviews (2): Last reviewed commit: "Merge branch 'main' into canonicalize-pl..." | Re-trigger Greptile

@RobinMalfait RobinMalfait enabled auto-merge (squash) May 14, 2026 09:54

@RobinMalfait RobinMalfait left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@RobinMalfait RobinMalfait merged commit a2b89a7 into tailwindlabs:main May 14, 2026
8 checks passed
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.

canonicalize calls plugin matchComponents callbacks with undefined values, crashing plugins that use the value (e.g. Phoenix heroicons)

2 participants