Skip to content

Conversation

@weareoutman
Copy link
Member

@weareoutman weareoutman commented Apr 22, 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

  • 新功能
    • 新增可选参数 unsafe_penetrate,允许在特定场景下访问全局上下文变量(存在安全风险)。
  • 测试
    • 增加了针对 unsafe_penetrate 行为的单元测试,确保其生效及上下文优先级正确。
  • 文档
    • 更新了相关接口的文档说明,涵盖 unsafe_penetrate 的用途和风险提示。

@coderabbitai
Copy link

coderabbitai bot commented Apr 22, 2025

Walkthrough

本次变更在运行时相关的接口和逻辑中引入了一个新的可选布尔标志 unsafe_penetrate。该标志被添加到 CreateRootOptionsRuntimeContext 接口,并在 unstable_createRoot 函数参数中支持传递。当该标志为 true 时,部分运行时上下文属性将从全局上下文中获取,实现“穿透”访问。相关的同步与异步值计算逻辑、上下文属性提取与测试用例也进行了相应调整,以支持和验证该标志的行为。未涉及其他控制流或逻辑变更。

Changes

文件/路径分组 变更摘要
etc/runtime.api.md CreateRootOptionsRuntimeContext 接口新增可选属性 unsafe_penetrateunstable_createRoot 函数签名更新以支持该选项。
packages/runtime/src/createRoot.ts CreateRootOptions 接口新增 unsafe_penetrateunstable_createRoot 支持解构该属性,并在 render 时传递到 runtimeContext
packages/runtime/src/internal/interfaces.ts RuntimeContext 接口新增可选属性 unsafe_penetrate
packages/runtime/src/internal/compute/computeRealValue.ts 引入 unsafe_penetrate 标志,若为 true,则合并全局上下文指定属性到本地上下文,相关同步/异步值计算逻辑据此调整。
packages/runtime/src/internal/compute/computeRealValue.spec.ts 增加对 unsafe_penetrate 标志行为的测试用例,mock 全局上下文获取函数,验证上下文优先级。
packages/runtime/src/internal/compute/evaluate.ts lowLevelEvaluaterun 方法根据 unsafe_penetrate 标志决定从全局或本地上下文提取属性,调整了解构逻辑。
packages/runtime/src/internal/compute/evaluate.spec.ts 增加 unsafe_penetrate 标志相关的测试用例,完善全局上下文访问的测试覆盖。

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/createRoot.ts

Oops! Something went wrong! :(

ESLint: 9.22.0

Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@next-core/eslint-config-next' imported from /eslint.config.mjs
at packageResolve (node:internal/modules/esm/resolve:839:9)
at moduleResolve (node:internal/modules/esm/resolve:908:18)
at defaultResolve (node:internal/modules/esm/resolve:1038:11)
at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:557:12)
at ModuleLoader.resolve (node:internal/modules/esm/loader:525:25)
at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:246:38)
at ModuleJob._link (node:internal/modules/esm/module_job:126:49)

packages/runtime/src/internal/compute/computeRealValue.spec.ts

Oops! Something went wrong! :(

ESLint: 9.22.0

Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@next-core/eslint-config-next' imported from /eslint.config.mjs
at packageResolve (node:internal/modules/esm/resolve:839:9)
at moduleResolve (node:internal/modules/esm/resolve:908:18)
at defaultResolve (node:internal/modules/esm/resolve:1038:11)
at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:557:12)
at ModuleLoader.resolve (node:internal/modules/esm/loader:525:25)
at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:246:38)
at ModuleJob._link (node:internal/modules/esm/module_job:126:49)

packages/runtime/src/internal/compute/computeRealValue.ts

Oops! Something went wrong! :(

ESLint: 9.22.0

Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@next-core/eslint-config-next' imported from /eslint.config.mjs
at packageResolve (node:internal/modules/esm/resolve:839:9)
at moduleResolve (node:internal/modules/esm/resolve:908:18)
at defaultResolve (node:internal/modules/esm/resolve:1038:11)
at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:557:12)
at ModuleLoader.resolve (node:internal/modules/esm/loader:525:25)
at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:246:38)
at ModuleJob._link (node:internal/modules/esm/module_job:126:49)

  • 3 others

📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 785217d and 729a787.

📒 Files selected for processing (7)
  • etc/runtime.api.md (3 hunks)
  • packages/runtime/src/createRoot.ts (3 hunks)
  • packages/runtime/src/internal/compute/computeRealValue.spec.ts (4 hunks)
  • packages/runtime/src/internal/compute/computeRealValue.ts (4 hunks)
  • packages/runtime/src/internal/compute/evaluate.spec.ts (3 hunks)
  • packages/runtime/src/internal/compute/evaluate.ts (1 hunks)
  • packages/runtime/src/internal/interfaces.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (7)
  • packages/runtime/src/internal/interfaces.ts
  • packages/runtime/src/createRoot.ts
  • packages/runtime/src/internal/compute/evaluate.spec.ts
  • packages/runtime/src/internal/compute/computeRealValue.ts
  • etc/runtime.api.md
  • packages/runtime/src/internal/compute/evaluate.ts
  • packages/runtime/src/internal/compute/computeRealValue.spec.ts
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: build (20.x)

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.
    • 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.
  • @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 introduces an unsafe_penetrate flag to allow accessing global variables from an isolated root. Changes include:

  • Adding an unsafe_penetrate property to RuntimeContext and CreateRootOptions.
  • Updating evaluation and computeRealValue functions to optionally use a penetrable runtime context.
  • Enhancing test coverage and API documentation to support the new unsafe_penetrate behavior.

Reviewed Changes

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

Show a summary per file
File Description
packages/runtime/src/internal/interfaces.ts Added optional unsafe_penetrate flag to RuntimeContext.
packages/runtime/src/internal/compute/evaluate.ts Modified context extraction to support unsafe penetration.
packages/runtime/src/internal/compute/evaluate.spec.ts Added tests for unsafe penetration feature.
packages/runtime/src/internal/compute/computeRealValue.ts Updated compute functions to possibly use a penetrable context.
packages/runtime/src/internal/compute/computeRealValue.spec.ts Added test cases for behavior with and without unsafe penetration.
packages/runtime/src/createRoot.ts Extended CreateRootOptions and unstable_createRoot with unsafe_penetrate support.
etc/runtime.api.md Updated API documentation to include unsafe_penetrate.
Comments suppressed due to low confidence (1)

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

  • [nitpick] The property name 'unsafe_penetrate' uses snake_case while other similar properties in this codebase use camelCase. Consider changing it to 'unsafePenetrate' for consistency.
unsafe_penetrate?: boolean;

@weareoutman weareoutman force-pushed the steve/v3-unsafe-penetrate branch from 0820bc6 to 785217d Compare April 22, 2025 08:24
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: 0

🔭 Outside diff range comments (2)
packages/runtime/src/internal/interfaces.ts (1)

1-40: 💡 Verification agent

🧩 Analysis chain

注意需要更新 API 文档

管道失败提示 API 签名已更改,请确保运行本地构建并更新 'etc/runtime.api.md' 文件以反映新添加的接口成员。


🏁 Script executed:

#!/bin/bash
# 检查 API 提取器是否已更新 temp 文件夹中的 API 文档
if [ -f "temp/runtime.api.md" ]; then
  echo "临时 API 文档存在,需要复制到 etc/runtime.api.md"
  # 显示差异
  diff -u etc/runtime.api.md temp/runtime.api.md || true
else
  echo "临时 API 文档不存在,可能需要运行 API 提取器构建"
fi

Length of output: 101


更新 runtime API 文档

检测到 packages/runtime/src/internal/interfaces.ts 中新增了接口成员,但未生成最新的 API 文档。请按以下步骤操作:

  • 在项目根目录运行 API 提取器(如 npm run docs:api 或对应的构建命令),生成 temp/runtime.api.md
  • 将生成的 temp/runtime.api.md 与现有的 etc/runtime.api.md 合并或替换,以同步接口签名变更。
  • 提交更新后的 etc/runtime.api.md,确保管道通过。
🧰 Tools
🪛 GitHub Actions: CI

[error] 1-1: API Extractor docs:build script failed with exit code 1. Warning: API signature changed; please copy 'temp/runtime.api.md' to 'etc/runtime.api.md' or perform a local build to update.

etc/runtime.api.md (1)

581-625: ⚠️ Potential issue

注意 API 接口更改需要更新构建

