soranoo / next-css-obfuscator

A package deeply inspired by PostCSS-Obfuscator but for Next.js.
https://next-css-obfuscator.vercel.app
MIT License
71 stars 3 forks source link

`[&>{sth}]:`, `[&_{sth}]:`, `[&_.{className}]:` and `[&_#{id}]:`. Tailwind is truly incredibly strong ! #9

Closed hoangnhan2ka3 closed 7 months ago

hoangnhan2ka3 commented 7 months ago

Yes, this is a variant of *: class, it means you can use arbitrary values to target child elements.

Please refer to How to access all the direct children of a div in Tailwind CSS? - StackOverflow

Hi @soranoo, me again 🫑, we have a more complicated problem, and the description of this issue is similar to hover: or *: that I mentioned in 2 previous issues.

πŸ‘‰ [&>{foo}]:, it can be tag, class or id, the difference with below is > (direct children):

Screenshot 2024-02-02 180103

πŸ‘‰ [&_{foo}]:, the difference with above is _ (all descendants ):

Screenshot 2024-02-02 181303

πŸ‘‰ [&_.{className}]:, the difference with above is _. (class):

Screenshot 2024-02-02 175212

πŸ‘‰ [&_#{id}]:, the difference with above is _# (id):

Screenshot 2024-02-02 181611

πŸ‘‰ Result:

Screenshot 2024-02-02 182605

I also just updated to the repo I shared with you the other day #7, in /src/app/layouts/Sidebar.tsx, please check out.

npm run dev for no obfuscation and u will see it works perfectly, or go to hoangnhan.uk.

npm run build + npm run start (delete /.next/cache and old css-obfuscator folder if any) or deploy to reproduce the issue.

Thank you so much, have a nice day πŸ’•.

soranoo commented 7 months ago

Let's check out the v.2.1.2

hoangnhan2ka3 commented 7 months ago

hmmm... I didn't try to deploy but when I run build + start, it's:

Screenshot 2024-02-03 121347 Screenshot 2024-02-03 121404

I lost my main πŸ₯², run dev is okay

hoangnhan2ka3 commented 7 months ago

omg I don't know what or who was wrong :))))

Check out https://hoangnhan.uk, I turned off obfuscation and it still work, which means Tailwind is fine

hoangnhan2ka3 commented 7 months ago

Looks like the obfuscate was successful:

Take class .side-box for example, it is obfuscated to .mbzjvf, you see: 11

Screenshot 2024-02-03 125719

But in the output css file:

Screenshot 2024-02-03 125743

I just don't think it would break the website like that πŸ’£

hoangnhan2ka3 commented 7 months ago

In View page source, my main and header tag still there but when Inspect, they disappear πŸ€”

image

image

Note: Only the main page / has lost main and header; subpages like /about are still there but the situation is not very good.

soranoo commented 7 months ago

I can't reproduce most of the situations you mentioned.

Looks like the obfuscate was successful:

Take class .side-box for example, it is obfuscated to .mbzjvf, you see: 11

Screenshot 2024-02-03 125719

But in the output css file:

Screenshot 2024-02-03 125743

I just don't think it would break the website like that πŸ’£ Regarding the HTML issue, it is due to the HTML entities.

hoangnhan2ka3 commented 7 months ago

Did you practice on the repo I shared with you? Can I see the results?

soranoo commented 7 months ago

image

hoangnhan2ka3 commented 7 months ago

Except for the red text, the rest should look like this:

image

hoangnhan2ka3 commented 7 months ago

Looks like the obfuscate was successful:

Take class .side-box for example, it is obfuscated to .mbzjvf, you see: 11

Screenshot 2024-02-03 125719

But in the output css file:

Screenshot 2024-02-03 125743

I just don't think it would break the website like that πŸ’£

Have you tried checking this?

soranoo commented 7 months ago

I can't reproduce most of the situations you mentioned.

Looks like the obfuscate was successful: Take class .side-box for example, it is obfuscated to .mbzjvf, you see: 11

Screenshot 2024-02-03 125719

But in the output css file:

Screenshot 2024-02-03 125743

I just don't think it would break the website like that πŸ’£

Regarding the HTML issue, it is due to the HTML entities.

hoangnhan2ka3 commented 7 months ago

Does your .side-box actually appear in the css file, why doesn't mine, I tried everything yesterday πŸ₯²

The blue gradient box is .side-box, it doesn't even appear in my output css file:

image

soranoo commented 7 months ago

nope, I didn't see the .side-box selector in the CSS

but I got the following image

hoangnhan2ka3 commented 7 months ago

Yes, it's not in global.css, but here:

Screenshot 2024-02-04 072638

which point to below motion.div className:

Screenshot 2024-02-04 072706

It's all in /src/app/layouts/Sidebar.tsx

hoangnhan2ka3 commented 7 months ago

Maybe you're confused because I use Framer Motion, motion.div in production is just a div

And this is that motion.div:

Does your .side-box actually appear in the css file, why doesn't mine, I tried everything yesterday πŸ₯²

The blue gradient box is .side-box, it doesn't even appear in my output css file:

image

soranoo commented 7 months ago

The files in src aren't necessary for the obfuscation.

soranoo commented 7 months ago

The obfuscator only looks at the build

hoangnhan2ka3 commented 7 months ago

Not only when build, but even when deployed, .side-box completely exists in the html Soranoo πŸ‘€:

image

I don't understand what you're wondering, what can I do to answer it for you, the problem seems quite complicated.

soranoo commented 7 months ago

What do u mean by "deployed"? the runtime? I guess I misunderstood it. I think it is an alternative word for build but now I see it is obviously not the case

hoangnhan2ka3 commented 7 months ago

OK I don't know what I'm talking about or what's going on 🀑.

But the main problem now is that after run build, the [&...] classes HAVE BEEN OBFUSCATED, right?

image

.side-box WAS EXACTLY OBFUSCATED INTO .fq27tw, right?

But, in the output css file AFTER run build, there are no .fq27tw, see?

image

Which caused this:

https://github.com/soranoo/next-css-obfuscator/issues/9#issuecomment-1925493318

So, I don't know if you understand what my original problem was?

Remember the problem with *: class the other day? yes, similar to it.

This means that even though they have been obfuscated, those new classes have NOT BEEN REPLACED IN both the final .html and .css files.

Please clone the exact project I shared with you the other day, change enable to false, npm i >npm run build > npm run start to see exactly if your package is not used. What will the website look like?

image

That's exactly what I expected to see on my website, except when I turned on your package it broke.

soranoo commented 7 months ago

Check the beta out.

soranoo commented 7 months ago

OK I don't know what I'm talking about or what's going on 🀑.

But the main problem now is that after run build, the [&...] classes HAVE BEEN OBFUSCATED, right?

image

.side-box WAS EXACTLY OBFUSCATED INTO .fq27tw, right?

But, in the output css file AFTER run build, there are no .fq27tw, see?

image

Which caused this:

#9 (comment)

So, I don't know if you understand what my original problem was?

Remember the problem with *: class the other day? yes, similar to it.

This means that even though they have been obfuscated, those new classes have NOT BEEN REPLACED IN both the final .html and .css files.

Please clone the exact project I shared with you the other day, change enable to false, npm i >npm run build > npm run start to see exactly if your package is not used. What will the website look like?

image

That's exactly what I expected to see on my website, except when I turned on your package it broke.

This is a different issue to *:

hoangnhan2ka3 commented 7 months ago

Yeah there is a difference, but I really don't know what to compare it to so you can understand.

hoangnhan2ka3 commented 7 months ago

Hey... maybe it works

soranoo commented 7 months ago

Ok let me sum up the issue,

Let say we have a selector.\[\&_\#i-am-id\]\

Tailwind will compile the class to the following CSS,

/* CSS */

.\[\&_\#i-am-id\]\{
/* something here */
}

but NEXT JS will do something like escape to the selector in HTML, like the following,

<!-- HTML -->

<div class="[&amp;_#i-am-id]"></div>

Now, you can see we have different classes/selectors and we can't match them directly using exact wording matching. SO to deal with it, simply replace these "Special Symbols" with HTML Character Entities

 "&": "&amp;",
  "<": "&lt;",
  ">": "&gt;",
  '"': "&quot;",
  "'": "&#39;",
hoangnhan2ka3 commented 7 months ago

Please wait, something happen with my npm :)))

