Skip to content

fix(web): centralize CSR route readiness and preserve initialization behavior - #2

Merged
c121914yu merged 2 commits into
DigHuang:fix/i18nfrom
c121914yu:codex/pr-7829-csr-ready
Oct 8, 2026
Merged

c121914yu merged 2 commits into
DigHuang:fix/i18nfrom
c121914yu:codex/pr-7829-csr-ready

Conversation

@c121914yu

@c121914yu c121914yu commented Oct 8, 2026 •

Copy link
Copy Markdown

本 PR 基于 fix/i18n,用于补充修复 labring#7829,作者合并后即可更新原 PR。

CSR 首次 hydration 时,路由 query 尚未就绪,列表请求和表单初始化可能读取到缺失的参数。现在在 AppShell 中统一等待路由首次就绪,再挂载 AppContent、Layout 和页面,移除三个列表 Context 中重复的 disabled: !router.isReady 以及创建页的局部等待包装。

门禁仅在首次启动时等待,开启后不再关闭,因此后续路由变化不会因这个门禁卸载业务组件、额外丢失编辑状态或新增白屏。正常跨页面导航仍遵循 Next.js 原有的挂载和卸载行为;SSR 页面直接放行,原有 i18n 资源加载等待仍保留。

另外修复两处 CSR 迁移后的兼容问题:

  • /chat 和 /chat/share 的 SSR namespace 声明补上 account_team,将全局 Layout 强制成员名弹窗所需的资源随页面 props 注入,避免裸显翻译 key。组件继续使用无参数 useSafeTranslation(),无需新增组件级加载接口。
  • 无 sourceDomain 时仍调用营销归因 helper,恢复 document.referrer 兜底及首次来源锁定行为。

同步更新现有 CSR i18n 设计文档,说明首屏门禁、后续导航及 SSR 页面资源声明约定。

验证:

  • 本轮 18 项局部测试通过,覆盖四种语言的成员名文案、营销来源兜底及初始化时机;此前路由门禁、AppShell、相关列表和成员名表单验证已通过。
  • 从两个聊天页实际声明中读取 namespace,调用真实 serverSideTranslations,验证四种语言的 SSR 资源均包含成员名标题、占位文案、按钮及校验文案(8 种页面/语言组合)。
  • ClientRouteReadyGate 的语句、分支、函数和行覆盖率均为 100%。
  • 应用生产源码及改动测试文件的 TypeScript 检查通过。
  • 改动文件 ESLint 和 Prettier 检查通过;创建页原有 React Hook Form watch 警告保留。
  • 提交前 lint-staged 及 git diff --check 通过。未运行全量测试或生产构建。

Copilot AI balanced review requested due to automatic review settings October 8, 2026 14:54

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

The centralized gate preserves SSR and navigation behavior, with focused coverage for the affected initialization paths.

0 open findings

What changed in this PR

Centralizes initial CSR route-readiness gating for labring#7829 while preserving SSR, navigation state, i18n loading, and marketing attribution behavior.

Changes:

  • Adds a one-time route-readiness gate around CSR application initialization.
  • Removes redundant page-level readiness checks and adds SSR namespace loading.
  • Restores referrer-based attribution and expands targeted tests/documentation.
File Description
projects/​app/​src/​web/​context/​ClientRouteReadyGate.tsx Adds the one-time CSR readiness gate.
projects/​app/​src/​web/​context/​AppShell.tsx Applies the gate around CSR content.
projects/​app/​src/​web/​context/​useInitApp.ts Restores referrer attribution fallback.
projects/​app/​src/​pages/​dashboard/​create/​index.tsx Removes the local readiness wrapper.
projects/​app/​src/​pageComponents/​dataset/​list/​context.tsx Removes redundant router readiness guards.
projects/​app/​src/​pageComponents/​dashboard/​skill/​context.tsx Removes redundant router readiness guards.
projects/​app/​src/​pageComponents/​dashboard/​agent/​context.tsx Removes redundant router readiness guards.
packages/​web/​hooks/​useSafeTranslation.ts Supports explicit namespace loading.
projects/​app/​src/​pageComponents/​account/​team/​MemberNameForm/​useMemberNameForm.ts Declares the team namespace.
projects/​app/​src/​pageComponents/​account/​team/​MemberNameForm/​index.tsx Declares the team namespace.
projects/​app/​src/​components/​Layout/​ForceMemberNameModal.tsx Declares the team namespace.
projects/​app/​test/​web/​context/​ClientRouteReadyGate.test.ts Tests gate hydration and navigation behavior.
projects/​app/​test/​web/​context/​AppShell.test.ts Tests application initialization ordering.
projects/​app/​test/​web/​context/​useInitApp.test.ts Tests marketing initialization behavior.
projects/​app/​test/​web/​support/​marketing/​utils.test.ts Tests referrer fallback.
packages/​web/​test/​i18n/​useSafeTranslation.test.ts Tests namespace loading and translation behavior.
.agents/​design/​common/​client-i18n-csr-migration.md Documents the updated CSR/SSR conventions.

🧠 Review effort: Balanced


Give feedback about Copilot approvals in this survey to enter a drawing for a $150 gift card.

@c121914yu
c121914yu merged commit 559e931 into DigHuang:fix/i18n Oct 8, 2026
2 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