管道失败显示 API 接口已更改,需要将 'temp/runtime.api.md' 复制到 'etc/runtime.api.md' 或执行本地构建来更新。建议在提交前确保 API 文档已正确更新。

🧹 Nitpick comments (1)
packages/runtime/src/internal/compute/computeRealValue.ts (1)

20-226: 考虑添加穿透行为的文档注释

当前代码实现了 unsafe_penetrate 功能,但缺少相关的文档注释来解释这个功能的用途、使用场景和潜在风险。建议在 penetrableCtxNames 常量和使用 unsafe_penetrate 的函数部分添加详细的注释,说明此功能的设计意图和使用注意事项。

+/**
+ * 可穿透的上下文属性名称列表。
+ * 当启用 unsafe_penetrate 时,这些属性将从全局上下文中获取,
+ * 而不是使用当前隔离的运行时上下文中的值。
+ * 
+ * 注意: 这是一个不稳定的功能,应谨慎使用,因为它可能破坏上下文隔离。
+ */
const penetrableCtxNames = [
  "app",
  "location",
  "query",
  "match",
  "flags",
  "sys",
] as const;

同样,在函数实现中的穿透逻辑部分也应添加注释,解释为什么需要这种行为以及它解决了什么问题。

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 90ddc3c and 0820bc6.

📒 Files selected for processing (7)
  • etc/runtime.api.md (3 hunks)
  • packages/runtime/src/createRoot.ts (3 hunks)
  • packages/runtime/src/internal/compute/computeRealValue.spec.ts (4 hunks)
  • packages/runtime/src/internal/compute/computeRealValue.ts (4 hunks)
  • packages/runtime/src/internal/compute/evaluate.spec.ts (3 hunks)
  • packages/runtime/src/internal/compute/evaluate.ts (1 hunks)
  • packages/runtime/src/internal/interfaces.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
packages/runtime/src/internal/compute/evaluate.spec.ts (2)
packages/runtime/src/internal/Renderer.spec.ts (1)
  • _internalApiGetRuntimeContext (70-72)
packages/runtime/src/internal/compute/evaluate.ts (1)
  • evaluate (105-112)
🪛 GitHub Actions: CI
packages/runtime/src/internal/interfaces.ts

[error] 1-1: API Extractor docs:build script failed with exit code 1. Warning: API signature changed; please copy 'temp/runtime.api.md' to 'etc/runtime.api.md' or perform a local build to update.

packages/runtime/src/internal/compute/evaluate.spec.ts

[error] 1-1: API Extractor docs:build script failed with exit code 1. Warning: API signature changed; please copy 'temp/runtime.api.md' to 'etc/runtime.api.md' or perform a local build to update.

packages/runtime/src/createRoot.ts

[error] 1-1: API Extractor docs:build script failed with exit code 1. Warning: API signature changed; please copy 'temp/runtime.api.md' to 'etc/runtime.api.md' or perform a local build to update.

packages/runtime/src/internal/compute/evaluate.ts

[error] 1-1: API Extractor docs:build script failed with exit code 1. Warning: API signature changed; please copy 'temp/runtime.api.md' to 'etc/runtime.api.md' or perform a local build to update.

packages/runtime/src/internal/compute/computeRealValue.ts

[error] 1-1: API Extractor docs:build script failed with exit code 1. Warning: API signature changed; please copy 'temp/runtime.api.md' to 'etc/runtime.api.md' or perform a local build to update.

packages/runtime/src/internal/compute/computeRealValue.spec.ts

[error] 1-1: API Extractor docs:build script failed with exit code 1. Warning: API signature changed; please copy 'temp/runtime.api.md' to 'etc/runtime.api.md' or perform a local build to update.

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (19)
packages/runtime/src/internal/interfaces.ts (1)

38-39: 添加了 unsafe_penetrate 选项

该变更添加了一个新的可选布尔属性 unsafe_penetrateRuntimeContext 接口中,这与 PR 的目标一致。

packages/runtime/src/internal/compute/evaluate.spec.ts (3)

257-259: 添加了 beforeEach 钩子以重置模拟

良好的测试实践,确保每个测试都有一个干净的模拟状态。


412-424: 修改了 mockReturnValueOnce 为 mockReturnValue

这个改变使模拟值在整个测试期间持续有效,而不仅仅是第一次调用时。这是测试逻辑上的改进。


426-444: 增加了 unsafe_penetrate 功能的测试

这个测试很好地验证了新的 unsafe_penetrate 标志的行为:

  1. 当标志设置为 true 时,会从全局上下文中获取 appflags 属性
  2. 测试确认全局属性 (app.id 为 "global") 被正确地使用
  3. 测试确认全局标志 (flags.unsafe 为 true) 被正确地使用
  4. 测试确认当全局上下文中不存在的属性 (flags.test) 返回 undefined

这些测试覆盖了新功能的关键行为,确保其按预期工作。

packages/runtime/src/createRoot.ts (4)

47-53: 添加了 unsafe_penetrate 选项文档

文档清晰地解释了该选项的目的和风险:允许从隔离的根访问全局变量,并警告用户这是不安全的。这是一个很好的文档实践,特别是对于可能有风险的功能。


70-75: 更新了 unstable_createRoot 函数签名

函数签名已更新以接受新的 unsafe_penetrate 选项,使用解构赋值模式保持了代码风格的一致性。


126-126: 传递 unsafe_penetrate 标志到运行时上下文

正确地将 unsafe_penetrate 标志添加到运行时上下文初始化中,这样标志就可以在渲染过程中被访问。


31-54:

✅ Verification successful

注意 CreateRootOptions 接口已更改

接口更改需要更新 API 文档。请确保在提交前运行本地构建并更新 etc/runtime.api.md 文件。


🏁 Script executed:

#!/bin/bash
# 查找所有引用了 CreateRootOptions 的文件,以检查是否有需要更新的地方
echo "查找引用了 CreateRootOptions 的文件:"
rg --type ts "CreateRootOptions" --files-with-matches

Length of output: 155


🏁 Script executed:

#!/bin/bash
# 检查 API 文档中是否包含并已更新 CreateRootOptions 接口定义
echo "扫描 etc/runtime.api.md 中的 CreateRootOptions 定义:"
rg -n "CreateRootOptions" etc/runtime.api.md || echo "未找到 CreateRootOptions,需添加文档条目"

Length of output: 356


文档已同步 CreateRootOptions 接口

已确认 etc/runtime.api.md 中包含最新的 CreateRootOptions 接口定义,无需额外更新。

packages/runtime/src/internal/compute/computeRealValue.spec.ts (3)

4-8: 添加了对 _internalApiGetRuntimeContext 的模拟

正确地设置了对 _internalApiGetRuntimeContext 函数的模拟,这对于测试新功能是必要的。


167-169: 添加了 beforeEach 钩子以重置模拟

良好的测试实践,确保每个测试都有一个干净的模拟状态。


314-331: 添加了两个测试用例验证 unsafe_penetrate 功能

这些测试很好地验证了 computeRealValue 函数在使用和不使用 unsafe_penetrate 标志时的行为:

  1. 第一个测试验证当不使用 unsafe_penetrate 时,函数使用本地上下文的 query (返回 "foo")
  2. 第二个测试验证当使用 unsafe_penetrate 时,函数使用全局上下文的 query (返回 "bar")

这些测试确保了新功能的核心行为按预期工作。

etc/runtime.api.md (3)

122-122: 扩展接口添加了 unsafe_penetrate 选项

CreateRootOptions 接口中新增了可选的 unsafe_penetrate 布尔属性,该属性允许开发者控制在执行时是否应该"穿透"访问全局上下文。


462-463: 运行时上下文接口添加 unsafe_penetrate 支持

RuntimeContext 接口新增了可选的 unsafe_penetrate 布尔属性,用于在运行时上下文中传递穿透访问标志。此更改与 CreateRootOptions 的更新保持一致。


588-588: unstable_createRoot 函数参数支持 unsafe_penetrate

unstable_createRoot 函数签名已更新,现在可以接收并解构 unsafe_penetrate 参数。此更改确保了从 API 到实现的一致性。

packages/runtime/src/internal/compute/evaluate.ts (1)

306-313: 实现运行时上下文的穿透访问机制

此代码片段实现了 unsafe_penetrate 的核心功能:从当前运行时上下文中提取 unsafe_penetrate 标志,并据此决定是使用全局上下文(通过 _internalApiGetRuntimeContext())还是本地上下文。这种方式允许在隔离的根中访问全局上下文的特定属性。

代码的实现简洁明了,使用解构赋值来提取并重组所需属性,保持了代码的可读性。

packages/runtime/src/internal/compute/computeRealValue.ts (4)

1-1: 添加 pick 方法导入

添加了 pick 方法的导入,用于后续对运行时上下文对象进行属性选择操作。此变更是必要的,以支持 unsafe_penetrate 功能的实现。

🧰 Tools
🪛 GitHub Actions: CI

[error] 1-1: API Extractor docs:build script failed with exit code 1. Warning: API signature changed; please copy 'temp/runtime.api.md' to 'etc/runtime.api.md' or perform a local build to update.


18-27: 定义可穿透的上下文属性列表

引入 _internalApiGetRuntimeContext 导入和定义 penetrableCtxNames 常量数组,明确指定了哪些上下文属性可以被"穿透"访问。这种显式列举的方式增加了代码的可维护性和安全性,防止了不必要的属性泄露。

使用 as const 断言确保了类型安全,这是一个良好的实践。


56-75: 在 asyncComputeRealValue 中实现穿透上下文逻辑

这段代码实现了 asyncComputeRealValue 函数中的穿透逻辑。当 lazy 为 true 时,直接返回原始值;否则,检查 unsafe_penetrate 标志并据此创建穿透上下文。

穿透上下文通过巧妙组合 pickomit 函数,将全局上下文中的特定属性与本地上下文的其他属性合并,确保了正确的属性优先级和访问控制。

值得注意的是,代码结构清晰,条件分支处理得当,保持了函数的可读性。


144-163: 在 computeRealValue 中实现穿透上下文逻辑

此段代码在同步版本的 computeRealValue 函数中实现了与 asyncComputeRealValue 相同的穿透逻辑。代码保持了一致性,确保了两个函数在行为上的统一。

实现方式与异步版本相同,通过 pickomit 函数组合创建穿透上下文,并根据上下文中是否存在 data 属性选择适当的转换函数。这种一致性有助于代码维护和理解。

@weareoutman weareoutman force-pushed the steve/v3-unsafe-penetrate branch from 785217d to 729a787 Compare April 22, 2025 08:32
@codecov
Copy link

codecov bot commented Apr 22, 2025

Codecov Report

Attention: Patch coverage is 92.30769% with 1 line in your changes missing coverage. Please review.

Project coverage is 95.26%. Comparing base (90ddc3c) to head (729a787).
Report is 2 commits behind head on v3.

Files with missing lines Patch % Lines
...s/runtime/src/internal/compute/computeRealValue.ts 88.88% 0 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##               v3    #4683      +/-   ##
==========================================
- Coverage   95.27%   95.26%   -0.01%     
==========================================
  Files         209      209              
  Lines        9028     9037       +9     
  Branches     1734     1737       +3     
==========================================
+ Hits         8601     8609       +8     
  Misses        319      319              
- Partials      108      109       +1     
Files with missing lines Coverage Δ
packages/runtime/src/createRoot.ts 98.73% <ø> (ø)
packages/runtime/src/internal/compute/evaluate.ts 98.42% <100.00%> (+0.01%) ⬆️
...s/runtime/src/internal/compute/computeRealValue.ts 98.11% <88.88%> (-1.89%) ⬇️
🚀 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 Apr 22, 2025

next-core    Run #11187

Run Properties:  status check passed Passed #11187  •  git commit 6d0b0a61cc ℹ️: Merge 729a787e51f36980e2529bf9ecef692dff8d916f into 90ddc3c042b10fff8deb37c1ba21...
Project next-core
Branch Review steve/v3-unsafe-penetrate
Run status status check passed Passed #11187
Run duration 00m 22s
Commit git commit 6d0b0a61cc ℹ️: Merge 729a787e51f36980e2529bf9ecef692dff8d916f into 90ddc3c042b10fff8deb37c1ba21...
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 WHChen-Alex April 22, 2025 08:38
@WHChen-Alex WHChen-Alex merged commit 985b279 into v3 Apr 22, 2025
6 of 7 checks passed
@WHChen-Alex WHChen-Alex deleted the steve/v3-unsafe-penetrate branch April 22, 2025 08:46
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