Skip to content

Upstream API errors are encountered when using construction styles in Lit. #3950

Answered by ouweiya
ouweiya asked this question in Q&A
Discussion options

You must be logged in to vote

After investigation, I found out that in JS, backslashes \ need to be escaped. Otherwise, .hover\:bg-red-300:hover is parsed as .hover:bg-red-300:hover, which is obviously not a valid CSS selector. The problem can be fixed by escaping the backslash, resulting in .hover\\:bg-red-300:hover.

If you're using PostCSS to compile TailwindCSS, you can write a mini plugin to complete the escape operation.

const postcssDoubleEscape = () => {
  return {
    postcssPlugin: 'postcss-double-escape',
    Once(root) {
      root.walkRules(rule => {
        rule.selectors = rule.selectors.map(selector => {
          return selector.replace(/\\:/g, '\\\\:');
        });
      });
    },
  };
};
// Run post…

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by e111077
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants