Skip to content

fix(workbench): stop double-prefixing the conversation route guard re… - #4558

Merged
YehongPan merged 3 commits into
developfrom
fix/conversation-route-guard-basepath
Dec 4, 2026
Merged

YehongPan merged 3 commits into
developfrom
fix/conversation-route-guard-basepath

Conversation

@jeffwu-1999

@jeffwu-1999 jeffwu-1999 commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

问题

子路径部署(如 /nexent)下,工作台创建的自动任务点"详情"必 404:地址栏出现双重前缀 /nexent/nexent/zh/workbench?conversation_id=N。

根因

useConversationRouteGuard(#4010 引入)给 router.replace 传了 withBasePath(...) 手动加过前缀的路径,而 Next.js router 内部 addBasePath 会再加一次(构建期内联的 __NEXT_ROUTER_BASEPATH)。根路径部署时 BASE_PATH 为空,加不加都一样,bug 隐形;#4502 让子路径部署可用后暴露。

触发链:工作台建定时任务 → 任务绑定 workbench 会话 → 详情链接写死指向 /newchat → 守卫判定类型不匹配需重定向 → 双拼 404。newchat 里建的任务(普通会话)不触发重定向,故不炸——这解释了现网"有的账号炸有的不炸"。

本地已用 CONFIGURED_BASE_PATH=/nexent 构建镜像完整复现(conversation 293 双前缀 404)。

修复

  • 守卫 router.replace 去掉 withBasePath 包裹,传应用内路径,加前缀职责还给框架(附注释说明契约)
  • 测试:原 withBasePath 恒等 mock 掩盖了 bug,改为真实前缀行为 mock;新增子路径回归断言(传给 router 的路径不得带前缀)

验证

20261204145400_rec_
  • 负向证明:回退守卫修复 → 3 例全红;恢复 → 全绿
  • workbench 全量 1018 例:985 过;33 个失败经基线对照确认为 develop 既有失败,与本改动无关
  • 现网临时兜底:nginx rewrite ^/nexent/nexent/(.*)$ /nexent/$1 permanent; 本修复合入后可撤

影响面

仅守卫重定向一处;分享链接(#4502)等 window.location/剪贴板场景的手动加前缀是正确的,不受影响。

…direct

The guard wrapped its router.replace href in withBasePath, but the Next.js
router already prepends the configured basePath internally. Under subpath
deployments this produced /nexent/nexent/zh/workbench -> 404 whenever an
automation-task detail link opened a workbench conversation through newchat.

Pass an app-internal path and let the router own the prefix. Replace the
identity withBasePath mock (which hid the bug) with a real-prefix mock and
add a subpath regression assertion; verified red before / green after.
@YehongPan
YehongPan merged commit 7bdd837 into develop Dec 4, 2026
8 checks passed
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