Skip to content

fix: CSS source map line offsets when wrapping extracted CSS with @cssId#2514

Merged
luhc228 merged 1 commit intomainfrom
fix/css-diagnostics-source-map
Apr 23, 2026
Merged

fix: CSS source map line offsets when wrapping extracted CSS with @cssId#2514
luhc228 merged 1 commit intomainfrom
fix/css-diagnostics-source-map

Conversation

@luhc228
Copy link
Copy Markdown
Collaborator

@luhc228 luhc228 commented Apr 23, 2026

Summary by CodeRabbit

  • Bug Fixes

    • Corrected CSS source map line offsets when extracted CSS is wrapped with cssId metadata so reported source positions are accurate.
  • New Features

    • Added a public API to process, resolve and deduplicate Tasm CSS diagnostics, plus related diagnostic types and exports for richer build-time reporting.
  • Tests

    • Added unit and integration tests for source-map offset behavior and the diagnostics processing pipeline.
  • Chores

    • Added changeset metadata to publish a patch release.

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).
  • Changeset added, and when a BREAKING CHANGE occurs, it needs to be clearly marked (or not required).

Copilot AI review requested due to automatic review settings April 23, 2026 07:06
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 23, 2026

🦋 Changeset detected

Latest commit: 17bb077

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@lynx-js/css-extract-webpack-plugin Patch
@lynx-js/react-rsbuild-plugin Patch
@lynx-js/react-alias-rsbuild-plugin Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 23, 2026

📝 Walkthrough

Walkthrough

Fixes CSS source-map line offsets when extracted CSS is wrapped with @cssId, adds an exported offsetSourceMapLines helper and tests, and centralizes TASM CSS diagnostics extraction, resolution, and deduplication into a new processTasmCSSDiagnostics pipeline used by the template plugin.

Changes

Cohort / File(s) Summary
Changeset + CSS Extract Plugin
\.changeset/fix-css-id-source-map-offset.md, packages/webpack/css-extract-webpack-plugin/src/loader.ts, packages/webpack/css-extract-webpack-plugin/test/loader.test.ts
Adds exported offsetSourceMapLines and uses it to prepend semicolons to mappings when wrapped with @cssId; changes sourceMap typing to DependencySourceMap; removes line-continuation prefix in wrapper output; adds unit tests for offsetSourceMapLines.
Template Plugin — diagnostics pipeline
packages/webpack/template-webpack-plugin/src/cssDiagnostics.ts, packages/webpack/template-webpack-plugin/src/LynxEncodePlugin.ts, packages/webpack/template-webpack-plugin/src/index.ts, packages/webpack/template-webpack-plugin/etc/template-webpack-plugin.api.md, packages/webpack/template-webpack-plugin/test/cssDiagnostics.test.ts
Introduces processTasmCSSDiagnostics and ProcessTasmCSSDiagnosticsOptions, adds getMainCSSSourceMap, reworks LynxEncodePlugin to call the new pipeline and emit Webpack warnings, re-exports new types/functions, updates API docs, and adds end-to-end unit test.
Test / Example config tweak
packages/webpack/template-webpack-plugin/test/cases/code-splitting/initial-css-order/rspack.config.js
Swaps plugin imports to use built lib/index.js instead of src in the test config; no behavioral changes.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

Suggested reviewers

  • upupming
  • colinaaa

Poem

🐰 I nudge the maps by just one line,

Wrapped CSS and source align,
Diagnostics flow through one neat gate,
Duplicate warnings separate,
Hop—builds assemble, code looks fine.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 10.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: CSS source map line offsets when wrapping extracted CSS with @cssId' directly and specifically summarizes the main change across the changeset.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/css-diagnostics-source-map

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Comment thread packages/webpack/template-webpack-plugin/src/index.ts
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 23, 2026

Codecov Report

❌ Patch coverage is 42.46575% with 42 lines in your changes missing coverage. Please review.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
...pack/template-webpack-plugin/src/cssDiagnostics.ts 38.29% 29 Missing ⚠️
...s/webpack/css-extract-webpack-plugin/src/loader.ts 57.89% 8 Missing ⚠️
...ck/template-webpack-plugin/src/LynxEncodePlugin.ts 28.57% 5 Missing ⚠️

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
packages/webpack/template-webpack-plugin/test/cssDiagnostics.test.ts (1)

175-211: Add a regression case for the @cssId wrapper offset.

This validates the new pipeline, but it does not reproduce the PR’s stated failure mode: generated CSS lines shifted by wrapping extracted CSS with @cssId. Please add a case where the reported diagnostic line includes the wrapper offset and assert it maps back to the original CSS line.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/webpack/template-webpack-plugin/test/cssDiagnostics.test.ts` around
lines 175 - 211, Add a regression test that verifies processTasmCSSDiagnostics
correctly removes the `@cssId` wrapper offset when mapping diagnostics back to
original source: create a new case in cssDiagnostics.test.ts that uses
processTasmCSSDiagnostics and supplies cssDiagnostics JSON containing a
diagnostic whose "line" value includes the wrapper offset (e.g., line =
originalLine + wrapperOffset), reuse the existing sourceMap and context
'/workspace/app', and assert the returned diagnostic's sourceLine/sourceColumn
correspond to the original CSS location (originalLine and originalColumn) and
not the wrapped line; reference processTasmCSSDiagnostics, mainCSSSourceMap,
cssDiagnostics, and emittedWarnings to implement the test.
packages/webpack/template-webpack-plugin/src/LynxEncodePlugin.ts (1)

9-9: Use the shared getMainCSSSourceMap helper here too.

cssDiagnostics.ts now exports the same helper, but this plugin still calls its local duplicate. Importing the shared helper keeps future source-map fixes covered by one implementation.

♻️ Suggested refactor
-import type * as CSS from '@lynx-js/css-serializer';
-
-import { processTasmCSSDiagnostics } from './cssDiagnostics.js';
+import {
+  getMainCSSSourceMap,
+  processTasmCSSDiagnostics,
+} from './cssDiagnostics.js';

Then remove the now-duplicated local Asset, normalizeCSSSourceMap, and getMainCSSSourceMap definitions near the bottom of this file.

Also applies to: 239-244

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/webpack/template-webpack-plugin/src/LynxEncodePlugin.ts` at line 9,
The plugin currently imports processTasmCSSDiagnostics but still uses a
duplicated local implementation of getMainCSSSourceMap (and related Asset and
normalizeCSSSourceMap) instead of the shared helper; replace the local helper
usage by importing getMainCSSSourceMap from cssDiagnostics.js alongside
processTasmCSSDiagnostics in LynxEncodePlugin.ts (use the shared
getMainCSSSourceMap where the plugin currently calls its duplicate), then remove
the duplicated local definitions Asset, normalizeCSSSourceMap, and
getMainCSSSourceMap at the bottom of the file so the plugin uses the single
shared implementation.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@packages/webpack/template-webpack-plugin/src/LynxEncodePlugin.ts`:
- Line 9: The plugin currently imports processTasmCSSDiagnostics but still uses
a duplicated local implementation of getMainCSSSourceMap (and related Asset and
normalizeCSSSourceMap) instead of the shared helper; replace the local helper
usage by importing getMainCSSSourceMap from cssDiagnostics.js alongside
processTasmCSSDiagnostics in LynxEncodePlugin.ts (use the shared
getMainCSSSourceMap where the plugin currently calls its duplicate), then remove
the duplicated local definitions Asset, normalizeCSSSourceMap, and
getMainCSSSourceMap at the bottom of the file so the plugin uses the single
shared implementation.

In `@packages/webpack/template-webpack-plugin/test/cssDiagnostics.test.ts`:
- Around line 175-211: Add a regression test that verifies
processTasmCSSDiagnostics correctly removes the `@cssId` wrapper offset when
mapping diagnostics back to original source: create a new case in
cssDiagnostics.test.ts that uses processTasmCSSDiagnostics and supplies
cssDiagnostics JSON containing a diagnostic whose "line" value includes the
wrapper offset (e.g., line = originalLine + wrapperOffset), reuse the existing
sourceMap and context '/workspace/app', and assert the returned diagnostic's
sourceLine/sourceColumn correspond to the original CSS location (originalLine
and originalColumn) and not the wrapped line; reference
processTasmCSSDiagnostics, mainCSSSourceMap, cssDiagnostics, and emittedWarnings
to implement the test.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 94900325-fb2a-4026-9035-2889daeaf289

📥 Commits

Reviewing files that changed from the base of the PR and between 30f0277 and 8bc0d64.

📒 Files selected for processing (8)
  • .changeset/fix-css-id-source-map-offset.md
  • packages/webpack/css-extract-webpack-plugin/src/loader.ts
  • packages/webpack/css-extract-webpack-plugin/test/loader.test.ts
  • packages/webpack/template-webpack-plugin/etc/template-webpack-plugin.api.md
  • packages/webpack/template-webpack-plugin/src/LynxEncodePlugin.ts
  • packages/webpack/template-webpack-plugin/src/cssDiagnostics.ts
  • packages/webpack/template-webpack-plugin/src/index.ts
  • packages/webpack/template-webpack-plugin/test/cssDiagnostics.test.ts

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes incorrect CSS source map line mapping when extracted CSS is wrapped with @cssId metadata, and refactors TASM CSS diagnostics handling into a single helper for parsing + resolving + deduping.

Changes:

  • Offset extracted CSS source map mappings when wrapping emitted CSS with an @cssId header.
  • Introduce processTasmCSSDiagnostics helper and add tests for end-to-end diagnostic processing/deduping.
  • Export the new diagnostics helper/types from @lynx-js/template-webpack-plugin entrypoint and update API docs.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
packages/webpack/template-webpack-plugin/test/cssDiagnostics.test.ts Adds coverage for processTasmCSSDiagnostics from raw input to deduped, source-mapped output.
packages/webpack/template-webpack-plugin/src/index.ts Re-exports processTasmCSSDiagnostics and related types from the package entrypoint.
packages/webpack/template-webpack-plugin/src/cssDiagnostics.ts Adds processTasmCSSDiagnostics helper and a getMainCSSSourceMap utility.
packages/webpack/template-webpack-plugin/src/LynxEncodePlugin.ts Switches encode-time diagnostics pipeline to use processTasmCSSDiagnostics.
packages/webpack/template-webpack-plugin/etc/template-webpack-plugin.api.md Updates extracted public API to include the new diagnostics helper/types.
packages/webpack/css-extract-webpack-plugin/test/loader.test.ts Adds unit tests for sourcemap line-offset behavior.
packages/webpack/css-extract-webpack-plugin/src/loader.ts Implements offsetSourceMapLines and applies it when wrapping with @cssId.
.changeset/fix-css-id-source-map-offset.md Adds a patch changeset for @lynx-js/css-extract-webpack-plugin.
Comments suppressed due to low confidence (1)

packages/webpack/css-extract-webpack-plugin/src/loader.ts:235

  • The @cssId wrapper template literal includes indentation whitespace before ${content} and before the closing } (and a trailing newline). That changes the emitted CSS (adds a leading space to the first content line) and can skew source map column expectations. Consider building the wrapper string with explicit \n separators (no indentation) or otherwise ensuring no incidental whitespace is introduced.
              ? `@cssId "${cssId}" "${filePath}" {
${content}
}
`
              : content,

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/webpack/template-webpack-plugin/src/cssDiagnostics.ts
Comment thread packages/webpack/template-webpack-plugin/src/index.ts
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Apr 23, 2026

Merging this PR will degrade performance by 12.96%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

❌ 1 regressed benchmark
✅ 80 untouched benchmarks
⏩ 26 skipped benchmarks1

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
transform 1000 view elements 39.9 ms 45.9 ms -12.96%

Comparing fix/css-diagnostics-source-map (17bb077) with main (30f0277)

Open in CodSpeed

Footnotes

  1. 26 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@luhc228 luhc228 force-pushed the fix/css-diagnostics-source-map branch from 8bc0d64 to 5ebaf8d Compare April 23, 2026 07:24
@relativeci
Copy link
Copy Markdown

relativeci Bot commented Apr 23, 2026

React External

#673 Bundle Size — 679.93KiB (0%).

17bb077(current) vs 30f0277 main#664(baseline)

Bundle metrics  no changes
                 Current
#673
     Baseline
#664
No change  Initial JS 0B 0B
No change  Initial CSS 0B 0B
No change  Cache Invalidation 0% 0%
No change  Chunks 0 0
No change  Assets 3 3
No change  Modules 17 17
No change  Duplicate Modules 5 5
No change  Duplicate Code 8.59% 8.59%
No change  Packages 0 0
No change  Duplicate Packages 0 0
Bundle size by type  no changes
                 Current
#673
     Baseline
#664
No change  Other 679.93KiB 679.93KiB

Bundle analysis reportBranch fix/css-diagnostics-source-mapProject dashboard


Generated by RelativeCIDocumentationReport issue

@relativeci
Copy link
Copy Markdown

relativeci Bot commented Apr 23, 2026

React Example

#7555 Bundle Size — 225.23KiB (0%).

17bb077(current) vs 30f0277 main#7546(baseline)

Bundle metrics  no changes
                 Current
#7555
     Baseline
#7546
No change  Initial JS 0B 0B
No change  Initial CSS 0B 0B
No change  Cache Invalidation 0% 0%
No change  Chunks 0 0
No change  Assets 4 4
No change  Modules 179 179
No change  Duplicate Modules 69 69
No change  Duplicate Code 44.57% 44.57%
No change  Packages 2 2
No change  Duplicate Packages 0 0
Bundle size by type  no changes
                 Current
#7555
     Baseline
#7546
No change  IMG 145.76KiB 145.76KiB
No change  Other 79.47KiB 79.47KiB

Bundle analysis reportBranch fix/css-diagnostics-source-mapProject dashboard


Generated by RelativeCIDocumentationReport issue

@relativeci
Copy link
Copy Markdown

relativeci Bot commented Apr 23, 2026

React MTF Example

#687 Bundle Size — 196.39KiB (0%).

17bb077(current) vs 30f0277 main#678(baseline)

Bundle metrics  no changes
                 Current
#687
     Baseline
#678
No change  Initial JS 0B 0B
No change  Initial CSS 0B 0B
No change  Cache Invalidation 0% 0%
No change  Chunks 0 0
No change  Assets 3 3
No change  Modules 173 173
No change  Duplicate Modules 66 66
No change  Duplicate Code 44.07% 44.07%
No change  Packages 2 2
No change  Duplicate Packages 0 0
Bundle size by type  no changes
                 Current
#687
     Baseline
#678
No change  IMG 111.23KiB 111.23KiB
No change  Other 85.15KiB 85.15KiB

Bundle analysis reportBranch fix/css-diagnostics-source-mapProject dashboard


Generated by RelativeCIDocumentationReport issue

@relativeci
Copy link
Copy Markdown

relativeci Bot commented Apr 23, 2026

Web Explorer

#9127 Bundle Size — 900.11KiB (0%).

17bb077(current) vs 30f0277 main#9118(baseline)

Bundle metrics  Change 1 change
                 Current
#9127
     Baseline
#9118
No change  Initial JS 44.46KiB 44.46KiB
No change  Initial CSS 2.22KiB 2.22KiB
Change  Cache Invalidation 0% 11.72%
No change  Chunks 9 9
No change  Assets 11 11
Change  Modules 229(+0.44%) 228
No change  Duplicate Modules 11 11
No change  Duplicate Code 27.29% 27.29%
No change  Packages 10 10
No change  Duplicate Packages 0 0
Bundle size by type  no changes
                 Current
#9127
     Baseline
#9118
No change  JS 495.97KiB 495.97KiB
No change  Other 401.92KiB 401.92KiB
No change  CSS 2.22KiB 2.22KiB

Bundle analysis reportBranch fix/css-diagnostics-source-mapProject dashboard


Generated by RelativeCIDocumentationReport issue

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
packages/webpack/css-extract-webpack-plugin/src/loader.ts (1)

309-321: offsetSourceMapLines silently no-ops on indexed source maps.

The function only shifts when sourceMap.mappings is truthy. For indexed source maps (which use a top-level sections array instead of mappings), the map is returned unchanged and the offset is not applied — any diagnostics against an indexed map would still point to the wrong lines. In practice, css-loader emits non-indexed RawSourceMap objects, so this is unlikely to be hit today, but a short comment (or an explicit guard) would make the assumption clear for future callers.

🧹 Suggested hardening
 export function offsetSourceMapLines<T extends DependencySourceMap>(
   sourceMap: T,
   lineOffset: number,
 ): T {
-  if (lineOffset <= 0 || !sourceMap.mappings) {
+  // Note: indexed source maps (with `sections`) are not supported here;
+  // css-loader emits standard RawSourceMap objects with a `mappings` string.
+  if (lineOffset <= 0 || typeof sourceMap.mappings !== 'string' || sourceMap.mappings.length === 0) {
     return sourceMap;
   }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/webpack/css-extract-webpack-plugin/src/loader.ts` around lines 309 -
