Skip to content

Conversation

@fireairforce
Copy link
Contributor

Summary

加个通用的 runtimeEntryBoostrap 配置来往运行时之前插入一些可执行的代码。

目前是为了去适配qiankun的加载。

Test Plan

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @fireairforce, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

此拉取请求引入了一个新的配置选项 runtimeEntryBootstrap,允许用户在主运行时执行之前注入自定义代码。此功能旨在促进与 qiankun 等微前端框架的集成,提供了一种灵活的方式来在应用启动前执行必要的初始化逻辑。

Highlights

  • 新增 runtimeEntryBootstrap 配置: 引入了一个新的通用配置 runtimeEntryBootstrap,允许在运行时之前插入可执行代码。
  • 支持 qiankun 适配: 此功能的主要目的是为了适配 qiankun 微前端框架的加载需求。
  • 灵活的配置方式: 新的配置支持两种方式:直接提供内联代码字符串,或者指定一个文件路径来加载引导代码。

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

这个 PR 增加了一个通用的 runtimeEntryBootstrap 配置,允许在运行时之前注入可执行代码,这对于适配 qiankun 等微前端框架非常有帮助。整体实现思路清晰,但在配置项的 enum 设计上存在一个严重问题,可能导致反序列化行为不符合预期。此外,处理不同配置类型的代码存在重复,可以进行重构以提高可维护性。

Comment on lines +124 to +133
#[derive(
Clone, Debug, PartialEq, Eq, Serialize, Deserialize, TraceRawVcs, NonLocalValue, OperationValue,
)]
#[serde(untagged)]
pub enum RuntimeBootstrapConfig {
/// Inline JavaScript code
Code(RcStr),
/// Path to a JavaScript/TypeScript file
Path(RcStr),
}
Copy link
Contributor

Choose a reason for hiding this comment

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

critical

RuntimeBootstrapConfig 枚举的定义存在一个严重问题。当 #[serde(untagged)] 与两个都包装了 RcStr(类似于 String)的变体一起使用时,serde 无法区分它们。在反序列化时,任何字符串值(无论是内联代码还是文件路径)都将被错误地解析为第一个变体,即 Code(RcStr)。这会导致文件路径被当作内联代码处理,从而引发运行时错误。
为了解决这个问题,建议将其中一个变体(例如 Path)修改为结构体,以便 serde 能够根据 JSON 结构进行区分。例如,用户可以通过 { "path": "./bootstrap.js" } 来指定文件路径,通过 "console.log('hello')" 来指定内联代码。
同时,别忘了更新 crates/pack-core/src/client/context.rs 中对应的 match 分支来匹配新的结构 (e.g. RuntimeBootstrapConfig::Path { path } => ...)。

pub enum RuntimeBootstrapConfig {
    /// Path to a JavaScript/TypeScript file, as an object: `{ "path": "./bootstrap.js" }`
    Path { path: RcStr },
    /// Inline JavaScript code, as a string
    Code(RcStr),
}

Comment on lines +221 to +243
if let Some(bootstrap_config) = bootstrap_config_opt.as_ref() {
match bootstrap_config {
crate::config::RuntimeBootstrapConfig::Code(code) => {
// Inline code: create a virtual source
let bootstrap_source = VirtualSource::new(
project_root.join("__runtime_bootstrap__.js")?,
AssetContent::file(File::from(code.clone()).into()),
)
.to_resolved()
.await?;
runtime_entries.push(
RuntimeEntry::Source(ResolvedVc::upcast(bootstrap_source)).resolved_cell(),
);
}
crate::config::RuntimeBootstrapConfig::Path(path) => {
// File path: use FileSource to load the file
let bootstrap_path = project_root.join(path.as_str())?;
let bootstrap_source = FileSource::new(bootstrap_path).to_resolved().await?;
runtime_entries.push(
RuntimeEntry::Source(ResolvedVc::upcast(bootstrap_source)).resolved_cell(),
);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

match 表达式的 CodePath 分支中存在代码重复。创建 bootstrap_source 后的逻辑(即 runtime_entries.push(...))是完全相同的。建议将这部分通用逻辑提取到 match 表达式之外,以减少重复并提高代码的可读性和可维护性。

        let bootstrap_source = match bootstrap_config {
            crate::config::RuntimeBootstrapConfig::Code(code) => {
                // Inline code: create a virtual source
                VirtualSource::new(
                    project_root.join("__runtime_bootstrap__.js")?,
                    AssetContent::file(File::from(code.clone()).into()),
                )
                .to_resolved()
                .await?
            }
            crate::config::RuntimeBootstrapConfig::Path(path) => {
                // File path: use FileSource to load the file
                let bootstrap_path = project_root.join(path.as_str())?;
                FileSource::new(bootstrap_path).to_resolved().await?
            }
        };
        runtime_entries.push(
            RuntimeEntry::Source(ResolvedVc::upcast(bootstrap_source)).resolved_cell(),
        );

@xusd320 xusd320 force-pushed the next branch 2 times, most recently from f77808c to 567e5ae Compare January 7, 2026 10:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants