Skip to content

Conversation

@weareoutman
Copy link
Member

@weareoutman weareoutman commented Jul 12, 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

  • 修复问题

    • 优化了节点渲染监听逻辑,避免未挂载或已销毁节点导致的异常执行。
  • 其他改进

    • 增加并统一了节点的挂载与销毁状态标记,提高了渲染树的状态管理准确性。

@coderabbitai
Copy link

coderabbitai bot commented Jul 12, 2025

Walkthrough

本次更改在渲染节点的生命周期管理中引入了 mounted 标志,并将 disposedmounted 属性集中到 BaseRenderNode 接口。渲染树挂载时会设置这些标志。同时,渲染监听器函数增加了守卫判断,避免对未挂载或已销毁节点进行处理。

Changes

文件/分组 变更摘要
.../internal/interfaces.ts disposed 属性从 RenderAbstract 移至 BaseRenderNode,新增 mounted 属性。
.../internal/mount.ts mountTree 函数中为根节点和每个遍历到的节点设置 mounted = true
.../internal/Renderer.ts 在监听函数中增加对节点 mounteddisposed 的守卫判断,添加相关 TODO 注释。

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/runtime/src/internal/Renderer.ts

Oops! Something went wrong! :(

ESLint: 9.29.0

Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@next-core/eslint-config-next' imported from /eslint.config.mjs
at Object.getPackageJSONURL (node:internal/modules/package_json_reader:255:9)
at packageResolve (node:internal/modules/esm/resolve:767:81)
at moduleResolve (node:internal/modules/esm/resolve:853:18)
at defaultResolve (node:internal/modules/esm/resolve:983:11)
at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:801:12)
at #cachedDefaultResolve (node:internal/modules/esm/loader:725:25)
at ModuleLoader.resolve (node:internal/modules/esm/loader:708:38)
at ModuleLoader.getModuleJobForImport (node:internal/modules/esm/loader:309:38)
at #link (node:internal/modules/esm/module_job:202:49)

packages/runtime/src/internal/interfaces.ts

Oops! Something went wrong! :(

ESLint: 9.29.0

Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@next-core/eslint-config-next' imported from /eslint.config.mjs
at Object.getPackageJSONURL (node:internal/modules/package_json_reader:255:9)
at packageResolve (node:internal/modules/esm/resolve:767:81)
at moduleResolve (node:internal/modules/esm/resolve:853:18)
at defaultResolve (node:internal/modules/esm/resolve:983:11)
at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:801:12)
at #cachedDefaultResolve (node:internal/modules/esm/loader:725:25)
at ModuleLoader.resolve (node:internal/modules/esm/loader:708:38)
at ModuleLoader.getModuleJobForImport (node:internal/modules/esm/loader:309:38)
at #link (node:internal/modules/esm/module_job:202:49)

packages/runtime/src/internal/mount.ts

Oops! Something went wrong! :(

ESLint: 9.29.0

Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@next-core/eslint-config-next' imported from /eslint.config.mjs
at Object.getPackageJSONURL (node:internal/modules/package_json_reader:255:9)
at packageResolve (node:internal/modules/esm/resolve:767:81)
at moduleResolve (node:internal/modules/esm/resolve:853:18)
at defaultResolve (node:internal/modules/esm/resolve:983:11)
at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:801:12)
at #cachedDefaultResolve (node:internal/modules/esm/loader:725:25)
at ModuleLoader.resolve (node:internal/modules/esm/loader:708:38)
at ModuleLoader.getModuleJobForImport (node:internal/modules/esm/loader:309:38)
at #link (node:internal/modules/esm/module_job:202:49)

✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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

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

This PR fixes an issue where controlled nodes could be re-rendered before they were marked as mounted by:

  • Introducing a mounted flag on BaseRenderNode and setting it on the root and each child in mountTree.
  • Moving the disposed flag to BaseRenderNode and updating the interface accordingly.
  • Updating the listener in legacyRenderBrick to skip re-renders if a node is not yet mounted or has been disposed.

Reviewed Changes

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

File Description
packages/runtime/src/internal/mount.ts Set mounted flag on root and each current node in mountTree
packages/runtime/src/internal/interfaces.ts Moved disposed into BaseRenderNode and added mounted
packages/runtime/src/internal/Renderer.ts Guarded re-render listener with returnNode.mounted and !disposed
Comments suppressed due to low confidence (3)

packages/runtime/src/internal/mount.ts:20

  • Add unit tests to verify that mountTree correctly sets the mounted flag on the root and child nodes, and that controlled nodes are not re-rendered before mounting.
  root.mounted = true;

packages/runtime/src/internal/interfaces.ts:79

  • [nitpick] Consider renaming boolean properties disposed and mounted to isDisposed and isMounted to make their boolean nature explicit and improve readability.
  disposed?: boolean;

