Skip to content

[@lit-labs/rollup-plugin-minify-html-literals] Does not minify @container queries correctly #5207

Description

@cadamsdev

Which package(s) are affected?

@lit-labs/rollup-plugin-minify-html-literals

Description

When we minify a template string that contains a css container query it does not minify correctly.

For example

Input

    function someFunction() {
      return css\`
        :host {
          container-type: inline-size;
        }

        .some-class {
          padding: 16px;
        }
      
        @container (min-width: 768px) {
          .some-class {
            display: flex;
          }

          .another-class {
            font-size: 20px;
          }
        }
      \`;
    }

Actual Output

    function someFunction() {
      return css`:host{container-type:inline-size}.some-class{padding:16px}.another-class{font-size:20px}`;
    }

Expected Output

    function someFunction() {
      return css`:host{container-type:inline-size}.some-class{padding:16px}@container (min-width:768px){.some-class{display:flex}.another-class{font-size:20px}}`;
    }

Reproduction

Inside packages/labs/rollup-plugin-minify-html-literals/src/test/minify-html-literals.spec.ts add unit test

  const CONTAINER_QUERY_SOURCE = `
    function someFunction() {
      return css\`
        :host {
          container-type: inline-size;
        }

        .some-class {
          padding: 16px;
        }
      
        @container (min-width: 768px) {
          .some-class {
            display: flex;
          }

          .another-class {
            font-size: 20px;
          }
        }
      \`;
    }
  `;

  const CONTAINER_QUERY_SOURCE_MIN = `
    function someFunction() {
      return css\`:host{container-type:inline-size}.some-class{padding:16px}@container (min-width:768px){.some-class{display:flex}.another-class{font-size:20px}}\`;
    }
  `;

  test('should preserve CSS inside @container queries', async () => {
    const result = await minifyHTMLLiterals(CONTAINER_QUERY_SOURCE, {
      fileName: 'test.js',
    });
    assert.equal(typeof result, 'object');
    assert.equal(result!.code, CONTAINER_QUERY_SOURCE_MIN);
  });

Workaround

I have not found a workaround.

Is this a regression?

No or unsure. This never worked, or I haven't tried before.

Affected versions

0.1.1

Browser/OS/Node environment

node --version
v22.21.1

npm --version
10.9.4

Activity

  1. added theissue type on Jan 9, 2026
  2. cadamsdev commented on Jan 9, 2026

    @cadamsdev
    Author

    I created a PR for this. Looks like all we have to do is bump the clean-css version. However that also introduces another small regression. See my comment. Let me know how we can proceed with fixing this.

    Thanks

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

    No labels
    No labels

    Type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions