Repository navigation
Commit 832dc48
perf(app-shell): a cold Console load asks the app bundle the moment the app list answers (#38252)
Fixes #38170
Clause-②: no
Metadata-protocol: none
## 维护者速读
- 用户能看到什么变化:在应用页面冷启动时,控制台拿到应用列表的同一刻就去请求应用包,不再等界面重绘一轮;机器忙时页面标题出现的中位时间从约
2.3 秒降到约 2.0 秒,空闲机器上没有可测的变化。
- 为什么做:属于「控制台首屏 2.5 秒内打开」专题,也是端到端测试在忙碌机器上等标题偶发超时的成因之一。
- 出错会怎样:最坏是应用包被多请求一次或晚一点请求,页面仍按原路读取并正常显示;可直接撤回本改动。
- 要你做什么:无。
## What changes
On an app route the console root (`useAppObjectScopePrefetch`) entered
the app's metadata bundle from an effect of the render that names the
app. On a cold load the app list is still on the wire when that hook
mounts, so a full tree re-render (and the effects after it) sat between
the `GET /api/v1/meta/app` answer and `GET
/api/v1/meta/app/NAME/bundle`. The hook now also asks for the bundle in
the app list's own answer: it joins the provider's eager app-list read
(`ensureType('app')` never asks again), resolves the route segment
against that list exactly as the render does (`matchAppBySegment`:
package id first, then name), and enters that app through the same
adapter. The render-time effect sees that this visit already entered the
app and does not ask again; any other visit (another app, a return after
leaving, an app list already in hand) enters as before.
Only WHEN changes. The request, its adapter and session, the app it
names and the number of requests are the same:
- **Same auth/session**: the bundle is still asked through the adapter's
own `loadAppBundle` (pinned: `this` is the adapter).
- **An app the user cannot see**: the app list is still what names the
app. A route naming an app the list does not hold asks no bundle, before
or after the list lands (pinned). `AppContent`, which draws the refusal,
is untouched.
- **Nothing moved ahead of the permission read**: the root's bundle
entry never waited on `/auth/me/permissions` (the hook sits above the
permission scope by design), and the bundle answer is filtered by the
server's own checks. `AppContent`'s entry, below the permission read, is
unchanged.
- **Same number of requests or fewer**: one bundle request and one
app-list read per cold load (pinned); measured API request counts are
unchanged (below).
## Why
The card's suggested direction was to start the bundle "as soon as the
route names the app". On current main the route cannot name the bundle
on its own: the `/apps/SEGMENT` segment is the package id (ADR-0048) or
the app name, the bundle route is keyed by the app name, a package may
ship several apps, and only the app list says whether this user may see
the app. Asking by segment would fetch a wrong or refused bundle on most
canonical URLs and add a request for apps the user cannot see, so the
earliest point that keeps the invariants is the app list's answer. That
is what this change does.
## Tests
- New top-level `describe` in the shared harness
`appObjectScope-12811.test.tsx` (5 tests): the ordering pin (the bundle
request lands after the app list answers and before the render that
names the app), bundle named by app not by segment through the same
adapter, the hidden-app control, the leave-before-answer control, and
the list-in-hand control (entered once, from the render).
- Ablation, one mutation at a time on the committed fix, restored to the
HEAD blob each time (`scripts/ablation-replace.mjs`, `git diff HEAD`
empty after restore):
- list-answer entry disabled: the ordering pin goes red (`expected 4 to
be less than 3`: the bundle comes after `render:named`), the four
controls stay green.
- render-time de-duplication removed: two tests red (`expected [
'bundle:crm', 'bundle:crm' ] to deeply equal [ 'bundle:crm' ]`).
- The 42 test files that reach the changed hook
(`useAppObjectScopePrefetch`, `enterAppBundle`, `loadAppBundle`,
`ConsoleShell`, `ConnectedShell`, including the App-level boot-wave and
boot-reads-once pins): 42 files, 334 tests passed. The full app-shell
package (2445 test files) was not run locally; CI's `Test UI` runs it.
## Acceptance notes
- Measured on `e3bdc748` (before) and this branch (after), the card's
lane rebuilt locally: backend `objectstack dev --seed-admin --fresh` on
examples/app-showcase, Console `vite build` with `VITE_BASE_PATH=/`,
`vite preview` proxying to it, Playwright Chromium, a fresh context per
load, route `/apps/showcase_app/page/showcase_project_workspace`,
heading `New Project + Tasks`. Before and after were served side by side
from two `vite preview`s and alternated in blocks, 27 cold loads each,
idle and with four CPU-bound processes on a 4-core box. Absolute times
are readings on a shared box.
- **Hop order** (same in both builds): runtime/config + get-session +
discovery, then me/localization, then me/permissions + organization
reads + i18n + `meta/app` + preferences, then the bundle. Three serial
API hops before the bundle request, before and after. The card's
five-hop chain did not reproduce on `e3bdc748`: `me/apps` and
`meta/object?package` leave in the same wave as the bundle, not before
it.
- **What moved** is the render gap inside that last hop:
| median over 27 cold loads | idle before | idle after | busy before |
busy after |
|:---|---:|---:|---:|---:|
| bundle request leaves (ms after goto) | 946 | 764 | 1343 | 974 |
| bundle request leaves after `meta/app` lands (ms) | 226 | 19 | 378 |
17 |
| later of bundle and package list answered (ms, n=12) | 1087 | 1046 |
1557 | 1421 |
| heading visible (ms) | 1668 | 1690 | 2300 | 2035 |
| heading visible, p90 / max (ms) | 1803 / 2295 | 1892 / 2256 | 2700 /
2745 | 2560 / 2687 |
| API requests before the heading | 33 | 33 | 34 | 33 |
- **Heading-ready on an idle box did not move outside noise.** A delay
probe (1.5 s held on one request family, 3 loads each) puts the heading
behind both the bundle and `meta/object?package` (+1.0 to +1.5 s each),
and not behind `me/apps`, `meta/view`, the approvals read, settings,
agents or the inbox reads. The two critical reads leave within ~60 ms of
each other and are answered by the server together, so on an idle box
the bundle's earlier start buys about 40 ms of "both in hand". On the
busy box the gain is larger because the render gap was larger.
- Not reproduced red: the 5 s heading budget held in every load measured
here, before and after (worst 2745 ms before, 2687 ms after), so the
card's second acceptance line (the busy-runner beforeEach wait) is not
shown red-to-green locally; it is the Live E2E UI lane's to confirm.
- What remains on the cold path is outside this card's surface: the gate
between the session answer and the `meta/app` request (sign-in locale,
adapter connect and the route guards in the Console app), the server's
time to answer the bundle and the package object list together, and the
client render after both land (300 to 1000 ms on the busy box).
## Verification
Read first, by risk:
1. `ui/packages/app-shell/src/console/appObjectScope.ts`, the two
effects added before the render-time bundle effect, and the
`enteredByList` check in it: the de-duplication between the two entry
points is the only place a second bundle request could come from.
2.
`ui/packages/app-shell/src/console/__tests__/appObjectScope-12811.test.tsx`,
the `objectstack#38170` describe at the end.
3. `.changeset/38170-bundle-on-app-list.md`.
Two-minute check: `pnpm --dir ui exec vitest run
packages/app-shell/src/console/__tests__/appObjectScope-12811.test.tsx`
from the repository root prints `Tests 28 passed (28)`.
<details><summary>Local gates at 4f299c6: the derived set (38 of 38
run, exit codes captured before any pipe) plus the app-shell type-check
and the narrowed suite</summary>
- exit 0 · `pnpm --filter @object-ui/app-shell type-check`
- exit 0 · `pnpm exec vitest run (the 42 files that reach the changed
hook)`
- exit 0 · `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:adr-anchors`
- 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`
- `node scripts/pm/dispatch-gates.mjs --ran`: 38 derived families
accounted for, 38 run, 0 NOT-MEASURED, 0 UNRUN.
- The app-shell `type-check` ran after building its dependency closure
(`turbo run build --filter='@object-ui/app-shell^...'`, exit 0); both
`tsc` programs exit 0.
- `pnpm exec eslint` on the two changed sources: 0 errors; 3 more
`no-explicit-any` warnings than base, from the test's `as any` casts on
the adapter double, the shape the harness already uses.
- CI owns the rest: `Test UI` (the full app-shell package), `Lint UI`,
`Type Check UI`, `Build & E2E UI`, `Live E2E UI`.
</details>
## Human Minimum
- [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic.
- [x] 2. Every name I added uses the casing for its kind.
- [x] 3. No formatter ran; `pnpm lint` is CI's (`Lint UI`); eslint on
the changed files reports 0 errors.
- [x] 4. One issue, one branch off an up-to-date `main`, one pull
request.
- [x] 5. A change that publishes carries a changeset, and both
declaration lines are filled in here and in the changeset.
- [x] 6. `packages/spec` touched: its generated artifacts are
regenerated and committed. (Not touched.)
- [x] 7. No hand edits to `content/docs/references/`,
`packages/*/CHANGELOG.md` or `content/docs/releases/`.
- [x] 8. Title, body and comments are in English.
- [x] The *Before Submitting* list in CONTRIBUTING.md is done.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_017xRBcWDb7S8Z7oRDGzvfT2
---
_Generated by [Claude
Code](https://claude.ai/code/session_017xRBcWDb7S8Z7oRDGzvfT2)_
---------
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: objectstack-fleet[bot] <332303061+objectstack-fleet[bot]@users.noreply.github.com>1 parent 975e34e commit 832dc48
3 files changed
Lines changed: 210 additions & 2 deletions
File tree
- .changeset
- ui/packages/app-shell/src/console
- __tests__
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
617 | 617 | | |
618 | 618 | | |
619 | 619 | | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
| 758 | + | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
| 768 | + | |
| 769 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
88 | 88 | | |
89 | 89 | | |
90 | 90 | | |
91 | | - | |
| 91 | + | |
92 | 92 | | |
93 | 93 | | |
94 | 94 | | |
| |||
926 | 926 | | |
927 | 927 | | |
928 | 928 | | |
| 929 | + | |
| 930 | + | |
| 931 | + | |
929 | 932 | | |
930 | 933 | | |
931 | 934 | | |
| |||
989 | 992 | | |
990 | 993 | | |
991 | 994 | | |
| 995 | + | |
| 996 | + | |
| 997 | + | |
| 998 | + | |
| 999 | + | |
| 1000 | + | |
| 1001 | + | |
| 1002 | + | |
| 1003 | + | |
| 1004 | + | |
| 1005 | + | |
| 1006 | + | |
| 1007 | + | |
| 1008 | + | |
| 1009 | + | |
| 1010 | + | |
| 1011 | + | |
| 1012 | + | |
| 1013 | + | |
| 1014 | + | |
| 1015 | + | |
| 1016 | + | |
| 1017 | + | |
| 1018 | + | |
| 1019 | + | |
| 1020 | + | |
| 1021 | + | |
| 1022 | + | |
| 1023 | + | |
| 1024 | + | |
| 1025 | + | |
| 1026 | + | |
| 1027 | + | |
| 1028 | + | |
| 1029 | + | |
| 1030 | + | |
| 1031 | + | |
| 1032 | + | |
| 1033 | + | |
| 1034 | + | |
| 1035 | + | |
992 | 1036 | | |
993 | 1037 | | |
994 | 1038 | | |
995 | | - | |
| 1039 | + | |
| 1040 | + | |
| 1041 | + | |
| 1042 | + | |
| 1043 | + | |
996 | 1044 | | |
997 | 1045 | | |
998 | 1046 | | |
| |||
0 commit comments