hoangnhan2ka3 commented 7 months ago

OMG I ran npm in another directory terminal =)))

hoangnhan2ka3 commented 7 months ago

hmm what was that weird spacing

image

hoangnhan2ka3 commented 7 months ago

only this [&_.side-box]:to-85% is not applied

image

image

Ahh I forgot, please refer to: https://tailwindcss.com/docs/gradient-color-stops#specifying-stop-positions

hoangnhan2ka3 commented 7 months ago

Otherwise, other than the strange spacing, it all works, maybe, let me enable a canvas

Update: also work

soranoo commented 7 months ago

I will open a new issue for it. This is not on my priority list. I will take a look at it after I finish my JS compiler.

hmm what was that weird spacing

image

soranoo commented 7 months ago

only this [&_.side-box]:to-85% is not applied

image

image

Ahh I forgot, please refer to: https://tailwindcss.com/docs/gradient-color-stops#specifying-stop-positions

where is it? I don't see in any file

hoangnhan2ka3 commented 7 months ago

Let me update for you, please wait

hoangnhan2ka3 commented 7 months ago

Updated, please check out @soranoo

soranoo commented 7 months ago

same, I didn't find it

image

hoangnhan2ka3 commented 7 months ago

I'm really sorry, right now when I sent the update message, I updated the wrong version and moved to-85% down for .side-box, then I updated it right away.

image

Sorry for this inconvenience

hoangnhan2ka3 commented 7 months ago

Harmless but worth optimizing:

image

soranoo commented 7 months ago

Check out the 2.1.4-beta.1

hoangnhan2ka3 commented 7 months ago

DONE, CLOSE IT HONEYπŸ’•

image