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

Abnormal css ouput when some string in the code is wrapped in square brackets #6395

Closed
ltclmbdev opened this issue Dec 11, 2021 · 1 comment · Fixed by #6469
Closed

Abnormal css ouput when some string in the code is wrapped in square brackets #6395

ltclmbdev opened this issue Dec 11, 2021 · 1 comment · Fixed by #6469

Comments

@ltclmbdev
Copy link

ltclmbdev commented Dec 11, 2021

What version of Tailwind CSS are you using?

v3.0.1

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

Next.js 12.0.4, postcss 8.4.4

What version of Node.js are you using?

v14.18.1

What browser are you using?

Chrome

What operating system are you using?

macOS

Reproduction URL

https://github.com/DrShpongle/tailwindcss-3-issue-demo

Describe your issue

In case we use some text wrapped with square brackets we get abnormal css output:

Example 1:
Just an object with string field:
https://github.com/DrShpongle/tailwindcss-3-issue-demo/blob/main/components/problem-01.js#L4-L5
problem-01 js — with-tailwindcss-app 2021-12-11 at 1 36 31 PM

and related output:
https://github.com/DrShpongle/tailwindcss-3-issue-demo/blob/main/dist/output.css#L579-L581
output css — with-tailwindcss-app 2021-12-11 at 1 38 58 PM

Example 2:
Just regular dumb component:
https://github.com/DrShpongle/tailwindcss-3-issue-demo/blob/main/components/problem-02.tsx#L10
problem-02 tsx — with-tailwindcss-app 2021-12-11 at 1 42 50 PM

and related output:
https://github.com/DrShpongle/tailwindcss-3-issue-demo/blob/main/dist/output.css#L583-L585
output css — with-tailwindcss-app 2021-12-11 at 1 44 09 PM

@ltclmbdev ltclmbdev changed the title Abnormal css ouput when some text is wrapped in square brackets Abnormal css ouput when some string in the code is wrapped in square brackets Dec 11, 2021
@sachinraja
Copy link
Contributor

sachinraja commented Dec 12, 2021

This is probably because of arbitrary properties.

you can just add an unnecessary escape:

const ProblemComponent = () => {
  return (
    <button
      nCanPlay={(event: any) => {
        console.debug(`player ready: [autoplay\:${autoplay}]`);
      }}
    ></button>
  );
};

you can also use a function like this:

const addBrackets = (str: string) => `[${str}]`;

const ProblemComponent = () => {
  return (
    <button
      nCanPlay={(event: any) => {
        console.debug(`player ready: ${addBrackets(`autoplay:${autoplay}`)}]`);
      }}
    ></button>
  );
};

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 a pull request may close this issue.

2 participants