Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: duplicated assets info in watch mode #1194

Merged
merged 2 commits into from
May 23, 2024

Conversation

xusd320
Copy link
Contributor

@xusd320 xusd320 commented May 22, 2024

  1. Close bug: duplicated chunk files in stats.json of dev mode #1132;
  2. Refact assets_info, narrow scopes of mutex.

Summary by CodeRabbit

  • 新功能

    • 简化了 StatsInfo 的处理,移除了对 Mutex 的需求,提升了代码的可读性和可维护性。
    • 在开发服务器中,添加了在发出开发块之前清除资产的调用。
    • StatsInfo 添加了新的方法,用于添加、清除和获取资产、客户端组件和 CSS 模块。
  • 改进

    • 更新了多个方法以使用新的 StatsInfo 方法,提升了代码的逻辑和控制流。
    • 改进了 ManifestPluginbuild_success 方法,现在通过新的方法 get_assets() 访问资产。

Copy link
Contributor

coderabbitai bot commented May 22, 2024

Walkthrough

这次更改主要是简化了 StatsInfo 的处理,通过移除 Mutex 包装器,直接在 Context 结构体中使用 StatsInfo。此外,还在 DevServer 实现中添加了对 clear_assets() 的调用,以解决开发模式下的冗余文件问题。

Changes

文件路径 更改摘要
crates/mako/src/compiler.rs Context 结构体中的 stats_infoMutex<StatsInfo> 改为 StatsInfo,并相应地更新了 DefaultCompiler 实现。
crates/mako/src/dev/mod.rs DevServer 实现中,添加了对 compiler.context.stats_info.clear_assets() 的调用。
crates/mako/src/features/rsc.rs 将对 context.stats_info 的直接访问替换为方法调用,以添加组件和模块。
crates/mako/src/generate/mod.rs 简化了对 stats_info 的访问,移除了每次访问时锁定和解锁的需求。
crates/mako/src/plugins/manifest.rs 更新了 build_success 方法,使用 get_assets() 方法来访问资源。
crates/mako/src/stats.rs 更新了 StatsInfo 结构体,使用 Mutex 包装向量,并添加了处理资源、客户端组件和 CSS 模块的方法。

Assessment against linked issues

目标 Addressed Explanation
解决开发模式下 stats.json 中冗余的 chunk 文件问题(#1132

在代码的世界里,改动如春风,
锁定的心情,变得轻松。
统计信息,不再冗重,
开发模式,清爽如风。


Note

Free review on us!

CodeRabbit is offering free reviews until Mon May 27 2024 to showcase some of the refinements we've made.

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
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.

Actionable comments posted: 0

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 7dd662c and c8d8b04.
Files selected for processing (6)
  • crates/mako/src/compiler.rs (3 hunks)
  • crates/mako/src/dev/mod.rs (1 hunks)
  • crates/mako/src/features/rsc.rs (2 hunks)
  • crates/mako/src/generate/mod.rs (6 hunks)
  • crates/mako/src/plugins/manifest.rs (1 hunks)
  • crates/mako/src/stats.rs (9 hunks)
Files skipped from review due to trivial changes (2)
  • crates/mako/src/dev/mod.rs
  • crates/mako/src/generate/mod.rs
Additional comments not posted (4)
crates/mako/src/plugins/manifest.rs (1)

26-26: 使用 get_assets() 方法来获取资产,这样可以更好地封装资产检索逻辑,提高代码的可维护性。

crates/mako/src/features/rsc.rs (1)

67-68: 通过使用 add_rsc_client_componentadd_rsc_css_module 方法来添加组件和模块,代码更加清晰,也便于管理。

Also applies to: 88-88

crates/mako/src/compiler.rs (1)

35-35: 移除 Mutex<StatsInfo>,直接使用 StatsInfo,简化了代码并可能提高了性能。请确保这一改动不会影响到多线程场景下的线程安全。

Also applies to: 121-121, 315-315

crates/mako/src/stats.rs (1)

45-83: 添加了多个方法来管理资产和组件,如 add_assets, clear_assets, get_assets 等,这些改动有助于封装逻辑,提高代码的可维护性和模块化。

@sorrycc sorrycc merged commit f05ac45 into master May 23, 2024
8 checks passed
@delete-merged-branch delete-merged-branch bot deleted the fix/duplicated_assets_info_in_watch_mode branch May 23, 2024 03:23
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.

bug: duplicated chunk files in stats.json of dev mode
3 participants