Skip to content

@container ruleset spaces removed after container-name #4397

Closed

Description

@cmerighi

To reproduce:

// less code here
@varx: foo;
@container @varx (min-width: @threshold){
   /* ... */
}

Current behavior:

/* trailing space after the variable gets removed
    => 'foo' handled as a function
    => fail */
@container foo(min-width: 1024px){
    /* ... */
}

Expected behavior:

/* space chars preserved */
@container foo (min-width: 1024px){
    /* ... */
}

Environment information:

  • less version: 4.4.1+
  • nodejs version: 24.13.0
  • operating system: Windows

Temporary workaround:

@varx: foo;
@varxs: ~"@{varx} ";
@container @varxs (min-width: @threshold){
   /* ... */
}

Activity

  1. dosubot commented on Jan 21, 2026

    @dosubot

    Hi @cmerighi! I'm Dosu and I’m helping the less.js team.

    This is a known issue in Less 4.4.1: when you use a variable for the container name in an @container rule, Less doesn't automatically preserve the space between the name and the condition. This happens because of how the parser merges nodes and sets a noSpacing flag, causing the output to omit the space—so @container foo(min-width: 1024px) is generated instead of the expected @container foo (min-width: 1024px) details.

    This was a regression and has been fixed in Less 4.4.2 (PR #4363). Upgrading to 4.4.2 or later should resolve the issue and preserve the space as expected.

    If you can't upgrade, your workaround of adding a trailing space to the variable value (e.g., @varxs: ~"@{varx} ";) is the correct approach for Less 4.4.1 source.

    To reply, just mention @dosu.


    Share context across your team and agents. Try Dosu.

    Leave Feedback Learn about less.js with Dosu Add Dosu to your team

  2. cmerighi commented on Jan 21, 2026

    @cmerighi
    Author

    @dosu 4.4.1 is the first version from which I experience the issue. I'm now on version 4.5.1.

  3. dosubot commented on Jan 21, 2026

    @dosubot

    The space-removal issue with @container rules was fixed in Less 4.4.2, and there’s no evidence of a regression in 4.5.1—the fix should still be effective in your current version link. If you’re still seeing the problem, double-check that your variable includes any needed trailing space, since Less relies on the actual value for spacing. If the issue persists despite this, let me know and I can help troubleshoot further.

    To reply, just mention @dosu.


    Share context across your team and agents. Try Dosu.

    Leave Feedback Learn about less.js with Dosu Add Dosu to your team

  4. changed the title [-]@container ruleset spaces removed after container-name.[/-] [+]@container ruleset spaces removed after container-name[/+] on Jan 21, 2026
  5. puckowski commented on Jan 23, 2026

    @puckowski
    Contributor

    Hello,

    I believe I have a change that would make this syntax possible

    @varx: foo;
    @container @varx (min-width: @threshold){

    but I need some time to simplify and review the solution. I'll try to create a PR this weekend.

  6. added 2 commits that reference this issue on Jan 24, 2026
    582d8c1
    830682a
  7. puckowski commented on Jan 25, 2026

    @puckowski
    Contributor

    I proposed a fix for this issue in #4398 which is pending peer review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions