CSS selector bug

I thought I was going insane In a popup, apply a sibling selector (~) , e.g. https://codepen.io/vescoyez/pen/wMyRLP?editors=1100 It appears that Plasmo uses autoprefixer to only apply -moz- selectors, but no prefix-free ones, despite running
plasmo dev --verbose
plasmo dev --verbose
40 Replies
Avi
AviOPโ€ข2y ago
FYI it occurs whether my <style> has lang="scss" or not FYI when I apply :placeholder-shown without ~, it doesn't apply the -moz- prefix @louis Any chance to solve it soon?
lab
labโ€ข2y ago
so it doesn't work if you do input:placeholder-shown??
Avi
AviOPโ€ข2y ago
It does work It fails to work when I use ~
input:placeholder-shown { } // works
label { } // works
input:placeholder-shown ~ label { } // DOESN'T work
input:placeholder-shown { } // works
label { } // works
input:placeholder-shown ~ label { } // DOESN'T work
lab
labโ€ข2y ago
Does it work if it's not embedded as a svelte style?
Avi
AviOPโ€ข2y ago
That's what I haven't tried, I haven't tested it against non-Svelte
lab
labโ€ข2y ago
plasmo uses lightningcss underneath so CSS compiling issue is due to that package
Avi
AviOPโ€ข2y ago
What I know so far is that even if I don't use SCSS, the issue persists I see, then we should perhaps report the issue there The issue persists whether the <style> has or doesn't have lang="scss" What do we do in the meantime? What is the easiest way to run lightningcss? I tried running through the browser, didn't work I tried running it through Node.js, couldn't reproduce I tried running it through the CLI, couldn't Trulysad
lab
labโ€ข2y ago
I'm not quite sure tbh xD...... what if you use a separate css file? does it work or still foobar xd
Avi
AviOPโ€ข2y ago
Interesting, + is also affected It has something to do with :placeholder-shown Probably this one https://github.com/parcel-bundler/lightningcss/blob/30469232c3fdb828753db4be49f48e9bf727a655/src/selector.rs#L131 For some reason, if the selectors are nested, it will change :placeholder-shown into :-moz-placeholder-shown, e.g.
input:placeholder-shown > label { }
โ†“
input:-moz-placeholder-shown > label {}
input:placeholder-shown > label { }
โ†“
input:-moz-placeholder-shown > label {}
Maybe it has to do with the Svelte compiler @louis Seems like I'm able to trick the compiler with
input:placeholder-shown:not(:-moz-placeholder-shown) ~ label { }
input:placeholder-shown:not(:-moz-placeholder-shown) ~ label { }
In this case, it'll produce both versions
.form__field:-moz-placeholder-shown:not(:-moz-placeholder-shown) ~ .form__label, .form__field:placeholder-shown:not(:-moz-placeholder-shown) ~ .form__label {
cursor: text;
font-size: 16px;
top: 20px;
}
.form__field:-moz-placeholder-shown:not(:-moz-placeholder-shown) ~ .form__label, .form__field:placeholder-shown:not(:-moz-placeholder-shown) ~ .form__label {
cursor: text;
font-size: 16px;
top: 20px;
}
WTF, despite the CSS looking right, the rules aren't being applied ๐Ÿ˜
lab
labโ€ข2y ago
fascinating lol
Avi
AviOPโ€ข2y ago
I ran into a stupid issue ๐Ÿ˜‘
Avi
AviOPโ€ข2y ago
๐Ÿคจ
Avi
AviOPโ€ข2y ago
position - CSS: Cascading Style Sheets | MDN
The position CSS property sets how an element is positioned in a document. The top, right, bottom, and left properties determine the final location of positioned elements.
Avi
AviOPโ€ข2y ago
Why dafuq is the initial value static???
lab
labโ€ข2y ago
lol it's always has been
Avi
AviOPโ€ข2y ago
It's so weird On the left it's the popup, on the right it's Codepen
Avi
AviOPโ€ข2y ago
And as I said before, the rules should be applied wait fr I removed the :not(:-moz-placeholder-shown) and it worked
lab
labโ€ข2y ago
heh
Avi
AviOPโ€ข2y ago
Yeah, the CSS engine apparently doesn't like unknown pseudo classes
Avi
AviOPโ€ข2y ago
And yes, it doesn't exist
lab
labโ€ข2y ago
should be fast I hope, it's a pretty active project
Avi
AviOPโ€ข2y ago
TBH I'm not even sure if my PR will solve the issue ๐Ÿ˜… It's been 4 days since the PR TrollDespair
lab
labโ€ข2y ago
bruh me when I submit a PR to parcel and they took 3 months to merge it, which prompted me to create the plasmo framework (fyi lightningcss was created and maintained by the same guy working on parcel) oh yeah they added it to the parcel project now eh I forgot about ixd
Avi
AviOPโ€ข2y ago
The thing is, I don't even know if my fix will indeed fix me problem hah
Avi
AviOPโ€ข2y ago
I thought it was a big brain moment, but lightningcss was like nope
<script lang="ts">
import styleText from "data-text:~styles/styles-text-field.css";

const style = document.createElement("style");
style.textContent = styleText;
document.head.append(style);
</script>
<script lang="ts">
import styleText from "data-text:~styles/styles-text-field.css";

const style = document.createElement("style");
style.textContent = styleText;
document.head.append(style);
</script>
Avi
AviOPโ€ข2y ago
@louis I'm wondering, why does data-text: involve lightningcss at all? I mean, I intend to import text
lab
labโ€ข2y ago
it still need to transform the css/sass into optimized code within the bundle :d
Avi
AviOPโ€ข2y ago
I see, IMO it should be context-dependent I.e. importing SCSS should indeed be processed and optimized, but if I import CSS this way while in a Svelte/Vue popup, I'd probably want to deal with the CSS myself, such as working around the annoying -moz-placeholder-shown thing You know what, how about if you fork the repo and apply my PR until a Parcel maintainer will merge it?
lab
labโ€ข2y ago
hmmm... tempting one problem I hate about the parcel repo is that it's big xD... I was never able to build the whole thing from source, and lightningcss is rust based too xd
Avi
AviOPโ€ข2y ago
I think it's worth the shot
lab
labโ€ข2y ago
oh actually seems like lightningcss is separated into its own repo now just under the same org
Avi
AviOPโ€ข2y ago
Relying on an unmaintained project is hell
lab
labโ€ข2y ago
lol well yeah but nobody thank him try build and publish to npm on your end, and I can guide you on how to use it in your local plasmo to test and debug further actually build and link it :p easiest for you to do is build, link your local lightningcss build with your extension <- pnpm will resolve to your local build then you can verify if that PR fix the issue you saw
Avi
AviOPโ€ข2y ago
man sounds like too much work ๐Ÿ˜‚
Avi
AviOPโ€ข2y ago
@louis This is what I call a big brain move
const elStyle = document.createElement("style");
elStyle.textContent = `
.form__group {
position: relative;
padding: 15px 0 0;
margin-top: 10px;
}

.form__field {
font-family: inherit;
width: 100%;
border: 0;
border-bottom: 1px solid #d2d2d2;
outline: 0;
font-size: 16px;
color: #212121;
padding: 7px 0;
background: transparent;
transition: border-color 0.2s;
}

.form__field::placeholder {
color: transparent;
}

.form__field:placeholder-shown ~ .form__label {
font-size: 16px;
cursor: text;
top: 20px;
}

label,
.form__field:focus ~ .form__label {
position: absolute;
top: 0;
display: block;
transition: 0.2s;
font-size: 12px;
color: #9b9b9b;
}

.form__field:focus ~ .form__label {
color: #009788;
}

.form__field:focus {
padding-bottom: 6px;
border-bottom: 2px solid #009788;
}
`;
document.head.append(elStyle);
const elStyle = document.createElement("style");
elStyle.textContent = `
.form__group {
position: relative;
padding: 15px 0 0;
margin-top: 10px;
}

.form__field {
font-family: inherit;
width: 100%;
border: 0;
border-bottom: 1px solid #d2d2d2;
outline: 0;
font-size: 16px;
color: #212121;
padding: 7px 0;
background: transparent;
transition: border-color 0.2s;
}

.form__field::placeholder {
color: transparent;
}

.form__field:placeholder-shown ~ .form__label {
font-size: 16px;
cursor: text;
top: 20px;
}

label,
.form__field:focus ~ .form__label {
position: absolute;
top: 0;
display: block;
transition: 0.2s;
font-size: 12px;
color: #9b9b9b;
}

.form__field:focus ~ .form__label {
color: #009788;
}

.form__field:focus {
padding-bottom: 6px;
border-bottom: 2px solid #009788;
}
`;
document.head.append(elStyle);
lab
labโ€ข2y ago
lol got 'em
Avi
AviOPโ€ข2y ago
Screw you lightningcss ๐Ÿ˜
Avi
AviOPโ€ข2y ago
@louis Someone responded wowreact
Want results from more Discord servers?
Add your server