turbopack: move CSS module composes validation from code generation to resolving - #92582
Merged
Merged
Conversation
… phase CssModuleComposesIssue was only emitted during chunk_item_content() (code generation), which meant get_compilation_issues (module graph only) could not surface these errors. Move the validation into module_references() so it runs during graph building. Add e2e test with a CSS module composing from a .txt file to verify the issue is detected. Co-Authored-By: Claude <noreply@anthropic.com>
Merging this PR will not alter performance
Comparing Footnotes
|
Contributor
Stats from current PR✅ No significant changes detected📊 All Metrics📖 Metrics GlossaryDev Server Metrics:
Build Metrics:
Change Thresholds:
⚡ Dev Server
📦 Dev Server (Webpack) (Legacy)📦 Dev Server (Webpack)
⚡ Production Builds
📦 Production Builds (Webpack) (Legacy)📦 Production Builds (Webpack)
📦 Bundle SizesBundle Sizes⚡ TurbopackClient Main Bundles
Server Middleware
Build DetailsBuild Manifests
📦 WebpackClient Main Bundles
Polyfills
Pages
Server Edge SSR
Middleware
Build DetailsBuild Manifests
Build Cache
🔄 Shared (bundler-independent)Runtimes
📎 Tarball URL |
…::resolve_reference Instead of validating in module_references(), move the logic into the reference itself. Introduce a CssModuleComposable marker trait in compose.rs; EcmascriptCssModule implements it. resolve_reference() now validates both cases (unresolvable + non-CSS-module target) and emits CssModuleComposesIssue directly, making the issue available during module graph traversal (e.g. get_compilation_issues) without coupling the validation to the consumer (module_references or codegen). Co-Authored-By: Claude <noreply@anthropic.com>
sokra
marked this pull request as ready for review
April 10, 2026 10:47
mischnic
reviewed
Apr 10, 2026
Both types live in the same crate, so compose.rs can import EcmascriptCssModule directly. The marker trait and its impl were unnecessary indirection. Co-Authored-By: Claude <noreply@anthropic.com>
mischnic
approved these changes
Apr 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What?
Move the validation that can produce
CssModuleComposesIssuefrom code generation (chunk_item_content) to the reference's ownresolve_reference()method, so these errors are surfaced during resolving rather than only during bundling.Two validation checks are moved into
CssModuleComposeReference::resolve_reference():composes: ... from "...";target module can't be resolved (unresolvable reference)composes: ... from "...";target module is not a CSS module (e.g. composing from a.jsor.txtfile)The
IssueStageis updated fromCodeGentoResolveto reflect the new phase.Code generation still handles the error cases gracefully (skipping broken references with
continue) — it just no longer re-emits the issue since it is already emitted byresolve_reference().Why?
get_compilation_issues(used by the MCP server and other tooling) only builds the module graph — it does not run code generation. Previously, bothCssModuleComposesIssuevariants were only emitted duringchunk_item_content(), which meant they were invisible toget_compilation_issues. Developers using the MCPget_compilation_issuestool would not see errors from brokencomposesreferences until an actual build/bundle was triggered.Since
resolve_reference()is called as part of module graph traversal, emitting the issue there means it is captured byget_compilation_issuesalongside other resolve-phase errors.How?
turbopack-css/src/references/compose.rsCssModuleComposeReference::resolve_reference()is changed fromfntoasync fn. It callscss_resolveas before, then awaitsfirst_module()on the result and validates:CssModuleComposable→ emit "not a CSS module" issueCssModuleComposesIssueand itsIssueimpl are moved here frommodule_asset.rs, now usingResolvedVc<FileSystemPath>(fromorigin_path()) as the issue location rather than theIssueSourceof the composing file.CssModuleComposablemarker trait (#[turbo_tasks::value_trait]) is defined here.resolve_reference()uses atry_sidecastto this trait to check whether the resolved module is a valid compose target — avoiding a hard dependency onEcmascriptCssModulefrom withincompose.rs.turbopack-css/src/module_asset.rsEcmascriptCssModuleimplementsCssModuleComposable, marking it as a validcomposes:target.module_references()is reverted to its original simple form — it only collects references without any validation.Issue,IssueExt,IssueSource, etc.) are removed.Test fixtures (
test/development/mcp-server/fixtures/compilation-errors-app/app/css-composes-error/)styles.module.css— CSS module withcomposes: something from './not-a-css-module.txt'not-a-css-module.txt— a plain text file (resolves but is not a CSS module)page.tsx— page importing the broken CSS moduletest/development/mcp-server/mcp-server-get-compilation-issues.test.tsshould detect CSS module composes errorsverifies the issue is surfaced viaget_compilation_issues.