Skip to content

Handle Live Component classes in Twig templates#20110

Open
officialasishkumar wants to merge 1 commit into
tailwindlabs:mainfrom
officialasishkumar:fix/issue-19458
Open

Handle Live Component classes in Twig templates#20110
officialasishkumar wants to merge 1 commit into
tailwindlabs:mainfrom
officialasishkumar:fix/issue-19458

Conversation

@officialasishkumar
Copy link
Copy Markdown

Summary

Fixes #19458.

  • Adds a Twig preprocessor for Symfony Live Component addClass(...) and removeClass(...) loading directives.
  • Keeps the generic extractor boundaries unchanged so this does not broaden class extraction in non-Twig files.

Test plan

  • CARGO_BUILD_JOBS=1 cargo test -p tailwindcss-oxide --lib twig -- --nocapture

@officialasishkumar officialasishkumar requested a review from a team as a code owner May 25, 2026 03:03
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 25, 2026

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: 51dbc796-8016-4600-a845-6bfb385b9d50

📥 Commits

Reviewing files that changed from the base of the PR and between 749c45e and 59764f5.

📒 Files selected for processing (4)
  • crates/oxide/src/extractor/mod.rs
  • crates/oxide/src/extractor/pre_processors/mod.rs
  • crates/oxide/src/extractor/pre_processors/twig.rs
  • crates/oxide/src/scanner/mod.rs

Walkthrough

This PR introduces a Twig pre-processor for the TailwindCSS scanner that handles Symfony Live Components directives. The implementation detects addClass() and removeClass() directives in Twig templates, neutralizes them by replacing the entire directive span with spaces, and handles escaped characters to preserve parenthesis balancing. The pre-processor is integrated into the module system and scanner pipeline, and a test verifies it correctly extracts class names from Twig template attributes.

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change—adding a Twig preprocessor to handle Live Component classes—and is directly related to the changeset.
Description check ✅ Passed The description is related to the changeset, explaining the addition of a Twig preprocessor for Symfony Live Component directives and references the linked issue.
Linked Issues check ✅ Passed The changes implement a Twig preprocessor that detects and processes addClass(...) and removeClass(...) directives, directly addressing the core requirement in issue #19458.
Out of Scope Changes check ✅ Passed All changes are focused on adding Twig preprocessor support and related test coverage, staying within the scope of handling Live Component classes in Twig templates.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 25, 2026

Confidence Score: 4/5

Safe to merge; the change is well-scoped to .twig files and does not alter any other extraction path.

The implementation is clean and tests cover the key scenarios including nested parens and multi-directive chains. One edge case: an unclosed addClass( causes the outer scan loop to exit early, silently abandoning any directives that follow it in the same file. Real templates are well-formed so this is unlikely to matter in practice, but the fix is trivial.

crates/oxide/src/extractor/pre_processors/twig.rs — the early-break path on unclosed parens is worth a second look.

Reviews (1): Last reviewed commit: "Handle Live Component classes in Twig te..." | Re-trigger Greptile

Comment on lines +44 to +46
if end >= content.len() {
break;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 An unclosed directive like addClass(foo (no closing )) causes the outer loop to break entirely, silently skipping every subsequent addClass/removeClass directive in the same file. In practice templates are well-formed, but a more resilient approach would be to advance cursor past the unmatched directive and continue rather than aborting.

Suggested change
if end >= content.len() {
break;
}
if end >= content.len() {
// Unclosed parenthesis — skip past the directive name and
// keep scanning so later directives are still processed.
cursor += directive_len;
continue;
}

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.

Source classes are not detected correctly when specified as data-loading="addClass(opacity-50)"

1 participant