Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve automatic var injection #12236

Merged
merged 4 commits into from Oct 24, 2023
Merged

Improve automatic var injection #12236

merged 4 commits into from Oct 24, 2023

Conversation

RobinMalfait
Copy link
Contributor

This PR improves the automatic var injection behaviour.

When using arbitrary properties such as:

<div class="[timeline-scope:--foo]"></div>

Then the compiled CSS will be:

.\[timeline-scope\:--foo\]{
  timeline-scope: var(--foo)
}

However, the timeline-scope property accepts a <dashed-ident> data type, which means that the value should stay as --foo, and not var(--foo).

This PR has an exceptions list for these properties, and won't wrap the variable with var() for properties that accept <dashed-ident>.

More info:

Fixes: #12205

@RobinMalfait
Copy link
Contributor Author

@thecrypticace what do you think about this solution?

This only solves it for arbitrary properties, and not when you use it inside of a plugin. Alternatively we can write a Lightning CSS plugin that strips the var() for properties that accept <dashed-ident>. That way all properties regardless where they are coming from will be fixed.

But, not generating them in the first place seems better I think.

Also, it looks like you can't use var(--foo) at all, because if you then define --foo as --tl Chrome devtools don't seem to resolve these correctly, so a Lightning CSS plugin seems doable. However, if it is allowed, then this solution won't work.

Example of what I mean with variables: https://play.tailwindcss.com/Y5fbjtUBHa

@thecrypticace
Copy link
Contributor

I think this is the better route. Creating a lightning CSS plugin to do this I think would be a bad idea. I kinda feel like specifying these values with a var(…) whose value is --thing should work and the fact that it doesn't is probably a bug.

Copy link
Contributor

@thecrypticace thecrypticace left a comment

Choose a reason for hiding this comment

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

Looks good other than needing to add the font-palette property and cleanup that one if statement.

@thecrypticace
Copy link
Contributor

LGTM. The rollup-sass integration test has become super flaky with timing btw. Need to figure out how to fix that so you can ignore it.

@RobinMalfait RobinMalfait merged commit 89ec6fb into master Oct 24, 2023
10 checks passed
@RobinMalfait RobinMalfait deleted the fix/issue-12205 branch October 24, 2023 12:08
RobinMalfait added a commit that referenced this pull request Oct 24, 2023
* prevent automatic var injection for properties that accept `<dashed-ident>` for the value

* add test

* add `font-palette`

* improve readability
thecrypticace pushed a commit that referenced this pull request Oct 24, 2023
* prevent automatic var injection for properties that accept `<dashed-ident>` for the value

* add test

* add `font-palette`

* improve readability
@nnmrts
Copy link

nnmrts commented Jan 5, 2024

@RobinMalfait Can this be extended to transition/transition-property?

@mrcsmcln
Copy link

+1 as I'm currently experiencing this issue while transitioning @Property values. Currently using an underscore (e.g., transition-[_--foo].

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.

var() is incorrectly wrapped around dashed idents with CSS scroll animations
4 participants