Skip to content

[Bug]: CSS Modules local identifiers differ when exportsOnly changes #14786

Description

@intellild

System info

  • Rspack: 2.1.3
  • Node.js: 24.15.0
  • Platform: macOS arm64

Minimal reproduction

Compile the same entry twice with builtin CSS Modules enabled. The only relevant difference between the client and SSR configurations is generator.exportsOnly:

const common = {
  experiments: {
    css: true,
  },
  module: {
    rules: [
      {
        test: /\.module\.css$/,
        type: 'css/module',
        generator: {
          localIdentName: '[local]-[hash:base64:6]',
        },
      },
    ],
  },
};

// client build
{
  ...common,
  module: {
    rules: [
      {
        test: /\.module\.css$/,
        type: 'css/module',
        generator: {
          exportsOnly: false,
          localIdentName: '[local]-[hash:base64:6]',
        },
      },
    ],
  },
}

// SSR build
{
  ...common,
  target: 'node',
  module: {
    rules: [
      {
        test: /\.module\.css$/,
        type: 'css/module',
        generator: {
          exportsOnly: true,
          localIdentName: '[local]-[hash:base64:6]',
        },
      },
    ],
  },
}

Import a class named external from the same style.module.css file in both builds.

Actual behavior

The generated local identifiers differ:

  • client (exportsOnly: false): external-WlNYTF
  • SSR (exportsOnly: true): external-UmUtc0

If exportsOnly is forced to false in both builds, both sides generate external-WlNYTF.

This reproduces with a regular .module.css import, so it is not specific to a framework or SFC integration.

Expected behavior

exportsOnly should control whether CSS assets are emitted, but should not affect CSS Modules local identifier generation. The SSR and client compilations must produce identical class names for the same resource and local name.

Impact

SSR markup contains a class name that does not match the client CSS output. This can cause missing styles and hydration mismatches in applications that use builtin CSS Modules with exportsOnly: true for the server build.


by OpenAI Codex

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions