docs(guide): 改教真正生效的 VITE_SERVER_URL,删除不存在的 MSW 开关 - #3532
Merged
Conversation
deployment.md 与 console.md 教读者配置 `VITE_API_URL` 与 `VITE_USE_MOCK_SERVER`,这两个变量全仓没有任何源码读取;真正生效的是 `VITE_SERVER_URL`(`packages/app-shell/src/providers/AdapterProvider.tsx:101` 用作 ObjectStackAdapter 的 baseUrl,auth / i18n / action 端点也全挂在它上面)。 MSW 引导路径已在 2b7435b 中被整体移除,文档不应继续描述该能力。 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GTRjn8xBqp75dk7kFupVRt
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
yinlianghui
marked this pull request as ready for review
August 7, 2026 03:11
This was referenced Aug 7, 2026
Open
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3527
只改两个文件:
content/docs/guide/deployment.md、content/docs/guide/console.md。一、前提复核(先证伪,再动手)
在
origin/main= d0d71df 上逐条重测 issue 的三条断言,全部成立:VITE_API_URL全仓无源码读取content/里;packages/apps/examples/scripts/零命中VITE_USE_MOCK_SERVER没有任何代码分支读它grep "import.meta.env.VITE_USE_MOCK_SERVER"零命中;apps/console/src、packages/app-shell/src、examples/console-starter/src里msw/setupWorker/mockServiceWorker全部零命中;全仓无mockServiceWorker.js资产VITE_SERVER_URL才是真变量packages/app-shell/src/providers/AdapterProvider.tsx:101即 `baseUrl: import.meta.env.VITE_SERVER_URL分诊留的那一问:死开关,还是「丢了读取方」?
triage 评论要求先判定
VITE_USE_MOCK_SERVER属于哪一类、别默默删掉它的文档。答案是死开关,不是丢失的读取方,证据是git log -S:即能力是被有意整体移除的,不是读取方意外丢失。今天全仓
from 'msw'零命中(msw只剩 root / plugin-form / plugin-grid 的 devDependency 残留)。因此不另立「读取方丢失」的单,文档里描述该能力的说法直接删除。二、逐条改写 + 源码锚点
deployment.mdVITE_USE_MOCK_SERVER与VITE_API_URL两行,换成一行VITE_SERVER_URL,默认值写""(同源)AdapterProvider.tsx:101;authapps/console/src/main.tsx:18;i18napps/console/src/loadLanguage.ts:18;actionpackages/app-shell/src/hooks/useConsoleActionRuntime.tsx:255/431/515。默认值取自apps/console/.env.production(VITE_SERVER_URL=留空,文件里写明「published package 嵌进任意 ObjectStack server,不许烤死 origin」)import.meta.env,只在静态托管的运行期设变量无效loadEnv语义;实测见下方「三」.env.production示例VITE_SERVER_URL=https://demo.objectstack.ai,并注明留空即同源examples/console-starter/.env.production就是这个值;apps/console/.env.production是留空那一支VITE_SERVER_URLAccess-Control-Allow-Origin指向 SPA 源 +Access-Control-Allow-Credentials: true),鉴权 cookie 要SameSite=None; Secureapps/console/README.md的 "Additional backend requirements for cross-origin deployments" 1/2 两条 —— 不是我编的,是把已验证过的那段搬到文档站VITE_USE_MOCK_SERVER=false pnpm build→VITE_SERVER_URL=https://demo.objectstack.ai pnpm buildbuild:serverscript defined in the console app.」——build:server这个脚本今天不存在(apps/console/package.json的 scripts 里没有;全仓仅在各 CHANGELOG 的历史条目里出现,与 MSW 一起被 2b7435b 移除)。它就贴在我必须改写的构建命令下面,同属一条死指引,一并改成pnpm build/pnpm build:console的真实口径package.json:build=turbo run build --filter=!@object-ui/site;build:console=pnpm --filter @object-ui/console buildNODE_ENV那一行核对后保留:vite build确实自动置production,描述属实。console.mdVITE_API_URL=http://localhost:3000 pnpm console→VITE_SERVER_URL=http://localhost:3000 pnpm dev,并补一句留空即同源VITE_SERVER_URL是决定连哪个后端的开关pnpm console与 93-95 里那条是同一条死命令(实测ERR_PNPM_RECURSIVE_EXEC_FIRST_FAIL Command "console" not found),只修其一等于继续教坏的那条;5175端口错(真值 5180);「with MSW providing a simulated backend」正是分诊要求删除的那条不存在的能力package.json的dev=pnpm --filter @object-ui/console dev;apps/console/vite.config.ts:320port: 5180;apps/console/.env.development:4VITE_SERVER_URL=http://localhost:3000mocks/ browser.ts # MSW browser worker)apps/console/src/mocks不存在⛔ 未触碰四个
.env文件里的死VITE_USE_MOCK_SERVER(维护者判断,issue 已单列)、未触碰apps/console/vercel.json、未触碰content/docs/releases/。无 changeset(纯 content 文档,沿用 #3524 / #3495 的 docs-only 先例)。三、实测:文档里新写的命令我真跑过
1. 内联
VITE_SERVER_URL能穿透pnpm --filter到 vite,且压过.env.development这条必须实测,因为 AGENTS.md 明写经
pnpm --filter … dev传 env「不可靠」—— 那条是对DEV_PROXY_TARGET(vite.config 读的 Node 侧变量)的结论;VITE_*走 Vite 自己的loadEnv,上面两行是它确实到位的证据。2.
pnpm console确实不存在3.
VITE_SERVER_URL=… pnpm build真的能到达构建 —— 差一点写错的一条pnpm build走 turbo,而turbo.json的build任务只声明了env: ["NODE_ENV", "VITE_BASE_PATH", "OBJECTSTACK_CLIENT_DIST"],VITE_SERVER_URL不在其中;turbo 2.10.7 的默认 envMode 是 strict(未声明的变量会被过滤)。按这个推理,新写的构建命令会是又一条无效指引。实跑 dry-run 才看清真相:turbo 识别出该包是 vite framework,把
VITE_*通配自动纳入,strict 模式下仍然透传。文档里那句「Turbo runs in strict env mode, but it detects the console as a Vite package and passesVITE_*through automatically」写的就是这条实测,不是推断。四、门禁(先写预测,再执行)
预测:全绿且计数不动。
grep -rln显示scripts/、packages/、apps/下没有任何*.test.ts*引用deployment.md/console.md(ci-cd-pipeline-doc.test.ts钉的是另一个页面),因此 204 条不应有任何 verdict 移动;diff 纯文本、不新增文件,check-control-bytes的扫描面数量也应不变。结果与预测逐条一致:
204 与 PR #3524 在同一 main sha 上记录的基线逐个相同 —— 无 verdict 移动。
一条门禁绿≠已验证,得说清楚: 我在
console.md:18新加了页内锚点[Running with a Real Backend](#running-with-a-real-backend),而check-doc-links.mjs:158-159对纯页内锚点是return true直接放行的 —— 它的绿不构成该锚点有效的证据。我自己按标题逐字核对:## Running with a Real Backend→ slugrunning-with-a-real-backend,吻合。这就是这条链接正确性的全部证据。替换后的复查:
五、越界发现(只报不改)
content/里还有 5 处VITE_API_URL,全在本单文件面之外 ——content/docs/utilities/runner.mdx:322/329/429、content/docs/guide/building-crud-app.md:306、content/docs/guide/objectos-integration.mdx:406。性质与本单两处不同:这些是「读者在自己的应用里自定义一个变量、再用自己的import.meta.env读它」的示例代码,不是在教 ObjectUI 自身的环境变量契约,所以不属于「配了没用」那一类。仍建议维护者过一眼(尤其objectos-integration.mdx:406用process.env.VITE_API_URL,在 Vite 应用里是读不到的),但按文件面纪律未动。console.md的 Folder Structure 代码块整体过期 —— 除我删掉的mocks/外,context/ExpressionProvider.tsx目录不存在,components/下列的AppHeader.tsx/AppSidebar.tsx/CommandPalette.tsx/ConsoleLayout.tsx/ObjectView.tsx/RecordDetailView.tsx六项在apps/console/src/components/里一个都没有(实际只有FormPage/MetadataHmrReloader/PerformanceDashboard/RootLandingRedirect/schema,那六个组件早已迁到packages/app-shell)。这是结构性漂移,与本单的死环境变量不同类,整块重写需要另行核对,已另立 issue,不在本 PR 顺手改。deployment.md:12的小瑕疵:「pnpm build(runsturbo run buildacross all packages)」,实际是turbo run build --filter=!@object-ui/site(排除文档站)。同一页但非本单类别,未改。🤖 Generated with Claude Code
https://claude.ai/code/session_01GTRjn8xBqp75dk7kFupVRt
Generated by Claude Code