question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Arbitrary values aren't recognised in Ruby percent arrays

See original GitHub issue

Thank you for an awesome tool! I’ve been using it in all my projects recently and the productivity gains have been immense.

What version of Tailwind CSS are you using?

Tailwind v3.2.4

What build tool (or framework if it abstracts the build tool) are you using?

postcss: 8.4.19, postcss-cli 10.0.0

What version of Node.js are you using?

Node v16.18.1

What browser are you using?

Firefox

What operating system are you using?

macOS

Reproduction URL

I have added a test case that fails, showing the incorrect behaviour. This is the first time I’ve popped the hood on Tailwind, so forgive me if the regexes I’ve linked are the incorrect ones.

https://github.com/developius/tailwindcss/commit/5fb86ab84603949212d8146b09d242b420c7df85

Describe your issue

We’re using Ruby on Rails with Tailwind and use the Ruby percent string syntax to generate arrays. Something like %w[text-[#bada55]] becomes ["text-[#bada55]"] in Ruby.

The following ERB code doesn’t correctly generate the arbitrary value Tailwind class:

<%= content_tag(:div, class: %w[text-[#bada55]]) {} %>

However, this does work:

<%= content_tag(:div, class: ["text-[#a55bad]"]) {} %>

As noted in my commit above, I think this is due to the extra closing square bracket tripping up the regex here^1 but my knowledge of Tailwind’s internals is very vague.

I’m not sure if there’s a way to fix this or not, as I appreciate that handling extremely specific scenarios like this is a direction the project might not want to head in. But maybe there’s a quick fix? Thanks for checking this issue out, anyway 😄

Issue Analytics

  • State:closed
  • Created 10 months ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
thecrypticacecommented, Dec 1, 2022

Hey, I’ve merged a fix for this which will be in our next release. In the mean time you can test it by installing our insiders build: npm install tailwindcss@insiders. It’ll take a few minutes for the changes to build, test, and publish to npm. Thanks! ✨

0reactions
developiuscommented, Nov 30, 2022

The transformer works perfectly, thank you @thecrypticace. I also validated that no other classes got added to the generated CSS - it only included the previously-unmatching one 💯

Do you feel that a modification to the regex is a path we can take here? We can use the transformer in the meantime.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Arbitrary values aren't recognised in Ruby percent arrays
So, just following up on this. Making this working might require some regex hijinks (and may not work well in general but will...
Read more >
literals - Documentation for Ruby 2.0.0 - doc.ruby-lang.org
Literals create objects you can use in your program. Literals include: Booleans and nil. Numbers. Strings. Symbols. Arrays. Hashes.
Read more >
Ruby: Is there an opposite of include? for Ruby Arrays?
Ruby : Is there an opposite of include? for Ruby Arrays? · 1. is the do valid ruby? i get an error syntax...
Read more >
Arrays - Ruby - DevTut
There are two ways to populate an array with default values: Pass an immutable value as second argument. Pass a block that gets...
Read more >
Arrays | RUBY
Arrays of strings can be created using ruby's percent string syntax: ... It is also possible to use arbitrary non-alphanumeric delimiters, such as:...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found