Skip to content

Conversation

@weareoutman
Copy link
Member

@weareoutman weareoutman commented Feb 14, 2025

依赖检查

组件之间的依赖声明,是微服务组件架构下的重要信息,请确保其正确性。

请勾选以下两组选项其中之一:

  • 本次 MR 没有使用上游组件(例如框架、后台组件等)的较新版本提供的特性。

或者:

  • 本次 MR 使用了上游组件(例如框架、后台组件等)的较新版本提供的特性。
  • 在对应的文件中更新了该上游组件的依赖版本(或确认了当前声明的依赖版本已包含本次 MR 使用的新特性)。

提交信息检查

Git 提交信息将决定包的版本发布及自动生成的 CHANGELOG,请检查工作内容与提交信息是否相符,并在以下每组选项中都依次确认。

破坏性变更是针对于下游使用者而言,可以通过本次改动对下游使用者的影响来识别变更类型:

  • 下游使用者不做任何改动,仍可以正常工作时,那么它属于普通变更。
  • 反之,下游使用者不做改动就无法正常工作时,那么它属于破坏性变更。

例如,构件修改了一个属性名,小产品 Storyboard 中需要使用新属性名才能工作,那么它就是破坏性变更。
又例如,构件还没有任何下游使用者,那么它的任何变更都是普通变更。

破坏性变更:

  • ⚠️ 本次 MR 包含破坏性变更的提交,请继续确认以下所有选项:
  • 没有更好的兼容方案,必须做破坏性变更。
  • 使用了 feat 作为提交类型。
  • 标注了 BREAKING CHANGE: 你的变更说明
  • 同时更新了本仓库中所有下游使用者的调用。
  • 同时更新了本仓库中所有下游使用者对该子包的依赖为即将发布的 major 版本。
  • 同时为其它仓库的 Migrating 做好了准备,例如文档或批量改动的方法。
  • 手动验证过破坏性变更在 Migrate 后可以正常工作。
  • 破坏性变更所在的提交没有意外携带其它子包的改动。

新特性:

  • 本次 MR 包含新特性的提交,且该提交不带有破坏性变更,并使用了 feat 作为提交类型。
  • 给新特性添加了单元测试。
  • 手动验证过新特性可以正常工作。

问题修复:

  • 本次 MR 包含问题修复的提交,且该提交不带有新特性或破坏性变更,并使用了 fix 作为提交类型。
  • 给问题修复添加了单元测试。
  • 手动验证过问题修复得到解决。

杂项工作:

即所有对下游使用者无任何影响、且没有必要显示在 CHANGELOG 中的改动,例如修改注释、测试用例、开发文档等:

  • 本次 MR 包含杂项工作的提交,且该提交不带有问题修复、新特性或破坏性变更,并使用了 chore, docs, test 等作为提交类型。

Summary by CodeRabbit

  • 新功能

    • 增加对 HTTP 区间请求的支持,提升大文件或部分内容的传输效率。
  • 重构

    • 简化并统一了静态资源的服务流程,优化了砖块预览资源的处理方式。
    • 优化了构建配置和中间件逻辑,移除冗余依赖,提升整体性能和一致性。

@coderabbitai
Copy link

coderabbitai bot commented Feb 14, 2025

Walkthrough

此次提交在多个包中做出了调整,涉及 Webpack 优化配置、中间件逻辑以及辅助工具包的扩展。主要改动包括在 brick-container 中重构缓存组配置;在 brick-container 和 brick-playground 中统一使用 serveBricks 函数替代传统的静态文件服务方式;在 serve-helpers 中更新了类型定义、扩展了公共 API,并增强了文件服务逻辑以支持 HTTP 范围请求。

Changes

文件(s) 变更说明
packages/brick-container/build.config.js 移除了多个缓存组(defaultVendors、core、default),并新增了统一的 all 缓存组,调整了优化配置。
packages/brick-container/serve/middlewares/getMiddlewares.js 更新中间件定义:将 req 改为 _req,去除 localBrickFolders,并由静态服务切换为使用 serveBricksserveBricksWithVersions
packages/brick-playground/…/start.js
packages/brick-playground/…/index.js
移除 express 静态服务逻辑,改为统一调用 serveBricks 提供静态资源服务。
packages/serve-helpers/…
(index.d.ts, src/index.js, src/serveBricks.js, src/tryFiles.js)
在类型定义中增加 NextFunction,新增并导出 serveBricks 函数,同时在 tryServeFiles 中加入对 HTTP 范围请求的处理及 sendMultiRanges 实现。

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

packages/brick-playground/scripts/start.js

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the config "@next-core/eslint-config-next" to extend from. Please check that the name of the config is correct.

The config "@next-core/eslint-config-next" was referenced from the config file in "/.eslintrc".

If you still have problems, please stop by https://eslint.org/chat/help to chat with the team.

