fix(app-shell): 伪路由开关改按路径段判断,拼错 app 名不再静默渲染别的 app (#3638) - #3654
Merged
Conversation
… not substrings (#3638) `isSystemRoute` / `isMetadataRoute` were `pathname.includes('/system')` / `includes('/metadata')`, so any segment merely STARTING with the word (`system_log`, `systems`, `metadata_import`) flipped `isSpecialRoute`. That suppressed `requestedAppMissing`, bypassing the "App not available" guard, and `/apps/<mistyped-app>/system_log` silently rendered the DEFAULT app's shell with the near-miss segment as its `:objectName`. Both flags now test whole path segments. `isCreateAppRoute`'s `endsWith` is unchanged. The live input surface was enumerated from the route tables and navigation targets first and pinned as regression assertions — every real pseudo-route spells `system` / `metadata` as a full segment, so all of them stay special, including the zero-app branch that keys on these flags directly (#3590 / #3610). 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. |
Contributor
✅ Console Performance Budget
📦 Bundle Size Report
Size Limits
|
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 #3638
问题
AppContent在决定「渲染哪个 app」之前先判断 URL 是不是内建伪路由。三个开关里有两个是子串判断:includes('/system')对任何以system开头的段都为真(system_log/system_setting/systems),metadata同理(metadata_import/metadata-export)。isSpecialRoute喂给requestedAppMissing,于是/apps/{拼错的app名}/system_log:matchedApp为 undefined;isSystemRoute被system_log误命中 →isSpecialRoute为真;requestedAppMissing因此为 false,「App not available」守卫不触发;activeApp回退成默认 app,渲染它的 shell,并把system_log当作该 app 下的:objectName。用户看到的是另一个 app 的界面,没有任何提示说所请求的 app 不存在 —— 正是 fallback 上方那段注释("A normal unmatched appName must NOT silently render a DIFFERENT app")要防的事。
改法
切路径段判断,不是正则:
选段判断而不是
/\/system(\/|$)/的理由:本文件相邻的isSetupRoute已经是=== / startsWith的字面量比较风格,全文件没有第二处路由正则;段判断读起来即是「某一段就叫 system」,与 issue 里三条伪路由的语义一字对应。isCreateAppRoute的endsWith未改动(它判的是末段,本来就没有这个歧义)。顺带把 no-app 分支里一句已经过时的注释("a substring test on
/metadata")改写为段判断的说法。先量后收:今天依赖宽松判断的真实输入面
以路由声明 + 导航目标为准枚举(grep
path=/navigate(/url:/href:),不臆测。逐条都写成了「收紧后仍为真」的回归断言:system/metadata是否整段/apps/{app}/system/marketplace{,/installed,/:packageId}console/AppContent.tsx路由表(两个分支都声明)/apps/{app}/metadata{,/_diagnostics,/:type,/:type/new,/:type/:name,/:type/:name/history}console/AppContent.tsx路由表/apps/{app}/component/metadata/{directory,resource/*}(#3610 的别名,?type=在 query 上不参与判断)console/AppContent.tsx两个分支/apps/{app}/system、system/{apps,profile,approvals,ai-approvals,audit-log,settings,settings/:namespace}apps/console/src/AppContent.tsx的extraRoutes/apps/{app}/system/{objects,objects/:objectName,metadata,metadata/:type,metadata/:type/:itemName}(legacy → 引擎的两跳重写)systemRoutes+MetadataRedirectsys-*簇:/apps/setup/system{,/apps,/marketplace,/users,/organizations,/roles,/settings}、/apps/setup/system/metadata/object、/apps/setup/component/metadata/resource?type=datasourceAppSidebar.tsx/UnifiedSidebar.tsxQuickActions/HomePage/InboxPopover:/apps/setup/system/{metadata/object,marketplace,approvals}/system书签经SystemRedirect(#3637)落到/apps/setup/systemconsole/SystemRedirectextraRoutes的developer{,/api-console,/flow-runs,/public-forms,/integrations}、docs{,/:slug,/:slug/:name}apps/console/src/AppContent.tsx/apps/setup{,/**}整族isSetupRouteisSetupRoute,与本 PR 无关结论:今天没有任何一条活路由把
system/metadata写成段的前缀,所以段判断不黑洞任何一条。第 9、10 行是边界,专门钉住「本 PR 没有顺手改它们」。两个 flag 到底在哪里承重
不是「为真的地方」都承重。app 段能匹配上时两个 flag 什么都不改变(
activeApp已由matchedApp决定)。它们只在两种情形下决定行为,测试两种都覆盖::568与:616两个!activeApp守卫直接读isSystemRoute/isMetadataRoute(console: 零应用空态的另一颗按钮 go-to-settings-btn 同样是死键——/apps/setup 渲染的正是这个空态本身 #3590 / console: 零应用下 sys-objects / sys-datasources 落到 /apps/setup/component/... 渲染空白屏——无-activeApp 分支既无 component/* 路由也无 catch-all #3610 建的那条分支)。消费面行为矩阵(行号以本 PR 基线实测)
isSpecialRoute的消费点::198(activeApp 回退)、:207(requestedAppMissing);requestedAppMissing再被:527(preview 空态)与:547(App not available)消费;:568(零应用空态)与:616(零应用伪路由分支)直接读两个 flag。/apps/ghost/system_log:547)/apps/ghost/metadata_import:547)/apps/ghost/system_log/record/abc123/apps/crm/system_log(app 存在)matchedApp命中,flag 不参与)/apps/ghost/system/marketplace等表 1–7 全部:616伪路由分支/apps/setup/system_log:616分支的 catch-all →「Page not found」:568) ← 见下最后一行是实测出来的连带变化,不是设计目标:零应用下
/apps/setup/system_log这种「以 system 开头的臆造 URL」从 404 变成空态。两块屏幕都不撒谎,变化在于system前缀的错字不再是特例 —— 它现在和/apps/setup/no-such-page落到同一块屏幕(那条已被AppContent.noAppComponentRoutes.test.tsx的 MEASUREMENT 用例钉住)。已在新测试里以MEASUREMENT:用例原样钉住并写明原委。逆向验证(先预测,后跑)
预测写在改代码之前:
system_log/system_setting/systems/metadata_import/metadata_log/metadata-export+ 深层system_log/record/abc123)7 条断言在未改动的 main 上必须红,且红的形态是「渲染了 crm 的 shell」,不是别的。跑出来与预测一致。修前(未改
AppContent.tsx,只加测试):8 红正是 P1/P2 的 7 条 + P4 的 1 条;28 绿正是 P3 的全部回归断言。修前失败现场直接把 bug 的形态打印了出来 ——
/apps/ghost/system_log渲染的是:修后:
测试证据
新测试文件按「消费半径」扫过:两个 flag 只在
AppContent内被读,但它们服务的路由由宿主apps/console声明,所以宿主那 23 个测试文件也跑了一遍。文件面
packages/app-shell/src/console/AppContent.tsx— 两行判断 + 注释packages/app-shell/src/console/__tests__/AppContent.pseudoRouteSegments.test.tsx— 新增(36 条).changeset/pseudo-route-segment-flags-3638.md— patch未改动:
#3636的AppContent.noAppComponentRoutes.test.tsx、#3573/#3590的AppContent.noAppsCta.test.tsx(只读不改,两者全绿)、导航侧文件、locale 包、content/docs/releases/。🤖 Generated with Claude Code
https://claude.ai/code/session_01GTRjn8xBqp75dk7kFupVRt
Generated by Claude Code