Skip to content

chore(): 修复如果brick设置了原生属性报错问题#4854

Open
WHChen-Alex wants to merge 1 commit intov3from
alex/useBrickFunction
Open

chore(): 修复如果brick设置了原生属性报错问题#4854
WHChen-Alex wants to merge 1 commit intov3from
alex/useBrickFunction

Conversation

@WHChen-Alex
Copy link
Contributor

@WHChen-Alex WHChen-Alex commented Jan 30, 2026

依赖检查

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

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

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

  • 重构
    • 优化了组件包装函数的类型系统,增强了类型参数的灵活性,允许更广泛的组件类型兼容性,同时保持运行时行为不变。

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Jan 30, 2026

总体概述

此次变更修改了 wrapLocalBrickwrapBrick 的泛型类型约束,从 T extends HTMLElement 改为 T extends Partial<HTMLElement>,并更新了相应的重载签名。运行时逻辑保持不变。

变更内容

Cohort / File(s) 摘要
类型签名更新
packages/react-element/src/wrapBrick.tsx
更新了 wrapLocalBrickwrapBrick 的泛型类型参数约束,从 T extends HTMLElement 改为 T extends Partial<HTMLElement>。修订了所有重载签名以反映新的 T 约束。实现逻辑在功能上保持不变。

代码审查工作量估算

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ❌ 3
❌ Failed checks (2 warnings, 1 inconclusive)
Check name Status Explanation Resolution
Description check ⚠️ Warning PR描述仅包含模板内容,所有检查项都未勾选,缺少对实际改动的说明和相关验证信息 完成并勾选相应的检查项;补充简单描述、改动说明及验证信息,特别是确认提交类型、是否涉及破坏性变更、是否添加了测试
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive 标题使用了中文且包含'修复'的描述,但'chore()'前缀与bug修复(fix)的预期不符,且标题缺乏细节 明确提交类型是'chore'还是'fix';如果是bug修复应使用'fix()'前缀;如果是chore应补充更多说明具体改动的信息

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch alex/useBrickFunction

Tip

🧪 Unit Test Generation v2 is now available!

We have significantly improved our unit test generation capabilities.

To enable: Add this to your .coderabbit.yaml configuration:

reviews:
  finishing_touches:
    unit_tests:
      enabled: true

Try it out by using the @coderabbitai generate unit tests command on your code files or under ✨ Finishing Touches on the walkthrough!

Have feedback? Share your thoughts on our Discord thread!


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@cypress
Copy link

cypress bot commented Jan 30, 2026

next-core    Run #11927

Run Properties:  status check passed Passed #11927  •  git commit f2399e0410 ℹ️: Merge bfc2a23827f08cc7f7363651d4d67ff2f7e44d80 into a752ddb014e8ceddad83b2932140...
Project next-core
Branch Review alex/useBrickFunction
Run status status check passed Passed #11927
Run duration 00m 24s
Commit git commit f2399e0410 ℹ️: Merge bfc2a23827f08cc7f7363651d4d67ff2f7e44d80 into a752ddb014e8ceddad83b2932140...
Committer Chén Wénháo
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 17
View all changes introduced in this branch ↗︎

@codecov
Copy link

codecov bot commented Jan 30, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.20%. Comparing base (a752ddb) to head (bfc2a23).

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##               v3    #4854   +/-   ##
=======================================
  Coverage   95.20%   95.20%           
=======================================
  Files         223      223           
  Lines        9489     9489           
  Branches     1821     1821           
=======================================
  Hits         9034     9034           
  Misses        334      334           
  Partials      121      121           
Files with missing lines Coverage Δ
packages/react-element/src/wrapBrick.tsx 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

Pull request overview

该 PR 旨在修复“brick 设置了原生属性时出现报错”的问题,通过放宽 wrapBrick / wrapLocalBrick 的泛型约束来避免类型层面的不兼容。

Changes:

  • wrapLocalBrick 的泛型约束从 T extends HTMLElement 放宽为 T extends Partial<HTMLElement>
  • wrapBrick 的泛型约束从 T extends HTMLElement 放宽为 T extends Partial<HTMLElement>
  • 调整部分函数重载/实现签名的写法以匹配新的泛型声明

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +28 to +33
export function wrapLocalBrick<
T extends Partial<HTMLElement>,
P,
E,
M extends object,
>(
Copy link

Copilot AI Jan 30, 2026

Choose a reason for hiding this comment

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

The new generic constraint T extends Partial<HTMLElement> makes almost any object type assignable (since all HTMLElement members are optional), which means ref/event handler generics can now be something that is not actually a DOM element. If the goal is only to relax structural compatibility while still guaranteeing a real element instance, consider constraining T to a DOM base type (e.g. Element/HTMLElement) and introducing a separate type parameter for any “looser” view of the instance, rather than weakening the element constraint to Partial<HTMLElement>.

Copilot uses AI. Check for mistakes.
Comment on lines +72 to +77
export function wrapBrick<
T extends Partial<HTMLElement>,
P,
E,
M extends object,
>(BrickName: string, eventsMapping: M): WrappedBrickWithEventsMap<T, P, E, M>;
Copy link

Copilot AI Jan 30, 2026

Choose a reason for hiding this comment

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

Same concern for wrapBrick: switching T to Partial<HTMLElement> widens the public API so wrapBrick<Foo, P>(...) can compile even when Foo is not a DOM element type, which can make ref typing misleading. If you need to support bricks whose instance types aren’t structurally compatible with HTMLElement, consider a safer bound (e.g. T extends Element) and/or a separate generic for the loose instance view used by callers.

Copilot uses AI. Check for mistakes.
Comment on lines +38 to 40
export function wrapLocalBrick<T extends Partial<HTMLElement>, P>(
brick: Constructable<T> | string
): WrappedBrick<T, P>;
Copy link

Copilot AI Jan 30, 2026

Choose a reason for hiding this comment

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

This change is intended to fix a typing error scenario, but there’s no regression coverage that would fail before and pass after (e.g. a compile-time usage that previously violated T extends HTMLElement). Consider adding a minimal type-level regression (even just a non-runtime "compiles" usage in the existing Jest TS test file) that exercises a brick instance type including native attributes/properties that previously triggered the error, so the issue doesn’t regress silently.

Copilot uses AI. Check for mistakes.
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.

1 participant