Skip to content
This repository was archived by the owner on Aug 28, 2026. It is now read-only.
This repository was archived by the owner on Aug 28, 2026. It is now read-only.

\@ in CSS Selector #913

Closed
Closed

Description

@marekkobida
  • macOS Mojave 10.14 (18A391)
  • Node.js 11.13.0
  • npm 6.7.0
  • webpack 4.29.6
  • css-loader 2.1.1

Expected Behavior

<div class="m_x_@"></div>

Actual Behavior

.m_x_\@ {
  margin-left: auto !important;
  margin-right: auto !important;
}
/*
 * @flow
 */

import * as React from 'react';

import design from './design.scss';

class Test extends React.Component<P: {

}> {
  render () {
    return <div className={design['m_x_@']} />;
  }
}

export default Test;
<div class="m_x_----wB9u"></div>

Code

const path = require('path');

const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const sass = require('sass');

const isProduction = process.env.NODE_ENV === 'production';

const js = {
  exclude: /node_modules/,
  test: /\.js$/,
  use: [
    {
      loader: 'babel-loader',
    },
  ],
};

module.exports = {
  devtool: isProduction ? '' : 'source-map',
  entry: {
    index: path.resolve(__dirname, 'private/index.js'),
  },
  mode: isProduction ? 'production' : 'development',
  module: {
    rules: [
      js,
      {
        exclude: /node_modules/,
        test: /\.scss$/,
        use: [
          MiniCssExtractPlugin.loader,
          {
            loader: 'css-loader',
            options: {
              importLoaders: 2,
              localIdentName: isProduction ? '[hash:base64:8]' : '[local]--[hash:base64:4]',
              modules: true,
              sourceMap: !isProduction,
            },
          },
          {
            loader: 'postcss-loader',
            options: {
              plugins: [
                require('autoprefixer'),
              ],
              sourceMap: !isProduction,
            },
          },
          {
            loader: 'sass-loader',
            options: {
              implementation: sass,
              outputStyle: isProduction ? 'compressed' : 'expanded',
              sourceMap: !isProduction,
            },
          },
        ],
      },
    ],
  },
  output: {
    filename: '[name].js',
    path: path.resolve(__dirname, 'public'),
  },
  plugins: [
    new MiniCssExtractPlugin(),
  ],
};

Activity

  1. alexander-akait commented on Apr 3, 2019

    @alexander-akait
    Member

    @ is not valid characters for classes in css so we strip this for css modules

  2. alexander-akait commented on Apr 3, 2019

    @alexander-akait
    Member

    What you expected? No hash or not strip @?

  3. marekkobida commented on Apr 3, 2019

    @marekkobida
    Author

    @ is allowed

    W3C says

    Identifiers can also contain escaped characters and any ISO 10646 character as a numeric code (see next item). For instance, the identifier "B&W?" may be written as "B&W?" or "B\26 W\3F".

    but css-loader modified \@ into -- (nothing)

  4. alexander-akait commented on Apr 3, 2019

    @alexander-akait
    Member

    Please provide minimum reproducible test repo, thanks

  5. alexander-akait commented on Apr 3, 2019

    @alexander-akait
    Member

    No @ is not allowed, and should be escaped in # (id selector) and . (class selector)

  6. alexander-akait commented on Apr 5, 2019

    @alexander-akait
    Member

    Looks i find problem @ is disappear from locals, yep it is bug, we need fix, feel free to send a PR

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions