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

Steve/v3-fix-rerender #4538

Merged
merged 3 commits into from
Oct 30, 2024
Merged

Steve/v3-fix-rerender #4538

merged 3 commits into from
Oct 30, 2024

Conversation

weareoutman
Copy link
Member

@weareoutman weareoutman commented Oct 30, 2024

依赖检查

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

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

  • 本次 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

  • 新功能

    • 改进了YAML语言配置和标记器定义,增强了对嵌入表达式和分隔符的处理。
    • 更新了渲染控制节点的逻辑,采用新的参数结构以提高类型安全性。
  • 错误修复

    • 改进了错误消息的清晰度,确保更好地指示问题来源。
  • 测试

    • 扩展了Renderersecret_internals模块的测试覆盖范围,增加了对边界情况和新逻辑的验证。

Copy link

coderabbitai bot commented Oct 30, 2024

Walkthrough

此次变更涉及多个文件的修改,主要集中在 YAML 语言配置、模板代理设置、渲染器模块的测试及其实现上。在 yaml.js 中,移除了 surroundingPairs 属性并调整了标记器的多表达式规则。在 setupTemplateProxy.ts 中,改进了错误消息和插槽处理逻辑。Renderer.ts 文件中重构了控制节点的渲染逻辑,并引入了新的类型定义。测试文件也进行了扩展,以增强对不同场景的覆盖。

Changes

文件路径 变更摘要
packages/monaco-contributions/yaml.js 移除 conf 对象中的 surroundingPairs 属性;更新 register 方法签名;调整标记器的多表达式规则。
packages/runtime/src/internal/CustomTemplates/setupTemplateProxy.ts 修改 setupTemplateProxy 函数中的错误消息;优化插槽处理逻辑,确保无插入砖块时不进行处理。
packages/runtime/src/internal/Renderer.spec.ts 增加对 renderRoutesrenderBrick 函数的新测试用例,增强现有测试以覆盖更多场景。
packages/runtime/src/internal/Renderer.ts 定义新类型 RenderControlNodeOptions;更新 renderControlNode 函数签名以接受对象参数;调整渲染逻辑。
packages/runtime/src/internal/secret_internals.spec.ts 增加新的测试用例以测试 useBrick 函数的行为;更新 mockInternalApiGetRuntimeContext 的返回值。

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 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

codecov bot commented Oct 30, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.23%. Comparing base (4d4bc39) to head (4e8953f).
Report is 4 commits behind head on v3.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##               v3    #4538   +/-   ##
=======================================
  Coverage   95.23%   95.23%           
=======================================
  Files         206      206           
  Lines        8911     8912    +1     
  Branches     1697     1698    +1     
=======================================
+ Hits         8486     8487    +1     
  Misses        319      319           
  Partials      106      106           
Files with missing lines Coverage Δ
...src/internal/CustomTemplates/setupTemplateProxy.ts 85.71% <ø> (ø)
packages/runtime/src/internal/Renderer.ts 94.25% <100.00%> (+0.01%) ⬆️

Copy link

cypress bot commented Oct 30, 2024

next-core    Run #10719

Run Properties:  status check passed Passed #10719  •  git commit 883df3da81 ℹ️: Merge 4e8953fc4e764c2673d5e589ad79eba01c30635e into 4d4bc3902718297643bae650a60c...
Project next-core
Branch Review steve/v3-fix-rerender
Run status status check passed Passed #10719
Run duration 00m 22s
Commit git commit 883df3da81 ℹ️: Merge 4e8953fc4e764c2673d5e589ad79eba01c30635e into 4d4bc3902718297643bae650a60c...
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 ↗︎

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

🧹 Outside diff range and nitpick comments (2)
packages/runtime/src/internal/CustomTemplates/setupTemplateProxy.ts (1)

Line range hint 74-89: 建议增强错误处理和代码可读性

当前代码在处理外部插槽时的逻辑较为复杂,建议考虑以下改进:

  1. expandableSlot 的初始化添加更明确的错误处理
  2. 考虑将插槽大小计算逻辑抽取为独立函数以提高可维护性

建议重构如下:

+ function calculateExpandableSlotSize(slots: SlotsConfOfBricks, refToSlot: string): number {
+   return hasOwnProperty(slots, refToSlot)
+     ? slots[refToSlot].bricks.length + 1
+     : 1;
+ }

  if (!expandableSlot) {
    expandableSlot = [];
-   const size = hasOwnProperty(slots, refToSlot)
-     ? slots[refToSlot].bricks.length + 1
-     : 1;
+   const size = calculateExpandableSlotSize(slots, refToSlot);
    for (let i = 0; i < size; i += 1) {
      expandableSlot.push([]);
    }
    quasisMap.set(refToSlot, expandableSlot);
  }
packages/runtime/src/internal/Renderer.spec.ts (1)

3450-3450: 建议将错误信息中的 "Can not" 修改为 "Cannot"

"Cannot" 是 "Can not" 的正确连写形式,更符合英语表达习惯,能够提高错误信息的专业性和准确性。

您可以应用以下修改:

- `[Error: Can not have proxied slot ref when the ref target has a slot element child, check your template "my.tpl-m" and ref "main"]`
+ `[Error: Cannot have proxied slot ref when the ref target has a slot element child, check your template "my.tpl-m" and ref "main"]`
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 4d4bc39 and 4e8953f.

📒 Files selected for processing (5)
  • packages/monaco-contributions/yaml.js (1 hunks)
  • packages/runtime/src/internal/CustomTemplates/setupTemplateProxy.ts (1 hunks)
  • packages/runtime/src/internal/Renderer.spec.ts (1 hunks)
  • packages/runtime/src/internal/Renderer.ts (5 hunks)
  • packages/runtime/src/internal/secret_internals.spec.ts (2 hunks)
🔇 Additional comments (8)
packages/runtime/src/internal/CustomTemplates/setupTemplateProxy.ts (1)

61-61: 错误信息更改提升了可读性!

新的错误消息更准确地描述了问题所在,使用"ref target"替代"parent"更清晰地表达了组件之间的关系。

packages/monaco-contributions/yaml.js (1)

308-311: 表达式分隔符的标记配置优化

此更改通过添加 bracket: "@open" 增强了分隔符的标记配置,这将改善编辑器的括号匹配和代码折叠功能。

让我们验证这个改动对括号匹配的影响:

✅ Verification successful

括号匹配配置验证完成,确认更改合理

代码分析显示:

  • 已正确配置了开括号标记 bracket: "@open"
  • 存在对应的闭括号标记 bracket: "@close"
  • 这些配置与 Monaco 编辑器的括号匹配系统完全兼容

这些更改将确保在 YAML 文件中的 JavaScript 表达式能够正确进行括号匹配和代码折叠。

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 描述:检查是否有相关的测试用例验证括号匹配功能

# 测试:搜索与括号匹配相关的测试
rg -l "bracket.*match" -g "*.spec.*"

# 测试:搜索与代码折叠相关的测试
rg -l "fold.*test" -g "*.spec.*"

Length of output: 73


Script:

#!/bin/bash
# 搜索与括号匹配和代码折叠相关的配置
rg -A 5 "bracket.*['\"]@open" packages/monaco-contributions/yaml.js

# 搜索其他使用 @open 和 @close 的规则
rg -A 5 "nextEmbedded.*javascript.*bracket" packages/monaco-contributions/yaml.js

# 检查是否有对应的闭合括号配置
rg "bracket.*['\"]@close" packages/monaco-contributions/yaml.js

Length of output: 716

packages/runtime/src/internal/secret_internals.spec.ts (2)

270-272: 测试上下文设置正确!

正确设置了运行时上下文的模拟,包含了必要的 DataStore 实例。这确保了测试环境的完整性。


478-478: 测试清理代码完善!

在测试结束时正确重置了运行时上下文的模拟,这是一个很好的实践,可以防止测试状态污染。

packages/runtime/src/internal/Renderer.ts (4)

506-519: 重构 RenderControlNodeOptions 类型,提高类型安全性

引入了新的类型 RenderControlNodeOptions,使用 discriminated union 来区分 "initial" 和 "rerender" 两种类型的参数配置。这种方式提升了代码的可读性和类型检查的严格性。


520-525: 优化 renderControlNode 函数参数,增强可读性

renderControlNode 函数现在接受一个解构的参数对象,明确了所需参数,这有助于后续参数的扩展和维护。


578-581: 调用 renderControlNode 时缺少必要参数

在初始调用 renderControlNode 时,没有传递 tplStateStoreScopeformStateStoreScope,但在函数内部可能会使用到这些参数。

请确认在 "initial" 类型下,这两个参数是否必需。如果函数内部代码依赖于这些参数,可能需要在调用时传入空数组:

const controlledOutput = await renderControlNode({
  type: "initial",
  runtimeContext,
+ tplStateStoreScope: [],
+ formStateStoreScope: [],
});

593-598: 确保 tplStateStoreScopeformStateStoreScope 在重新渲染时有效

在重新渲染时,传递了这两个参数,但需要确认它们在上下文中的正确性,以避免可能的数据同步问题。

packages/runtime/src/internal/Renderer.ts Show resolved Hide resolved
@qiaofengxi qiaofengxi merged commit 6e6758f into v3 Oct 30, 2024
8 checks passed
@qiaofengxi qiaofengxi deleted the steve/v3-fix-rerender branch October 30, 2024 04:06
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.

2 participants