less / less/less.js

Building mixins should combine duplicate nested selectors

Open
#930 13 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

feature request low priority up-for-grabs
Dominant language
JavaScript
Stars
17k
Forks
3.4k
Avg merge
7h 42m
Merged PRs (30d)
26

Description

I often find myself avoiding mixins because I know that the compiled CSS will have duplicate selectors, which makes for a larger file. For example, a reduced test case:

.mixin () {
    a {
        color: red;
    }
}
div {
    .mixin();
    a {
        text-decoration: none;
    }
}

When this is compiled, the resulting output is:

div a {
    color: red;
}
div a {
    text-decoration: none;
}

In a perfect world, selectors inside a mixin and selectors inside the scope in which the mixin was executed would be combined when they are identical. Then, the resulting output would be the much cleaner:

div a {
    color: red;
    text-decoration: none;
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by compiling the reduced mixin test case in the issue and compare its duplicate CSS selectors with the requested combined output. Done means identical nested selectors from the mixin and its surrounding scope produce one CSS rule containing both declarations.

Written by the indexing model from the issue text.

Assessment

Tech stack
css
Domain
frontend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.