Repository navigation
Commit 121017b
fix(app-shell): Home sends its deployment-notice, authorized-clients and API-key reads once per load (#34097)
<!-- claude-projects-attribution: {"github_login":"os-steve"} -->
_Requested by **Steve** · [project
thread](https://claude.ai/code/project/chan_01FdL1XeUyvVNxLreh3F4Qi9?thread=cmsg_01FdL1XeUyvVNxLreh3F4Qi9W6PBGd35eGZ3aW4WwdNVYk)_
Fixes #28085
Clause-②: no
Metadata-protocol: none
## 维护者速读
- 改了什么:首页冷加载时,部署提示、已授权 AI 助手、API 密钥这三个读取各只发一次(之前在打包后的控制台上分别是 2 次、3 次、3
次);列表页本来就每个 URL 只读一次,不变,现在由一个新的请求计数测试钉住(带消融)。
- 为什么改:首页先画一帧完整页面、再切成"加载中"、再画一遍,里面的组件被挂载两次;另外"连接 AI
助手"卡片和管理员首次使用清单各自读同一份数据。每次打开首页白白多 5 次请求。
- 风险与回滚:产品代码只动 `@object-ui/app-shell` 两个文件(另加一个控制台测试文件);首页现在在 `/me/apps`
回答之前显示"加载中"(这本来就是该标志声明的行为)。回滚即 revert 本 PR。
-
先看:`ui/packages/app-shell/src/hooks/useLauncherApps.tsx`(`firstReadDue`)、`ui/packages/app-shell/src/console/connect/connectedAccess.ts`(共享读取的生命周期)。
- 两分钟验证:`pnpm --dir ui exec vitest run
packages/app-shell/src/hooks/__tests__/useLauncherApps-26838.test.tsx
packages/app-shell/src/console/connect/ConnectAgentWidget.connected-30898.test.tsx`,预期
29 个用例全绿;列表页钉子:`pnpm --dir ui exec vitest run
apps/console/src/__tests__/App.listPageBootReadsOnce-28085.test.tsx`,预期
1 个用例绿。
- 需要你做的:无,席位落地。
## What changes
Step 0 measured the card on a **production** console build (`pnpm
console:build`, served by `objectstack dev --ui --fresh` from
`examples/app-showcase`, seeded admin, headless Chromium 1440×900, a
fresh page per load after sign-in, GETs under `/api/` counted from
navigation to network idle plus 3 s), on `main` `bc6b7ffd`:
- **List page** (`showcase_task` ×4, `showcase_account` ×1): every URL
is read once. `auth/get-session`, `meta/app`, `auth/me/permissions` and
`me/apps` read 1 each, and `meta/object?package`, `sys_user_preference`
and `me/localization` read 1 each too. The doubling the card names is
still React.StrictMode's development replay, which this PR does not
touch.
- **Home** (×1, then ×2 with response times): `GET
/api/settings/deployment/notice` ×2, `GET
/api/v1/auth/authorized-clients` ×3, and the `sys_api_key` list ×3.
**None of them overlapped**: each repeat started after the previous one
had answered. So sharing an in-flight request (the card's "Wanted")
could not remove them. The causes, traced on the Console dev server with
StrictMode turned off locally (a local edit, restored) and a React
DevTools hook recording mounts:
1. **Home mounted its children twice.** `HomePage` waits on
`useLauncherApps().pending` so it never draws a tile `/me/apps` then
hides. `LauncherAppsProvider` set `pending` only from its effect, after
the first commit, so the first frame had nothing pending and nothing
narrowed. Home drew its page (mounting `DeploymentNotice` and
`ConnectAssistantCard`, which read on mount), switched to its loading
state when the effect published `pending`, then drew the page again when
the answer came. Now the provider answers `pending` from the render that
makes the first read due. Home draws the page once, after the answer.
This also removes the first frame that drew a hidden app's tile, which
the hook's own doc says never happens.
2. **Two readers of one answer.** Home draws the Connect an AI Assistant
card and, for an administrator, the first-run checklist. Both call
`useConnectedAccess`, and each owned its own effects, so each sent
`authorized-clients` and the `sys_api_key` list. The checklist's reader
enables later (after the settings read), so its requests came after the
card's had answered. `useConnectedAccess` now reads through a store
shared by every reader mounted at the same time, keyed by adapter and
person. A reader that mounts while the entry lives joins its answer or
its reads in flight. A change to `sys_api_key` or `sys_oauth_consent`
re-reads that record once for all readers. The entry is dropped with its
last reader, so a page mounted later reads afresh, as it did before. The
store's subscribe/getSnapshot pair is keyed on the adapter and person
outside React, not on a memoised callback (ui `AGENTS.md` #10).
Both are one-place fixes at the source of each repeat. Neither is a
per-call-site guard.
<details><summary>Readings: production console, before and
after</summary>
Before (`main` `bc6b7ffd`), Home, one load: 35 GETs; repeated URLs
`deployment/notice` ×2, `authorized-clients` ×3, `sys_api_key` list ×3.
Timeline of the repeats (ms from navigation, start → end):
```
deployment/notice 977 → 1075 1116 → 1305
authorized-clients 979 → 1098 1117 → 1335 1375 → 1430
sys_api_key list 979 → 1109 1119 → 1342 1376 → 1433
```
After (head of this PR, console rebuilt), Home ×3: 30 GETs each, no URL
repeated; `deployment/notice` 1, `authorized-clients` 1, `sys_api_key`
list 1, `me/apps` 1, `meta/app` 1, `me/permissions` 1, `get-session` 1.
List page, before ×5 and after ×3 (`showcase_task`, `showcase_account`):
26 GETs each, no URL repeated; the card's four reads 1 each (`meta/app`
and `meta/app/showcase_app/bundle` are two different URLs).
Dev server, StrictMode off, mounts recorded through a React DevTools
hook (before the fix): `DeploymentNotice` and `ConnectAssistantCard`
mounted twice under the same `HomePage` element, each mount followed by
its reads; after fix 1, once; after fix 2, `authorized-clients` and the
`sys_api_key` list are sent once, with the checklist mounted.
</details>
## Tests
- `useLauncherApps-26838.test.tsx`, new top-level describe `the first
/me/apps read is pending from the first render`: a page behind Home's
gate mounts once, so a child that reads on mount reads once per load (a
request count); `pending` is true in the very first render when a read
is due; and false when none is due (no user, metadata loading, no apps).
- `ConnectAgentWidget.connected-30898.test.tsx`, new `§7 one pair of
reads per page, however many readers`: two readers mounted together send
each request once; a reader mounting after the answer joins it; a
`sys_api_key` change re-reads that record once for both; a page mounted
after every reader left reads afresh.
-
`ui/apps/console/src/__tests__/App.listPageBootReadsOnce-28085.test.tsx`
(new, the card's acceptance pin): a list page (`/apps/crm/crm_contact`)
loads through the real route tree with the boot `main.tsx` runs, the
real `preflightAuth`, then `App` with the real `AuthProvider`,
`AuthGuard`, `ConnectedShell` (real `ObjectStackAdapter` and
`MetadataProvider`), `RequireOrganization`, the `/me/permissions` scope
and `LauncherAppsProvider`, over one stubbed global `fetch` that records
every URL. `auth/get-session`, `meta/app`, `auth/me/permissions` and
`me/apps` are counted at exactly one request each. Only the app's own
content and the pages off the route are stubbed, as in the sibling
`App.rootLandingReadsOnce-32633`. No `React.StrictMode`, since a built
console does not replay effects.
- No existing test was edited.
<details><summary>Ablations (mutation through
scripts/ablation-replace.mjs, restored to HEAD, git diff HEAD
empty)</summary>
- `useLauncherApps.tsx`: `const state = firstReadDue ? PENDING :
heldState;` → `const state = heldState;` — 2 failed / 9 passed: `a page
behind the gate mounts once…` ("expected vi.fn() to be called 1 times,
but got 2 times") and `is pending in the very first render…` ("expected
[ false ] to deeply equal [ true ]").
- `connectedAccess.ts`: `let entry = byUser.get(userId);` → `let entry:
SharedReads | undefined = undefined;` (one entry per reader) — 3 failed
/ 15 passed: two readers together, the late reader, and the re-read on
change.
- List-page pin, `ui/packages/auth/src/createAuthClient.ts`
(`takePreflightSession`, the handoff that keeps the boot at one
`get-session`): ` if (!slot || slot.taken) return null;` → ` if (!slot
|| slot.taken || true) return null;` — 1 failed / 0 passed: `expected {
'auth/get-session': 2, …(3) } to deeply equal { 'auth/get-session': 1,
…(3) }`. Restored: blob == HEAD (`ab510ed0c019`), `git diff HEAD` empty.
</details>
## Acceptance notes
- The card's acceptance, "a list page load makes one request per URL for
the four reads", held on a built console without a product change, as
the 2026-10-31 reading (6538476483) found. The four doubled only behind
the Vite dev server with StrictMode, and the order for this card says
not to "fix" that. It is now pinned by
`App.listPageBootReadsOnce-28085.test.tsx` with the ablation above (the
card's claim amendment widened the surface to that one file).
- The QA reading on the card (6765285185) also named `sys_audit_log` and
`sys_user` ×2 on a record page. Not measured here (record page outside
this card's step 0).
- `me/localization`, which that reading saw ×2 on the list page, read
once on the built console; its files are held for #33985 and are
untouched.
## Verification
All on head `1feba497` (merge base `bc6b7ffd`), after the last commit.
The product files are unchanged since `76497be1`; that round's app-shell
checks (`pnpm --filter @object-ui/app-shell type-check` exit 0; `cd ui
&& pnpm exec vitest run packages/app-shell/ --maxWorkers=2` under the
verify lock, Test Files 2270 passed / 1 skipped, Tests 21007 passed / 9
skipped, exit 0) stand for them.
- `cd ui && pnpm exec vitest run
apps/console/src/__tests__/App.listPageBootReadsOnce-28085.test.tsx
apps/console/src/__tests__/App.rootLandingReadsOnce-32633.test.tsx`,
twice: 2 files, 3 tests passed each time (the new pin also passed alone
once before the ablation).
- `pnpm --filter @object-ui/console type-check` (covers the new test
file) — exit 0.
- Consumers of the two hooks (round 1, unchanged files):
`FirstRunChecklist.test.tsx` and the console
`App.permissionsWave-29114`, `App.homePermissions-12700`,
`App.rootLandingReadsOnce-32633`, `App.linkRefusalLanding-33063` suites
— green.
- `node scripts/pm/dispatch-gates.mjs --ran` on `1feba497` — 37 derived
(the same 37 as round 1), 37 run, 0 NOT-MEASURED, 0 UNRUN; the whole
round under the verify lock, every family exit 0 on the first run.
- `pnpm check:new-line-citations` (ui) — 0 new citations.
- Dogfood battery: not run — no `!` in the title and no `(narrowing)`
arm.
- The CI families (Lint & Repo Gates, Type Check UI, Test UI, Build &
E2E UI, the rest of the required set) are this PR's check-runs.
<details><summary>Derived gate ledger on 1feba49 (CMD ::
exit)</summary>
```
node scripts/check-adr-0087-registration.mjs --base origin/main :: exit 0
node scripts/check-adr-0087-registration.mjs --self-test :: exit 0
node scripts/check-changeset-no-major.mjs --base origin/main :: exit 0
node scripts/check-closing-keyword-parity.mjs :: exit 0
node scripts/check-closing-keyword-parity.mjs --self-test :: exit 0
node scripts/check-comment-mask-corpus.mjs :: exit 0
node scripts/check-empty-changeset.mjs --base origin/main :: exit 0
node scripts/check-empty-changeset.mjs --self-test :: exit 0
node scripts/check-sdui-manifest.mjs :: exit 0
node scripts/check-sdui-manifest.mjs --self-test :: exit 0
node scripts/ci/snapshot-next.mjs --self-test :: exit 0
node scripts/pm/check-governed-queue-guard.mjs --self-test :: exit 0
node scripts/pm/release-rehearsal-clone.mjs --self-test :: exit 0
node scripts/release-pending-publish.mjs --self-test :: exit 0
pnpm --dir ui exec vitest run scripts/ :: exit 0
pnpm --filter @objectstack/spec run check:duration-unit-keys :: exit 0
pnpm check:changeset-gate-self-tests :: exit 0
pnpm check:closed-ceremony-text :: exit 0
pnpm check:cross-package-test-inputs :: exit 0
pnpm check:dispatcher-error-vocabulary :: exit 0
pnpm check:driver-memory-census :: exit 0
pnpm check:engine-double-contract :: exit 0
pnpm check:gitlink-declared :: exit 0
pnpm check:nul-bytes :: exit 0
pnpm check:published-files :: exit 0
pnpm check:query-options-erasure :: exit 0
pnpm check:refd-timer-probe :: exit 0
pnpm check:registry-log-declared :: exit 0
pnpm check:rest-log-spy-declared :: exit 0
pnpm check:skill-identifier-liveness :: exit 0
pnpm check:test-source-alias :: exit 0
pnpm check:tier-file-adoption :: exit 0
pnpm check:type-check-coverage :: exit 0
pnpm check:type-check-debt :: exit 0
pnpm check:undeclared-dep-imports :: exit 0
pnpm check:watch-hint-literal :: exit 0
pnpm check:where-matcher :: exit 0
```
</details>
---
_Generated by [Claude
Code](https://claude.ai/code/session_01ADHkmPiLw38ErmCpnkcQvh)_
<!-- signed: domain:ui#2 · os-steve · session_01ADHkmSzhXR4yUAgwq1bQRi
-->
---------
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: objectstack-fleet[bot] <332303061+objectstack-fleet[bot]@users.noreply.github.com>1 parent 27298b8 commit 121017b
6 files changed
Lines changed: 500 additions & 51 deletions
File tree
- .changeset
- ui
- apps/console/src/__tests__
- packages/app-shell/src
- console/connect
- hooks
- __tests__
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
29 | | - | |
| 29 | + | |
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| |||
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
63 | | - | |
| 63 | + | |
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
| |||
303 | 303 | | |
304 | 304 | | |
305 | 305 | | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
0 commit comments