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: When hmr=none,mako does not take effect #1552

Merged
merged 1 commit into from
Aug 30, 2024

Conversation

Wu-kung
Copy link
Contributor

@Wu-kung Wu-kung commented Aug 30, 2024

#1545 @stormslowly @sorrycc

Summary by CodeRabbit

  • 新特性
    • 根据环境变量 HMR 的设置,动态控制热模块替换(HMR)的启用或禁用。
  • 样式
    • 改进了代码的可读性,通过调整字符串的缩进。

Copy link
Contributor

coderabbitai bot commented Aug 30, 2024

Warning

Rate limit exceeded

@Wu-kung has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 7 minutes and 12 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

Commits

Files that changed from the base of the PR and between 5da4311 and 770c6a7.

Walkthrough

此次更改涉及对 packages/bundler-mako/index.js 文件中 dev 函数内 hmr(热模块替换)配置的处理。新逻辑根据环境变量 HMR 的值来决定 makoConfig.hmr 的状态,从而影响开发服务器的模块替换行为。此外,checkConfig 函数中的字符串缩进也进行了小幅调整,以提高代码的可读性。

Changes

文件路径 变更摘要
packages/bundler-mako/index.js 修改 dev 函数逻辑以条件性设置 makoConfig.hmr,并调整 checkConfig 函数中的字符串缩进。

Sequence Diagram(s)

sequenceDiagram
    participant Developer
    participant Environment
    participant MakoConfig

    Developer->>Environment: 设置 HMR 环境变量
    Environment->>MakoConfig: 读取 HMR 值
    alt HMR = 'none'
        MakoConfig->>MakoConfig: 设置 hmr 为 false
    else HMR != 'none'
        MakoConfig->>MakoConfig: 保持 hmr 为 {}
    end
Loading

Poem

在草地上跳跃的小兔,
新逻辑让我心欢喜,
热模块替换随意切换,
代码整齐如春日,
让我们一起欢呼吧,
代码更美,开发更快! 🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
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.
    • @coderabbitai help me debug CodeRabbit configuration file.

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 using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration 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 aad4580 and 54498d5.

Files selected for processing (1)
  • packages/bundler-mako/index.js (2 hunks)
Additional comments not posted (1)
packages/bundler-mako/index.js (1)

201-205: 优化 HMR 配置处理

根据环境变量 HMR 的值来决定 hmr 的配置,当 HMR 设置为 'none' 时,hmr 被设置为 false,否则保持为空对象。这一改动符合 PR 的目标,确保在禁用 HMR 的情况下 Mako 能正常工作。

代码更改已批准。

建议添加注释说明这一逻辑,以便未来维护时能快速理解代码意图。

请验证当环境变量 HMR 未设置或设置为其他值时,此逻辑的行为是否符合预期。

Copy link
Member

@stormslowly stormslowly left a comment

Choose a reason for hiding this comment

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

lgtm

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 54498d5 and c614a12.

Files selected for processing (1)
  • packages/bundler-mako/index.js (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • packages/bundler-mako/index.js

@sorrycc
Copy link
Member

sorrycc commented Aug 30, 2024

不要用 force push,代码改动咋没了。

image

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 c614a12 and 5da4311.

Files selected for processing (1)
  • packages/bundler-mako/index.js (1 hunks)
Additional comments not posted (1)
packages/bundler-mako/index.js (1)

201-205: 审查 hmr 配置的修改

代码正确地根据环境变量 HMR 的值来设置 hmr 属性。当 HMR 设置为 "none" 时,hmr 被设置为 false,否则为一个空对象。这样的改动可以有效地根据开发者的需求启用或禁用 HMR 功能。

代码更改已被批准。

建议在不同的 HMR 设置下验证此行为,确保功能按预期工作。

Verification successful

确认 hmr 配置的实现

代码正确地实现了 hmr 配置逻辑,符合预期行为。当环境变量 HMR 设置为 "none" 时,hmr 被设置为 false,否则为一个空对象。无需进一步修改。

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the behavior of the `hmr` configuration with different `HMR` settings.

# Test: Run the server with different `HMR` settings and check the `hmr` property.
echo "Testing with HMR=none"
export HMR=none
node packages/bundler-mako/index.js
echo "Testing with HMR=auto"
export HMR=auto
node packages/bundler-mako/index.js

Length of output: 384


Script:

#!/bin/bash
# Use ast-grep to search for the `hmr` configuration logic in the codebase.
ast-grep --lang javascript --pattern $'if (process.env.HMR === "none") {
  $_.hmr = false;
} else {
  $_.hmr = {};
}'

Length of output: 118


Script:

#!/bin/bash
# Use rg to search for occurrences of `process.env.HMR` in the codebase.
rg 'process.env.HMR' -A 3

Length of output: 249

@Wu-kung
Copy link
Contributor Author

Wu-kung commented Aug 30, 2024

不要用 force push,代码改动咋没了。

image

觉着 commits 冗余,rebase 误操作了。已重新提交。

@sorrycc
Copy link
Member

sorrycc commented Aug 30, 2024

merge 时会 squash,分支的 commit 不会印象到 master 分支的。

@sorrycc sorrycc merged commit 8b79017 into umijs:master Aug 30, 2024
14 of 15 checks passed
Copy link

codecov bot commented Aug 30, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 61.63%. Comparing base (aad4580) to head (770c6a7).
Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1552   +/-   ##
=======================================
  Coverage   61.63%   61.63%           
=======================================
  Files         127      127           
  Lines       15294    15294           
=======================================
  Hits         9427     9427           
  Misses       5867     5867           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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.

3 participants