packages/runtime/src/internal/Renderer.ts:601

  • Requiring returnNode.mounted for the root or other nodes may prevent intended re-renders before mountTree runs. If this gating is intentional only for non-root nodes, consider excluding RenderTag.ROOT here or documenting why the root also needs mounted.
        if (!returnNode.mounted || returnNode.disposed) {

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

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between bfb8087 and 3aaf6ff.

📒 Files selected for processing (3)
  • packages/runtime/src/internal/Renderer.ts (2 hunks)
  • packages/runtime/src/internal/interfaces.ts (1 hunks)
  • packages/runtime/src/internal/mount.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
packages/runtime/src/internal/mount.ts (1)
packages/runtime/src/internal/interfaces.ts (1)
  • RuntimeBrickElement (111-122)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: build (20.x)
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (4)
packages/runtime/src/internal/mount.ts (2)

20-20: 正确设置根节点的挂载状态

mountTree 函数开始时设置 root.mounted = true 是正确的做法,确保根节点的挂载状态得到正确跟踪。


25-25: 正确设置节点挂载状态

在遍历过程中为每个节点设置 current.mounted = true 能确保所有节点在挂载期间都有正确的生命周期状态标记。

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

619-620: 改进了过期渲染的检查逻辑

将过期渲染检查条件更新为 returnNode.mounted && !returnNode.disposed 确保只有在节点已挂载且未销毁的情况下才继续处理,这比之前的条件更加严格和准确。

packages/runtime/src/internal/interfaces.ts (1)

79-80: 正确地将生命周期属性集中到基础接口

disposedmounted 属性添加到 BaseRenderNode 接口是一个很好的设计决策,这样所有继承自该接口的渲染节点类型都能统一管理生命周期状态。

将属性定义为可选的(?:)是正确的,因为节点在初始状态下是未挂载的。

Comment on lines +600 to +603
// TODO(steve): start listeners when mounting, and handle changes between rendering and mounting.
if (!returnNode.mounted || returnNode.disposed) {
return;
}
Copy link

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

添加了必要的生命周期保护逻辑

在监听器函数中添加的保护条件 !returnNode.mounted || returnNode.disposed 能正确防止对未挂载或已销毁的节点进行处理,这是一个重要的防护措施。

TODO 注释正确识别了渲染和挂载之间可能存在的时序问题。

考虑实现更精细的生命周期管理来处理渲染和挂载之间的状态变化,可以通过以下方式验证当前实现是否存在竞态条件:


🏁 Script executed:

#!/bin/bash
# 搜索 mounted 属性的使用模式,检查是否存在其他需要同步处理的地方
rg -A 3 -B 3 "\.mounted" --type ts

Length of output: 1888


改进渲染监听器的启动时机以消除渲染与挂载之间的竞态

当前在 Renderer.ts 中直接启动监听器(listener),即便加了 guard 条件,仍可能与 mount.ts 的挂载流程产生时序冲突。建议将 listener 的注册/启动延后到所有节点的 mounted 标志设置完毕之后,或在挂载流程中统一启动。

需要关注的代码位置:

  • packages/runtime/src/internal/Renderer.ts(约第596–603行):listener 定义与立即启动处
  • packages/runtime/src/internal/mount.ts(约第3–7行):root.mounted = truecurrent.mounted = true 赋值处

示例改进思路:

--- Renderer.ts
- listener(); // 立即启动会与挂载流程竞态
+ // 不在这里直接启动 listener,而在挂载完成后统一注册
// mount.ts 挂载流程末尾
root.mounted = true;
for (let node of allNodes) {
  node.mounted = true;
}
// 挂载完成后再启动渲染监听器
renderer.registerListener(listener);

请根据项目整体生命周期管理方案,将 listener 启动逻辑移至挂载完成位置。

🤖 Prompt for AI Agents
In packages/runtime/src/internal/Renderer.ts around lines 596 to 603, the
listener is currently started immediately during rendering, which can cause race
conditions with the mounting process in mount.ts where nodes' mounted flags are
set around lines 3 to 7. To fix this, remove the listener startup from
Renderer.ts and instead move the listener registration and startup to the end of
the mounting process in mount.ts, after all nodes have their mounted flags set
to true, ensuring listeners start only after mounting is fully complete.

@codecov
Copy link

codecov bot commented Jul 12, 2025

Codecov Report

Attention: Patch coverage is 50.00000% with 2 lines in your changes missing coverage. Please review.

Project coverage is 95.22%. Comparing base (bfb8087) to head (3aaf6ff).
Report is 2 commits behind head on v3.

Files with missing lines Patch % Lines
packages/runtime/src/internal/Renderer.ts 0.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##               v3    #4749      +/-   ##
==========================================
- Coverage   95.24%   95.22%   -0.02%     
==========================================
  Files         209      209              
  Lines        9140     9144       +4     
  Branches     1759     1760       +1     
==========================================
+ Hits         8705     8707       +2     
- Misses        322      323       +1     
- Partials      113      114       +1     
Files with missing lines Coverage Δ
packages/runtime/src/internal/mount.ts 94.82% <100.00%> (+0.18%) ⬆️
packages/runtime/src/internal/Renderer.ts 93.56% <0.00%> (-0.51%) ⬇️
🚀 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.

@cypress
Copy link

cypress bot commented Jul 12, 2025

next-core    Run #11491

Run Properties:  status check passed Passed #11491  •  git commit 8ca897cbb3 ℹ️: Merge 3aaf6ff1580303079978d5ec8227359e41f835bd into bfb8087e80ddb503a1f55bc975a9...
Project next-core
Branch Review steve/v3-fix-control-bug
Run status status check passed Passed #11491
Run duration 00m 23s
Commit git commit 8ca897cbb3 ℹ️: Merge 3aaf6ff1580303079978d5ec8227359e41f835bd into bfb8087e80ddb503a1f55bc975a9...
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 17
View all changes introduced in this branch ↗︎

@weareoutman weareoutman merged commit 80c26eb into v3 Jul 13, 2025
7 of 9 checks passed
@weareoutman weareoutman deleted the steve/v3-fix-control-bug branch July 13, 2025 12:10
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