321, The function offsetSourceMapLines currently only adjusts source maps that
have a top-level mappings string and silently no-ops for indexed source maps
(those with a top-level sections array); update offsetSourceMapLines to
explicitly detect indexed maps (check for a sections property on the incoming
DependencySourceMap) and either apply an appropriate handling strategy (e.g.,
throw a clear error/warning indicating indexed maps are unsupported) or document
the assumption with a concise comment near offsetSourceMapLines and add a guard
that returns early while making the unsupported case explicit; reference the
function name offsetSourceMapLines and the DependencySourceMap type when adding
the guard/comment so future maintainers see the intended behavior for indexed
maps.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@packages/webpack/css-extract-webpack-plugin/src/loader.ts`:
- Around line 309-321: The function offsetSourceMapLines currently only adjusts
source maps that have a top-level mappings string and silently no-ops for
indexed source maps (those with a top-level sections array); update
offsetSourceMapLines to explicitly detect indexed maps (check for a sections
property on the incoming DependencySourceMap) and either apply an appropriate
handling strategy (e.g., throw a clear error/warning indicating indexed maps are
unsupported) or document the assumption with a concise comment near
offsetSourceMapLines and add a guard that returns early while making the
unsupported case explicit; reference the function name offsetSourceMapLines and
the DependencySourceMap type when adding the guard/comment so future maintainers
see the intended behavior for indexed maps.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 4ecbe8c4-e402-4fff-84cb-d87bbc7e1b81

📥 Commits

Reviewing files that changed from the base of the PR and between 8bc0d64 and 5ebaf8d.

📒 Files selected for processing (8)
  • .changeset/fix-css-id-source-map-offset.md
  • packages/webpack/css-extract-webpack-plugin/src/loader.ts
  • packages/webpack/css-extract-webpack-plugin/test/loader.test.ts
  • packages/webpack/template-webpack-plugin/etc/template-webpack-plugin.api.md
  • packages/webpack/template-webpack-plugin/src/LynxEncodePlugin.ts
  • packages/webpack/template-webpack-plugin/src/cssDiagnostics.ts
  • packages/webpack/template-webpack-plugin/src/index.ts
  • packages/webpack/template-webpack-plugin/test/cssDiagnostics.test.ts
✅ Files skipped from review due to trivial changes (3)
  • .changeset/fix-css-id-source-map-offset.md
  • packages/webpack/css-extract-webpack-plugin/test/loader.test.ts
  • packages/webpack/template-webpack-plugin/src/index.ts
🚧 Files skipped from review as they are similar to previous changes (3)
  • packages/webpack/template-webpack-plugin/test/cssDiagnostics.test.ts
  • packages/webpack/template-webpack-plugin/etc/template-webpack-plugin.api.md
  • packages/webpack/template-webpack-plugin/src/cssDiagnostics.ts

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

packages/webpack/css-extract-webpack-plugin/src/loader.ts:235

  • The @cssId wrapper template literal includes indentation whitespace before ${content} and before the closing }. That alters the emitted CSS and can shift generated column positions, while offsetSourceMapLines only adjusts line mappings. Build the wrapper string without incidental indentation (or explicitly control it) so the wrapped output and source-map offsets stay accurate.
              ? `@cssId "${cssId}" "${filePath}" {
${content}
}
`
              : content,

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread .changeset/fix-css-id-source-map-offset.md
@luhc228 luhc228 force-pushed the fix/css-diagnostics-source-map branch from 5ebaf8d to 17bb077 Compare April 23, 2026 07:58
@luhc228 luhc228 enabled auto-merge (squash) April 23, 2026 07:58
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/webpack/css-extract-webpack-plugin/src/loader.ts (1)

178-188: ⚠️ Potential issue | 🟠 Major

Use the effective dependency cssId for wrapping and source-map offsetting.

Line 178 preserves an existing cssId on the dependency, but Lines 186 and 231 still use the parent cssId. That can emit an identifier with one CSS id while wrapping with another, or skip wrapping/offsetting when only the dependency has cssId.

🐛 Proposed fix
         if (params.get('cssId') === null) {
           params.set('cssId', cssId);
         }
+        const dependencyCssId = params.get('cssId') ?? '';

         const filePath = path.relative(
           this.rootContext,
           extractPathFromIdentifier(identifier)!,
         );
-        const shouldWrapCSSId = Boolean(cssId)
+        const shouldWrapCSSId = Boolean(dependencyCssId)
           && (params.get('common') === null
             || params.get('common') === 'false');
-              ? `@cssId "${cssId}" "${filePath}" {
+              ? `@cssId "${dependencyCssId}" "${filePath}" {
 ${content}
 }
 `

Also applies to: 231-244

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/webpack/css-extract-webpack-plugin/src/loader.ts` around lines 178 -
188, Compute and use the effective dependency cssId (prefer the existing
params.get('cssId') if present, otherwise fall back to the parent cssId) instead
of always using the parent cssId; i.e., derive a variable like effectiveCssId =
params.get('cssId') ?? cssId and use effectiveCssId wherever the code currently
uses cssId for decisions and transformations (specifically for shouldWrapCSSId
logic and the source-map offsetting/wrapping code referenced around the later
block that currently uses cssId), ensuring you update uses in the
shouldWrapCSSId calculation and the source-map offset/wrap section (the code
using params, cssId, extractPathFromIdentifier and the wrapping/offset logic) to
reference effectiveCssId.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@packages/webpack/css-extract-webpack-plugin/src/loader.ts`:
- Around line 178-188: Compute and use the effective dependency cssId (prefer
the existing params.get('cssId') if present, otherwise fall back to the parent
cssId) instead of always using the parent cssId; i.e., derive a variable like
effectiveCssId = params.get('cssId') ?? cssId and use effectiveCssId wherever
the code currently uses cssId for decisions and transformations (specifically
for shouldWrapCSSId logic and the source-map offsetting/wrapping code referenced
around the later block that currently uses cssId), ensuring you update uses in
the shouldWrapCSSId calculation and the source-map offset/wrap section (the code
using params, cssId, extractPathFromIdentifier and the wrapping/offset logic) to
reference effectiveCssId.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: f7008649-c377-4f3a-aad1-7c2f2e7626a5

📥 Commits

Reviewing files that changed from the base of the PR and between 5ebaf8d and 17bb077.

📒 Files selected for processing (9)
  • .changeset/fix-css-id-source-map-offset.md
  • packages/webpack/css-extract-webpack-plugin/src/loader.ts
  • packages/webpack/css-extract-webpack-plugin/test/loader.test.ts
  • packages/webpack/template-webpack-plugin/etc/template-webpack-plugin.api.md
  • packages/webpack/template-webpack-plugin/src/LynxEncodePlugin.ts
  • packages/webpack/template-webpack-plugin/src/cssDiagnostics.ts
  • packages/webpack/template-webpack-plugin/src/index.ts
  • packages/webpack/template-webpack-plugin/test/cases/code-splitting/initial-css-order/rspack.config.js
  • packages/webpack/template-webpack-plugin/test/cssDiagnostics.test.ts
✅ Files skipped from review due to trivial changes (5)
  • packages/webpack/template-webpack-plugin/test/cases/code-splitting/initial-css-order/rspack.config.js
  • .changeset/fix-css-id-source-map-offset.md
  • packages/webpack/template-webpack-plugin/src/index.ts
  • packages/webpack/css-extract-webpack-plugin/test/loader.test.ts
  • packages/webpack/template-webpack-plugin/src/cssDiagnostics.ts
🚧 Files skipped from review as they are similar to previous changes (3)
  • packages/webpack/template-webpack-plugin/test/cssDiagnostics.test.ts
  • packages/webpack/template-webpack-plugin/etc/template-webpack-plugin.api.md
  • packages/webpack/template-webpack-plugin/src/LynxEncodePlugin.ts

@luhc228 luhc228 merged commit 13655ac into main Apr 23, 2026
39 of 41 checks passed
@luhc228 luhc228 deleted the fix/css-diagnostics-source-map branch April 23, 2026 08:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants