Skip to content

Conversation

@fireairforce
Copy link
Contributor

@fireairforce fireairforce commented Sep 5, 2025

Summary

一个 loader 重命名的 bug fix,以 less 修改作为例子:

image

以前的 rename 逻辑会把整个模块全 rename 成 .module.css,举个例子:

style.module.less 过 less-loader 的时候会变成 .module.css(这里如果是 css modules 还好,因为后面有个根据 content 生成的 hashName,那肯定不会冲突),如果是个这样的 case:

import './index.less';
import './index2.less';

这两个 module 会直接冲突,具体表现行为大概是在 module_graph 里面这两个是一个东西:

image

不过这里 turbopack 也有点小问题,他这里的行为是:

index.less -> index.less.css 实际上 rename 成 index.css 会更省体积?后续可以简单优化一下。

Test Plan

快照测试更新了。

Copilot AI review requested due to automatic review settings September 5, 2025 08:00
Copy link
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

This PR fixes a loader renaming bug in the less-loader and style-loader where modules were being incorrectly renamed, causing conflicts in the module graph. The fix changes the rename logic from using dot prefixes (which stripped filename information) to asterisk wildcards (which preserve the original filename).

  • Fixed less-loader rename patterns from .module.css/.css to *.module.css/*.css
  • Updated corresponding test snapshots to reflect the corrected module naming
  • Updated next.js submodule commit reference

Reviewed Changes

Copilot reviewed 5 out of 7 changed files in this pull request and generated no comments.

Show a summary per file
File Description
next.js Updates submodule commit reference
crates/pack-core/src/shared/webpack_rules/less.rs Fixes less-loader rename patterns to preserve original filenames
crates/pack-tests/tests/snapshot/style/css_modules/output/main.js Updates test snapshot with corrected CSS chunk filename
crates/pack-tests/tests/snapshot/style/css_modules/output/crates_pack-tests_tests_snapshot_style_css_modules_input_db4c60c6.css Updates CSS output with proper module names and source paths
crates/pack-tests/tests/snapshot/style/css_modules/output/crates_pack-tests_tests_snapshot_style_css_modules_input_a4667d8f.js Updates JS output with corrected CSS class names

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Summary of Changes

Hello @fireairforce, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

此拉取请求旨在解决 CSS 预处理器(如 Less)在模块重命名过程中存在的关键错误。通过修正重命名逻辑,它避免了在处理具有相似名称的多个文件时可能发生的命名冲突,从而确保了构建系统中正确的模块解析和避免了意外行为。

Highlights

  • 重命名逻辑修复: 修复了 less-loaderstyle-loader 的重命名逻辑错误,解决了旧逻辑将整个模块重命名为 .module.css 导致的文件冲突问题。
  • 模块冲突解决: 确保了重命名时保留完整文件名,从而避免了在模块图中因 index.lessindex2.less 等文件而产生的冲突。
  • 快照测试更新: 更新了快照测试以反映修复后的正确行为和输出。
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

本次 PR 修复了 less-loader 重命名逻辑中的一个错误,该错误可能导致模块名冲突。您通过在重命名模式中添加 * 来保留基本文件名,这是一个正确的修复方法。快照测试的更新也充分验证了修复的效果。代码实现清晰,干得漂亮!

@xusd320 xusd320 changed the title fix(pack): less-loader & style-loader rename logic [WIP] fix(pack): less-loader & style-loader rename logic Sep 5, 2025
@fireairforce fireairforce changed the title [WIP] fix(pack): less-loader & style-loader rename logic [WIP] fix(pack): less-loader rename logic Sep 5, 2025
@xusd320 xusd320 changed the title [WIP] fix(pack): less-loader rename logic fix(pack): less-loader rename logic Sep 5, 2025
@xusd320 xusd320 merged commit b76d801 into next Sep 5, 2025
5 of 6 checks passed
@xusd320 xusd320 deleted the fix-sass-modules-rename branch September 5, 2025 12:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants