fix(): enable force standalone mode by default#4858
Conversation
实现概述通过 --no-force-standalone CLI 标志在环境配置中引入新的独立模式控制,并在代理逻辑中添加条件分支以根据该标志处理 HTML 注入流程。 变更
预估代码审查工作量🎯 2 (Simple) | ⏱️ ~10 分钟 🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
next-core
|
||||||||||||||||||||||||||||
| Project |
next-core
|
| Branch Review |
steve/v3-force-standalone
|
| Run status |
|
| Run duration | 00m 27s |
| Commit |
|
| Committer | Shenwei Wang |
| View all properties for this run ↗︎ | |
| Test results | |
|---|---|
|
|
0
|
|
|
0
|
|
|
0
|
|
|
0
|
|
|
17
|
| View all changes introduced in this branch ↗︎ | |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@packages/brick-container/serve/getProxy.js`:
- Around line 432-440: The local variable named content in the
env.forceStandalone branch shadows an outer content variable and reduces
readability; rename that local variable to rawIndexHtml (or similar) in the
block where you call getRawIndexHtml(), i.e. inside the branch guarded by
env.forceStandalone that calls getMatchedStoryboard(), getRawIndexHtml(),
getStandaloneConfig() and returns injectIndexHtml(...); update any subsequent
references in that block to use rawIndexHtml so the outer content variable is no
longer shadowed.
| } else if (env.forceStandalone) { | ||
| const storyboard = await getMatchedStoryboard( | ||
| env, | ||
| req.path.replace(/^\/next\//, "/") | ||
| ); | ||
| const content = await getRawIndexHtml(); | ||
| const standaloneConfig = getStandaloneConfig(storyboard); | ||
| return injectIndexHtml(env, content, standaloneConfig); | ||
| } |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
# First, let's locate and examine the main file and understand the context
fd "getProxy.js" | head -5Repository: easyops-cn/next-core
Length of output: 106
🏁 Script executed:
# Find the getMatchedStoryboard function implementation
rg "getMatchedStoryboard" --type js -A 15 | head -50Repository: easyops-cn/next-core
Length of output: 3770
🏁 Script executed:
# Find the getStandaloneConfig function implementation
rg "getStandaloneConfig" --type js -A 10 | head -50Repository: easyops-cn/next-core
Length of output: 3737
🏁 Script executed:
# Get the structure of the serve directory
tree packages/brick-container/serve -L 2Repository: easyops-cn/next-core
Length of output: 677
🏁 Script executed:
# Read the full getStandaloneConfig.js file
cat packages/brick-container/serve/utils/getStandaloneConfig.jsRepository: easyops-cn/next-core
Length of output: 509
🏁 Script executed:
# Read the full getStoryboards.js file
cat packages/brick-container/serve/utils/getStoryboards.jsRepository: easyops-cn/next-core
Length of output: 1968
🏁 Script executed:
# Read getProxy.js focusing on the relevant sections
wc -l packages/brick-container/serve/getProxy.jsRepository: easyops-cn/next-core
Length of output: 110
🏁 Script executed:
# Read the relevant sections of getProxy.js
sed -n '310,450p' packages/brick-container/serve/getProxy.jsRepository: easyops-cn/next-core
Length of output: 6044
🏁 Script executed:
# Read the injectIndexHtml.js to understand how it handles null config
cat packages/brick-container/serve/utils/injectIndexHtml.jsRepository: easyops-cn/next-core
Length of output: 2372
🏁 Script executed:
# Get more context around line 318 in getProxy.js to understand variable scope
sed -n '315,450p' packages/brick-container/serve/getProxy.js | cat -nRepository: easyops-cn/next-core
Length of output: 6849
变量命名不清晰导致代码混淆。
第 437 行的变量 content 遮蔽了第 318 行外层作用域的同名变量。虽然它们在语义上表示不同的内容(一个是响应的 HTML,一个是原始的 index HTML),但同一变量名在嵌套作用域中使用会降低可读性。建议重命名为 rawIndexHtml 以保持一致性和清晰度。
另注:getStandaloneConfig 已通过可选链操作符 storyboard?.app.standaloneMode 安全地处理 undefined 情况,injectIndexHtml 也通过 if (standaloneConfig) 检查来处理 null 值,所以即使 getMatchedStoryboard 返回 undefined,现有代码也能安全处理。
🤖 Prompt for AI Agents
In `@packages/brick-container/serve/getProxy.js` around lines 432 - 440, The local
variable named content in the env.forceStandalone branch shadows an outer
content variable and reduces readability; rename that local variable to
rawIndexHtml (or similar) in the block where you call getRawIndexHtml(), i.e.
inside the branch guarded by env.forceStandalone that calls
getMatchedStoryboard(), getRawIndexHtml(), getStandaloneConfig() and returns
injectIndexHtml(...); update any subsequent references in that block to use
rawIndexHtml so the outer content variable is no longer shadowed.
There was a problem hiding this comment.
Pull request overview
This PR enables force standalone mode by default for the brick-container development server. The change allows developers to test standalone micro-apps behavior during local development without explicitly enabling the flag. The implementation adds a new CLI flag --no-force-standalone to disable this behavior when needed.
Changes:
- Added
forceStandaloneCLI flag withtrueas default value in env.js - Added logic to handle force standalone mode in the proxy response interceptor in getProxy.js
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| packages/brick-container/serve/env.js | Adds --no-force-standalone CLI flag and forceStandalone configuration with default value true |
| packages/brick-container/serve/getProxy.js | Imports required utilities and adds conditional logic to inject standalone configuration when force standalone mode is enabled |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| env, | ||
| req.path.replace(/^\/next\//, "/") | ||
| ); | ||
| const content = await getRawIndexHtml(); |
There was a problem hiding this comment.
Inconsistent variable naming: This should be named rawIndexHtml to match the existing pattern in the same file (see line 321). Using content here creates variable shadowing with the outer content variable declared on line 318 and is inconsistent with the established naming convention.
| env, | ||
| req.path.replace(/^\/next\//, "/") | ||
| ); | ||
| const content = await getRawIndexHtml(); |
There was a problem hiding this comment.
The getMatchedStoryboard function can return undefined when no storyboard matches the pathname (see getStoryboards.js line 67). This will cause getStandaloneConfig to receive undefined, and while it handles null/undefined storyboards gracefully by returning null, the subsequent call to injectIndexHtml will receive a null standaloneConfig. While injectIndexHtml does handle null standaloneConfig, consider adding error handling or fallback logic when no storyboard matches, as this might indicate a configuration issue that should be logged or handled explicitly.
| const content = await getRawIndexHtml(); | |
| const content = await getRawIndexHtml(); | |
| if (!storyboard) { | |
| // No storyboard matched the current path while forceStandalone is enabled. | |
| // Log a warning and fall back to injecting the index HTML without standalone config. | |
| console.warn( | |
| `[brick-container] No storyboard matched for path "${req.path}" while forceStandalone is enabled. Falling back to default index HTML.` | |
| ); | |
| return injectIndexHtml(env, content); | |
| } |
依赖检查
组件之间的依赖声明,是微服务组件架构下的重要信息,请确保其正确性。
请勾选以下两组选项其中之一:
或者:
提交信息检查
Git 提交信息将决定包的版本发布及自动生成的 CHANGELOG,请检查工作内容与提交信息是否相符,并在以下每组选项中都依次确认。
破坏性变更:
feat作为提交类型。BREAKING CHANGE: 你的变更说明。新特性:
feat作为提交类型。问题修复:
fix作为提交类型。杂项工作:
即所有对下游使用者无任何影响、且没有必要显示在 CHANGELOG 中的改动,例如修改注释、测试用例、开发文档等:
chore,docs,test等作为提交类型。Summary by CodeRabbit
发布说明
新功能
改进