Skip to content

Conversation

philipp-spiess
Copy link
Member

@philipp-spiess philipp-spiess commented Jan 30, 2025

This PR ensures that escaped theme variables are properly handled. We do this by moving the escape/unescape responsibility back into the main tailwindcss entrypoint that reads and writes from the CSS and making sure that _all internal state of the Theme class are unescaped classes.

However, due to us accidentally shipping the part where a dot in the theme variable would translate to an underscore in CSS already, this logic is going to stay as-is for now.

Here's an example test that visualizes the new changes:

expect(
  await compileCss(
    css`
      @theme {
        --spacing-*: initial;
        --spacing-1\.5: 2.5rem;
        --spacing-foo\/bar: 3rem;
      }
      @tailwind utilities;
    `,
    ['m-1.5', 'm-foo/bar'],
  ),
).toMatchInlineSnapshot(`
  ":root, :host {
    --spacing-1\.5: 2.5rem;
    --spacing-foo\\/bar: 3rem;
  }

  .m-1\\.5 {
    margin: var(--spacing-1\.5);
  }

  .m-foo\\/bar {
    margin: var(--spacing-foo\\/bar);
  }"
`)

Test plan

  • Added a unit test

  • Ensure this works end-to-end using the Vite playground:

    Screenshot 2025-01-30 at 14 51 05

@philipp-spiess philipp-spiess requested a review from a team as a code owner January 30, 2025 13:55
),
).toMatchInlineSnapshot(`
":root, :host {
--spacing-1_5: 2.5rem;
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this be --spacing-1\.5?

Copy link
Member Author

Choose a reason for hiding this comment

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

@adamwathan Ah yeah I think you're right if they're defined with \. they should be CSS variables with \. just the lookup for 1_5 should also work 👍

@philipp-spiess philipp-spiess merged commit 60e6195 into main Jan 31, 2025
5 checks passed
@philipp-spiess philipp-spiess deleted the fix/escaped-theme-vars branch January 31, 2025 14:20
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.

3 participants