cssinjs / jss

JSS is an authoring tool for CSS which uses JavaScript as a host language.
https://cssinjs.org
MIT License
7.08k stars 399 forks source link

fixed bug on jss-plugin-nested #1591

Closed heyymarco closed 2 years ago

heyymarco commented 2 years ago

According a bug on here

The bug is here:

  function replaceParentRefs(nestedProp, parentProp) {
    const parentSelectors = parentProp.split(separatorRegExp)
    const nestedSelectors = nestedProp.split(separatorRegExp)

it split the string by comma, but imagine a selector like this: &.hello, &.world:is(.awesome, .good, .bad)

it will splitted to:

['&.hello', '&.world:is(.awesome', '.good', '.bad)']

it's incorrect, and should be:

['&.hello', '&.world:is(.awesome, .good, .bad)']

and the another bug is with the parent selector &.
Imagine if a selector like this: &.hello, &.world[data-message="you & me"] The & inside "you & me" is not a parent selector, it's just a string expression.

To solve the 2 problem above, i wrote a selector parser,
you can see (and maybe make more perfection) here: see my repo. The parser is smart enough to distinguish between parent selector, universal selector, combinators, string expression, and so on. The usage is simple: parseSelector => flatMapSelectors (replace & with something) => selectorsToString.

the package published with es9 format, but you can fork & re-transpile to es5.

seiyab commented 2 years ago

Great. I think you should write tests.

See also: https://github.com/cssinjs/jss/pull/1568#issuecomment-949967416 https://github.com/cssinjs/jss/pull/1523#issuecomment-869145245 https://github.com/cssinjs/jss/pull/1388#issuecomment-707008924

kof commented 2 years ago

please reopen once you have time to continue

kof commented 2 years ago

Feel free to fix a bug with a proper test and I will merge it.

Oleg

On 19. Apr 2022, at 09:24, Daniil @.***> wrote:

This bug is from version 10.0.1 (more one year!!). Shouldn't it be fixed by the current library team? Part of my team is giving up on jss, as well as some people I know because of this problem. I honestly don't quite understand the point of preparing a move to 18 React if there are such critical bugs Sorry if I offended or don't understand your processes, I'm speaking as a regular consumer of your library

— Reply to this email directly, view it on GitHub https://github.com/cssinjs/jss/pull/1591#issuecomment-1102277792, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAM4WEBOPNFAETL2QRPHFDVFZUUVANCNFSM5JK7XM5Q. You are receiving this because you modified the open/close state.