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

fixed bug on jss-plugin-nested #1591

Closed
wants to merge 1 commit into from
Closed

Conversation

heyymarco
Copy link

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.

@heyymarco heyymarco requested a review from kof as a code owner December 4, 2021 01:51
@seiyab
Copy link
Member

seiyab commented Feb 2, 2022

Great.
I think you should write tests.

See also:
#1568 (comment)
#1523 (comment)
#1388 (comment)

parseSelectors,
flatMapSelectors,
selectorsToString,
} from '@cssfn/css-selector'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am afraid we can't do this, its a huge bundle-size increase

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need a solution that is super minimalistic

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow did you write the selector parser to fix this bug? If so huge props in any case!
But jss is runtime-executed, it gets bundled with a client-side app, the only way forward is to reduce the size, even potentially remove features to make it small.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@heyymarco wow dude! thats some serious work!

@kof
Copy link
Member

kof commented Apr 16, 2022

please reopen once you have time to continue

@kof kof closed this Apr 16, 2022
@kof
Copy link
Member

kof commented Apr 19, 2022 via email

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 this pull request may close these issues.

4 participants