packages/brick-container/build.config.js

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the config "@next-core/eslint-config-next" to extend from. Please check that the name of the config is correct.

The config "@next-core/eslint-config-next" was referenced from the config file in "/.eslintrc".

If you still have problems, please stop by https://eslint.org/chat/help to chat with the team.

packages/serve-helpers/index.d.ts

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the config "@next-core/eslint-config-next" to extend from. Please check that the name of the config is correct.

The config "@next-core/eslint-config-next" was referenced from the config file in "/.eslintrc".

If you still have problems, please stop by https://eslint.org/chat/help to chat with the team.

  • 5 others
✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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

@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: 1

🧹 Nitpick comments (4)
packages/serve-helpers/src/tryFiles.js (1)

42-76: 建议验证区间有效性并处理流错误
sendMultiRanges 函数中,对所有区间均直接解析后使用 createReadStream。若请求区间越界(如 start 大于 end 或超出文件大小),没有显式报错处理。同时,在管道传输过程中若出现错误或连接中断,也缺少监听与对应处理逻辑。建议在本函数中或调用层添加以下改进:

  1. 验证区间有效性,若存在越界或无效区间则返回 416(Requested Range Not Satisfiable)或进行相应提示。
  2. 监听流错误事件并在错误时及时中止传输,释放资源,以增强健壮性。
packages/serve-helpers/src/serveBricks.js (1)

25-25: 建议增加错误处理

tryServeFiles 执行失败时,应该有适当的错误处理机制。

建议添加错误处理:

-    tryServeFiles(files, req, res, next);
+    try {
+      tryServeFiles(files, req, res, next);
+    } catch (error) {
+      console.error('Error serving brick files:', error);
+      next(error);
+    }
packages/brick-playground/scripts/start.js (1)

6-6: 中间件配置简化且合理!

使用 serveBricks 替换了原有的 express.static 配置,使中间件设置更加简洁。建议添加日志记录以便于调试。

建议添加调试日志:

 middlewares.push({
   path: "/preview/bricks/",
   middleware: serveBricks({ localBrickFolders }),
 });
+console.log('Registered brick serving middleware for folders:', localBrickFolders);

Also applies to: 55-58

packages/brick-container/build.config.js (1)

124-127: 缓存组配置优化合理!

新增的 all 缓存组配置具有以下优点:

  • 优先级设置为 -10,低于 mockdate 缓存组,确保特定模块优先被处理
  • 配置简单明了,易于维护

建议考虑添加注释说明此缓存组的用途。

 all: {
+  // 通用缓存组,用于处理所有其他模块的分块
   priority: -10,
   name: "all",
 },
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d647a7e and 12c3d95.

📒 Files selected for processing (9)
  • packages/brick-container/build.config.js (1 hunks)
  • packages/brick-container/serve/middlewares/getMiddlewares.js (7 hunks)
  • packages/brick-playground/scripts/start.js (2 hunks)
  • packages/brick-playground/serve/examplesJson.js (1 hunks)
  • packages/brick-playground/serve/index.js (2 hunks)
  • packages/serve-helpers/index.d.ts (2 hunks)
  • packages/serve-helpers/src/index.js (1 hunks)
  • packages/serve-helpers/src/serveBricks.js (1 hunks)
  • packages/serve-helpers/src/tryFiles.js (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: build (20.x)
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (8)
packages/serve-helpers/src/index.js (1)

3-3: 确认命名冲突与循环引用
使用 export * from "./serveBricks.js"; 时,请确保不会造成与已有导出实体命名冲突,也要避免循环引用等风险。建议查看本模块内其他导出,确认不会造成重复命名或循环依赖。

packages/brick-playground/serve/examplesJson.js (1)

13-13: 验证新路径是否可用
此处将路径指向 ../next-bricks/bricks,请确认该目录在所有运行环境中均存在且包含所需的示例文件。若不存在,会导致 getExamples 返回空或报错,建议在读取前进行目录存在性检查或在调用端处理异常。

packages/serve-helpers/index.d.ts (1)

1-1: 类型定义清晰且符合 Express 中间件模式!

类型定义准确地反映了 Express 中间件的函数签名,并且参数类型完整。

Also applies to: 22-24

packages/serve-helpers/src/serveBricks.js (1)

22-24: 建议增加路径安全性检查

当前实现在处理请求路径时可能存在路径遍历漏洞。

建议添加路径验证以防止目录遍历攻击:

 return function (req, res, next) {
+  const normalizedPath = path.normalize(req.path).replace(/^(\.\.[\/\\])+/, '');
   const files = localBrickFolders.map((dir) =>
-    path.join(dir, req.path.split("/").join(path.sep))
+    path.join(dir, normalizedPath.split("/").join(path.sep))
   );
   tryServeFiles(files, req, res, next);
 };
packages/brick-playground/serve/index.js (1)

7-7: 代码重构改进了静态文件服务的实现!

使用 serveBricks 替换原有的静态文件服务实现,使代码更加简洁和统一。

Also applies to: 50-50

packages/brick-container/serve/middlewares/getMiddlewares.js (3)

7-7: 导入语句正确添加!

@next-core/serve-helpers 导入 serveBricks 函数的做法正确,这与其他中间件导入保持一致。


37-37: 参数命名优化得当!

使用 _req 替代 req 作为未使用参数的命名是一个很好的实践,它明确表示该参数在函数中未被使用。

Also applies to: 48-48, 57-57


111-114: 中间件配置合理!

新增的中间件配置正确:

  • 路径使用 baseHref 构建,保持了一致性
  • 使用新的 serveBricks 函数处理请求

@cypress
Copy link

cypress bot commented Feb 14, 2025

next-core    Run #10936

Run Properties:  status check passed Passed #10936  •  git commit 9a04b98dc5 ℹ️: Merge 226a728f69c20839c5a39df10ae5e624b2ccadf5 into d647a7e21f334279b24664c4df40...
Project next-core
Branch Review steve/v3-perf
Run status status check passed Passed #10936
Run duration 00m 26s
Commit git commit 9a04b98dc5 ℹ️: Merge 226a728f69c20839c5a39df10ae5e624b2ccadf5 into d647a7e21f334279b24664c4df40...
Committer Shenwei Wang
View all properties for this run ↗︎

Test results
Tests that failed  Failures 0
Tests that were flaky  Flaky 0
Tests that did not run due to a developer annotating a test with .skip  Pending 0
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 16
View all changes introduced in this branch ↗︎

@weareoutman weareoutman requested a review from Copilot February 14, 2025 01:16
Copy link

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.

Copilot reviewed 6 out of 9 changed files in this pull request and generated no comments.

Files not reviewed (3)
  • packages/brick-container/build.config.js: Evaluated as low risk
  • packages/brick-playground/scripts/start.js: Evaluated as low risk
  • packages/brick-container/serve/middlewares/getMiddlewares.js: Evaluated as low risk
Comments suppressed due to low confidence (2)

packages/serve-helpers/src/tryFiles.js:22

  • The new functionality for handling multiple ranges in the tryServeFiles function should be covered by tests.
export function tryServeFiles(files, req, res, next) {

packages/brick-playground/serve/examplesJson.js:13

  • Verify that the new path '../next-bricks/bricks' is correct and accessible by the getExamples and getBrickManifests functions.
path.join(rootDir, "../next-bricks/bricks"),

},
defaultVendors: {
test: /[\\/]node_modules[\\/]/,
all: {
Copy link
Member Author

Choose a reason for hiding this comment

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

目标:通过合并 JS 输出,减少请求数。 副作用:请求体积增大;失去拆分 JS 分块缓存带来的的好处。

Copy link

@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: 1

🧹 Nitpick comments (1)
packages/serve-helpers/src/tryFiles.js (1)

59-59: 建议移除注释掉的过期时间

代码中包含了一个被注释掉的 Expires 头部设置。建议直接删除这行注释,因为已经使用了 Cache-Control 来控制缓存。

-    // "Expires": "Thu, 12 Feb 2026 09:39:38 GMT",
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 12c3d95 and 226a728.

📒 Files selected for processing (8)
  • packages/brick-container/build.config.js (1 hunks)
  • packages/brick-container/serve/middlewares/getMiddlewares.js (7 hunks)
  • packages/brick-playground/scripts/start.js (2 hunks)
  • packages/brick-playground/serve/index.js (2 hunks)
  • packages/serve-helpers/index.d.ts (2 hunks)
  • packages/serve-helpers/src/index.js (1 hunks)
  • packages/serve-helpers/src/serveBricks.js (1 hunks)
  • packages/serve-helpers/src/tryFiles.js (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (6)
  • packages/brick-container/build.config.js
  • packages/brick-playground/serve/index.js
  • packages/serve-helpers/src/index.js
  • packages/serve-helpers/index.d.ts
  • packages/serve-helpers/src/serveBricks.js
  • packages/brick-container/serve/middlewares/getMiddlewares.js
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: build (20.x)
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (2)
packages/brick-playground/scripts/start.js (1)

55-58: 代码重构改进了可维护性!

通过使用 serveBricks 替换 express.static 中间件,实现了以下改进:

  • 集中了静态文件服务的逻辑
  • 减少了对 express 的直接依赖
  • 保持了原有功能的完整性
packages/serve-helpers/src/tryFiles.js (1)

25-35: 多区间请求的处理逻辑正确实现!

代码正确地检测和解析多区间请求,并将单区间请求委托给 Express.js 原生处理。这种实现方式是合理的。

@qiaofengxi qiaofengxi merged commit e232b9a into v3 Feb 14, 2025
8 checks passed
@qiaofengxi qiaofengxi deleted the steve/v3-perf branch February 14, 2025 01:59
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