Skip to content

Commit 1c1a5d4

Browse files
perf(data-objectstack)!: an object route reads that object's saved views, not every view of every object (#29634)
domain:ui#4 · zhuangjianguo · session_01QsR2jR7ZFkpqmm4U8S1f9y <!-- claude-projects-attribution: {"github_login":"zhuangjianguo"} --> _Requested by **Steedos** · [project thread](https://claude.ai/code/project/chan_018ETKaNwMZCNRYD7D8Q9Ubb?thread=cmsg_018ETKaNwMZCNRYD7D8Q9UbbSdbhcPy8LxJmPaZb2ECoEq)_ Fixes #29550 Clause-②: no (narrowing) Metadata-protocol: none Claim: 6586963407 · amendments: 6587053002, 6587483534, 6591325082 ## 维护者速读 - 改了什么:对象页的已保存视图(`listViews`)和视图设置(`listViewOverrides`)不再下载所有对象的全部视图。没有别的读取在加载整张视图列表时,两者合用一次 `GET /api/v1/meta/view?object=对象名`(ADR-0017 §3.5)。整张列表已加载或正在加载时,直接从它取,不再发请求。 - 为什么改:控制台创建的应用(无包)打开对象页时,`listViews` 是唯一下载整张 `/meta/view` 的读取。app-crm 上 crm_account 从 7,452 B 降到 395 B,crm_lead 从 7,452 B 降到 3,677 B,请求数不变。有包的应用对象页在 #29609(已合入 main)之后,`listViews` 也是唯一的整表读取;本分支合并 main 后,这些页面同样只发 `?object=`(crm_lead 3,239 B,showcase_project 4,763 B)。 - 风险与回滚:这是收窄。没有 `viewKind` 或顶层 `object` 的旧视图行(#7741 写入门之前存的)不再显示为页签,草稿预览也一样。服务端的按对象读取本来就不返回这种行。app-crm 和 showcase 新部署上没有这种行,控制台今天保存的视图两个字段都有。补救是在控制台里重新保存该视图。视图顺序改为契约顺序(`order`,再 `name`),控制台可见的视图切换器顺序在三个路由上实测不变。回滚方法是 revert 本 PR。 - 先看:`ui/packages/data-objectstack/src/index.ts` 的 `readObjectViewRows`(三条路径:已存列表、正在读的列表、按对象读取)和 `objectBoundViewRows`(规则);`cache/MetadataCache.ts` 的 `peekInflight`。 - 两分钟验证:新建一个不带包的应用,放一个对象入口,打开该对象页,在开发者工具 Network 里过滤 `meta/view`:应该只有 `GET /api/v1/meta/view?object=<对象名>`,没有不带参数的 `/meta/view`。 - 需要你做的:无,席位落地。 ## What changes `ObjectView`'s saved-views overlay calls `dataSource.listViews(objectName)` on every object route (`ObjectView.tsx:416`), and its override merge calls `listViewOverrides(objectName)`. Both went through the adapter's private `readViewList()`. It downloaded every view of every object (`GET /api/v1/meta/view`) to keep one object's rows. `ObjectView.tsx` is unchanged. Both readers now go through one private helper, `readObjectViewRows(objectName)` in `@object-ui/data-objectstack`: | The whole view list (`list:view` in the metadata cache) | What the readers do | |---|---| | stored (Studio, the MetadataProvider, or an earlier read loaded it) | Answer from it. No request. | | on the wire (a packaged app's object scope reads it for out-of-bundle lookup targets, #29551) | Join that read. No request of their own. `MetadataCache.peekInflight` is new. The class is not exported from the package, and the method is absent from `dist/index.d.ts`. | | neither | `GET /api/v1/meta/view?object=OBJECT` (ADR-0017 §3.5: "the aggregation query that powers the switcher"). Both readers share it while it is in flight, and its answer is stored for the next read, as the whole list's is. | **Drops (amendment 6591325082).** The one-object answer is stored under a metadata-cache key that names the last invalidation of the whole list (`list:view@N?object=OBJECT`, with `N` from the new `MetadataCache.droppedAt`). Every path that drops the whole list also moves that key: a view write through any door (`invalidateViewKeys`, the client write wrap, the console client's `invalidateCache('list:view')`) and an organization, session or locale switch (`clearCache`). So after a drop, the stored one-object answer no longer answers, a request sent before the drop is detached, and the next read asks again. The key a drop retired is dropped on the next read rather than left to the LRU. Every path keeps the same rows in the same order (`objectBoundViewRows`): the server's rule (`createMetaListAnswer` step 4 in `packages/rest/src/meta-item-read-gate.ts`), which is `viewKind` set, `object` naming the object, sorted by `order` then `name`. A server that ignores `?object=` answers its whole list, and the rule still keeps one object's rows. The draft preview (`listViews(obj, { previewDrafts: true })`) keeps its own `?preview=draft` read and applies the same rule to its rows (amendment 6587483534 (1)). Neither client spells `?object=`. `client.meta.getItems` takes a package, and `MetadataClient`'s list takes a package and an include. So the request is built in the adapter, the way `downloadImportTemplate`'s is: the adapter's origin and auth headers, the client's `Accept-Language`, and `credentials: 'include'`. A non-2xx answer rejects with the server's `status` and ADR-0112 `code`, so `listViews` still degrades to `[]` with a `refused` read warning, and `listViewOverrides` still rejects. `listViews`' and `listViewOverrides`' signatures and answer shapes are unchanged. The private `readViewList()` is removed. ### The narrowing (Clause-②: no (narrowing)) A `view` row with no `viewKind` or no top-level `object` is no longer a saved-view tab or a per-view setting, on the published or the draft path. Before, the client matched on `data.object` or `object`, with or without `viewKind`. Such a row could only be stored before the write door refused unbound rows (#7741), and the server's own one-object read never served it. The remedy is in the changeset: open the view in the Console and save it again. The save writes `object` and `viewKind`. Census (amendment 6587053002 (3)), on fresh `objectstack dev --fresh` deployments at base: - app-crm: 87 objects, 10 view rows. Every object's `?object=` rows equal the rows today's adapter lists (crm_activity 3/3, crm_lead 4/4, crm_opportunity 3/3). No row is dropped. - showcase: 115 objects, 36 view rows across 6 objects. No row is dropped. - Two views saved through the Console's own path (`viewEnvelope` → `MetadataClient.save` as draft → `publishDraft`) are stored with `object` and `viewKind: 'list'`, and both are in the `?object=` answer. ## Tests - New `listViews.objectScopedRead-29550.test.ts` (14). It runs the real adapter and the real `@objectstack/client`; only `fetch` is a recording double, serving the server's rule from rows deliberately out of contract order. - Opening an object route makes one `GET /api/v1/meta/view?object=crm_lead` for both readers, and no unscoped `/meta/view`. Tabs come in contract order. - CONTROL: with the whole list loaded, nothing more is asked, and the answers equal the one-object read's. - With the whole list on the wire, both readers join it, with no `?object=` beside it and the same answers. - A second object asks its own `?object=`. - A server that ignores `?object=` still yields one object's rows. - Auth and locale headers are sent. - A 403 keeps each reader's failure contract. - The draft preview makes one `?preview=draft` read, no `?object=`, and applies the same rule (a legacy row is excluded). - A view write (`invalidateViewKeys`), a console-client view write (`invalidateCache('list:view')`) and a switch (`clearCache`) each detach the one-object read in flight, and the read after the drop asks again (3 cases). CONTROL: with nothing dropped, a read in flight is joined. - The one-object answer serves the next read, and a view write or a switch drops it (2 cases). - New `objectViewRoute.test-support.ts`: the server half of `?object=` for the suites that stand a store in for the server. It restates the server's rule rather than importing the adapter's, so a drift between them goes red. - Existing doubles answer `?object=` from the same rows their store holds, and stub clients gained `getLocale` (in `listViews.test.ts`, `listViewOverrides.test.ts`, `listViews.roundTripKeys-11013`, `viewItemObjectName.declaredSpelling-11013`, `viewOverlayMarker`, `viewOverlayMarkerOnly-10210`, `viewOverlayPatchOnly`, and `viewCacheInvalidation.pin`). Fixtures whose subject is not `viewKind` gained `viewKind: 'list'`. App-shell consumer pins (amendment 6591325082). These suites stood a fake store in for the whole `/meta/view` list, so after this change their reads went to an unanswered `?object=`. Every fake server or store now answers `GET /api/v1/meta/view?object=` by the server's rule (new test support `ui/packages/app-shell/src/views/__tests__/objectViewRoute.ts`, which restates the rule rather than importing the adapter's). Each card's invariant is kept. Nothing is deleted, skipped or loosened. | Test | Old assertion | New assertion | |---|---|---| | `MetadataProvider.oneMetadataRead-13044` "a view write drops the stored list: the next list read asks again" (both writes) | after the write, `listViews('account')` + `listViewOverrides('contact')`: `/meta/view` asked 2 times | after the write, `listViews('account')` + `listViewOverrides('account')`: `?object=account` asked once (the read after the write asked; the one after it reads what it stored), `/meta/view` still 1 | | `…oneMetadataRead-13044` "a view write detaches the list request in flight" and "a view saved straight through the client detaches…" | the read after the write makes `/meta/view` 2 | the read after the write asks `?object=account` (1); it does not join the whole-list request on the wire (`/meta/view` stays 1) | | `…oneMetadataRead-13044` "a draft-preview list read never fills the stored list" | the published read after it: `/meta/view` 1 | the published read after it: `?object=account` 1, `/meta/view` 0, and `list:view` still not stored | | `MetadataProvider.switchDropsAdapter-13044` "an organization switch detaches a view-list request in flight" | the read after the switch makes `/meta/view` 2 | the read after the switch asks `?object=account` (1); `/meta/view` stays 1 | | `…switchDropsAdapter-13044` "an organization or session switch drops the stored view list" (both switches) | `/meta/view` 2 after the switch | `?object=account` 1 after the switch, `/meta/view` 1, and a second read asks nothing more | | `…switchDropsAdapter-13044` new: "an organization or session switch drops a stored one-object view answer" (both switches) | (new) | a stored `?object=account` answer, then the switch: the next read asks again (`?object=account` 1 → 2) | | `viewListDrop-13057` (all 9 write cases and the controls) | reads counted on `/api/v1/meta/view` exactly | reads counted on `/api/v1/meta/view` with any query (`?object=` included); every number unchanged | | `viewCacheInvalidation.guard` (Publish, create, report-publish control) | `getItems` called 1 / 2 times | reads of the published views (`?object=account` requests plus `getItems` calls) 1 / 2 times; same numbers | | `ObjectView.viewConfigSaveEnvelope-10210` "a re-read still classifies the view as a saved view" | the publish lands through a bare `meta.saveItem` stub | the publish lands through the console's `publishRuntimeMetadata` seam (as `objectViewViewCrud` saves), which drops the object's view keys; assertions unchanged | | `ObjectView.overlayPatchOnly`, `ObjectView.overrideMasquerade` (marked row) | overlay fixtures without `viewKind` | the fixtures carry `viewKind: 'list'`, as the server stores an overlay (inherited at save from the registry entry it shadows, `normalizeViewMetadata`, objectstack#2555). These tests are about the overlay's body and its marker, not about legacy rows. Assertions unchanged. | | `ObjectView.fallbackTabSessionOnly-11643`, `ObjectView.inlineEditSessionOnly-5144`, `InterfaceListPage.hollowOverlayHydration` | (harness only) | the fake store answers `?object=`; assertions unchanged | | `data-objectstack/viewCacheInvalidation.pin` 13057 and `listViewOverrides` key pins | cache keys read: `[]`, and `['view-overrides:account']` | `['list:view@0?object=account', 'list:view@0?object=account']`, and `['view-overrides:account', 'list:view@0?object=account']`: the one-object key, which every invalidation of `list:view` retires | Pin rewrites, authorized by amendment 6587483534: | Test | Old assertion | New assertion | |---|---|---| | `listViews.test.ts` "keeps legacy bare specs without a viewKind" → "a legacy row without a viewKind is not a tab, published or in the draft preview" | `['saved_grid', 'wrapped_grid']` | `[]` on both paths | | `listViews.test.ts` "does NOT exclude a flat legacy saved view with no viewKind at all" → "…is not listed by either read (objectstack#29550)" | `['crm_lead.my_view']` | `[]` on both paths | | `listViews.test.ts` "non-preview mode uses the published getItems path" → "non-preview mode reads the published one-object route" | `getItems` called once, 0 `/meta/view` fetches | `getItems` not called, fetches exactly `['http://test.local/api/v1/meta/view?object=crm_activity']` | | `listViews.test.ts` "a marked row is excluded even without the legacy viewKind signal" → "a marked row is excluded by the marker alone" | marked row (no `viewKind`) excluded | marked row (with `viewKind`) excluded, and an unmarked control row is listed | | `viewCacheInvalidation.pin.test.ts` 13057 case | `getItems` called 2 times with `'view'` | two `?object=account` fetches, `getItems` not called, and a held list answers with no third request | ## Acceptance notes - **A whole-list read already on the wire is joined.** Before #29609, on a packaged app's object route the unscoped `/meta/view` was the app object scope's read for lookup targets outside the bundle (#29551). At base, `listViews` joined it through the shared `list:view` entry. A first cut that always asked `?object=` put one request more beside it (+3,677 B on crm_lead, +5,249 B on showcase_project). Joining the read already on the wire fixed that, and an ablation of the join goes red. #29609 landed first. This branch merged main at `dfc9107d` and re-measured crm_app: `?object=` is all these routes ask (see Verification). - **Order.** The adapter's answer follows the contract order (`order`, then `name`). The Console's visible view switcher sorts on its own (`ObjectView`'s `viewList.sort`: the user's order, then `sortOrder`, then declared order), and on the three measured routes it is unchanged (see Verification). - **The URL** uses the fixed `/api/v1/meta` prefix, as `MetadataClient` does. - **A write or a switch while the one-object read is in flight** detaches it, as it detaches the whole-list read (amendment 6591325082). A reader that joined it before the write gets the pre-write rows, the same window the whole-list share has. - The adapter's `createView` does not stamp `viewKind`. No production caller uses it: the Console saves through `viewEnvelope`, which writes both fields. - `appObjectScope.ts`, `AppContent.tsx` and `ObjectView.tsx` are not touched. The app bundle is not used as a source: a new saved view does not mark it stale, and it does not cover objects outside the app. ## Verification Production Console (`pnpm console:build`), served by `objectstack dev --fresh` (app-crm on one server, showcase on another). Playwright signs in, opens each route, then reloads with the cache disabled and logs every `/api/` request with its CDP initiator stack (`Debugger.setAsyncCallStackDepth 64`), as #29416 measured. The view list on app-crm is 7,452 B here (#29416 measured 7,014 B) because two views were saved on `crm_lead` through the Console's path for the order check. Raw results and the scripts are in the project folder `issue-29550/measure/`. **1. A console-created (package-less) app's object route: the card's case.** Runtime app `ops_app`, saved through `PUT /api/v1/meta/app/ops_app` with entries for `crm_account` and `crm_lead`. Before is the base adapter (`dbca3ef0`), after is this head. | Route | Before | After | |---|---|---| | `/apps/ops_app/crm_account` | 33 requests, 368,178 B. `GET /api/v1/meta/view` 7,452 B, initiator `listViews` → `readViewList` → `getItems` | 33 requests, 361,121 B. `GET /api/v1/meta/view?object=crm_account` 395 B, initiator `listViews` → `readObjectViewRows` → `requestObjectViewRows`. No unscoped `/meta/view`. | | `/apps/ops_app/crm_lead` | 33 requests, 368,977 B. `/meta/view` 7,452 B, same initiator | 33 requests, 365,202 B. `?object=crm_lead` 3,677 B. No unscoped `/meta/view`. | **2. A packaged app's object route, with #29551's fix (#29609, now on main).** Same server data in both columns. Before is #29609's head `fadf5b2f` alone. After is this branch with #29609 merged. | Route | #29609 alone | #29609 + this PR | |---|---|---| | `crm_app/crm_lead` | `/meta/view` 7,452 B, initiator `listViews` → `readViewList` (the only reader left) | `?object=crm_lead` 3,677 B. No unscoped `/meta/view`. | | `crm_app/crm_account` | `/meta/view` 7,452 B, same | `?object=crm_account` 395 B | | `showcase_app/showcase_project` | `/meta/view` 24,867 B, same | `?object=showcase_project` 5,249 B | **3. Re-measured at the final head `dfc9107d`** (main merged, #29609 included), on fresh servers (no extra saved views). Every route asks one `?object=` read from `listViews` → `readObjectViewRows` → `requestObjectViewRows`, and none asks an unscoped `/meta/view`: - `crm_app/crm_lead`: 28 requests, `?object=crm_lead` 3,239 B. - `crm_app/crm_account`: 28 requests, `?object=crm_account` 395 B. - `ops_app/crm_account`: 33 requests, 395 B. - `ops_app/crm_lead`: 33 requests, 3,239 B. - `showcase_project`: 29 requests, `?object=showcase_project` 4,763 B. Before #29609 landed, on a packaged route the unscoped read was the app object scope's, and the readers joined it. Request counts were then equal to base (28, 28 and 29), with no `?object=` beside it. **Tab order (amendment 6587053002 (2)).** Two views were saved through the Console's path, "Zeta board" first and then "Alpha grid". | Object | `listViews` before (the whole list's order) | `listViews` after (contract order; the same from the stored list) | |---|---|---| | app-crm `crm_lead` | all, pipeline, zeta_board, alpha_grid | all, alpha_grid, zeta_board, pipeline | | showcase `showcase_project` | by_status, budget_chart, default, zeta_board, alpha_grid | alpha_grid, by_status, zeta_board, budget_chart, default | The Console's visible view switcher sorts on its own and is unchanged before and after, read from the open switcher: - `crm_app/crm_lead`: All Leads, Lead Pipeline (Kanban), Zeta board, Alpha grid. - `showcase_project`: All Projects, By Status, Budget by Account, Zeta board, Alpha grid. The order is the same at `e2b1fef3`, with #29609 merged, and on `ops_app/crm_lead`. <details><summary>Ablations (each through <code>scripts/ablation-replace.mjs</code>, restored with <code>git diff HEAD</code> empty)</summary> At `e2b1fef3`: - `listViews` reads `client.meta.getItems('view')` again: 5 of 8 red in the new file. - `listViewOverrides` reads `client.meta.getItems('view')` again: 4 of 8 red. - The in-flight join removed (`if (listing && false)`): the join case red (1 of 8). At `1ed9b5c3` (amendment 6591325082): - The one-object key no longer names the last drop (`list:view@0?object=`): 6 red. That is `viewCacheInvalidation.guard` (Publish click, create), the new file (two detach cases, the stored-answer drop) and `ObjectView.viewConfigSaveEnvelope-10210` (re-read after the publish). - An earlier cut that detached in-flight reads only, joining whatever was on the wire: the three detach cases red. </details> <details><summary>Local runs</summary> At the final head `c9e08a02` (main merged): - Derived gates (`dispatch-gates --commands`): 36 commands, all exit 0, reconciled with `--ran` (36 derived, 36 run, 0 NOT-MEASURED). `check-sdui-manifest` is among them. - Every app-shell test file that names `listViews`, `listViewOverrides` or `/meta/view`: 140 files, 1,154 tests, all passed (under `os-verify-lock`, `--maxWorkers=2`). - `@object-ui/data-objectstack` full suite: 113 files, 1,291 tests, all passed. `type-check` exit 0. - `@object-ui/app-shell` `type-check` (sources and `tsconfig.test.json`): exit 0, at `1ed9b5c3`. - Full dogfood battery (narrowing arm), closure built, then `pnpm --filter @objectstack/dogfood test` under `os-verify-lock`: Tests 3,308 passed and 17 skipped (3,325); Test Files 400 passed, 1 skipped, 1 failed (402), VERDICT command-exit 1. The failed file is `print-service-render.dogfood.test.ts`, at its `afterAll` cleanup, not at a test. `rmSync` of the Chromium profile dir raised `ENOTEMPTY` (`/tmp/os-print-render-remote-*/Default`) after all 8 tests passed. Re-run alone under the lock, the file passes (8/8, VERDICT command-exit 0). It reads no adapter or app-shell code. At `e2b1fef3` (main merged at `a81b625f`): - `eslint --no-inline-config` on the changed files: no error on a changed line. Four pre-existing `no-console` hits at `index.ts:2041-2061` are inline-disabled on main. - Full dogfood battery: VERDICT command-exit 0, Test Files 400 passed and 1 skipped (401), Tests 3,291 passed and 17 skipped (3,308). </details> ## Human Minimum - [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic. (not touched) - [x] 2. Every name I added uses the casing for its kind. - [x] 3. No formatter ran; `pnpm lint` passes. - [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_01QsR2jStGcAjjnTU8DfEJ3o --- _Generated by [Claude Code](https://claude.ai/code/session_01QsR2jStGcAjjnTU8DfEJ3o)_ --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent ece5faa commit 1c1a5d4

24 files changed

Lines changed: 888 additions & 150 deletions
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
'@object-ui/data-objectstack': patch
3+
---
4+
5+
perf(data-objectstack)!: an object route reads that object's saved views (`GET /meta/view?object=`), not every view of every object (#29550)
6+
7+
Clause-②: no (narrowing) — `listViews` and `listViewOverrides` no longer list a stored `view` row that carries no `viewKind` or no top-level `object` (a legacy bare spec, a `{ list }` wrapper, a row bound only through `data.object`). The draft-preview read applies the same rule. Nothing is widened.
8+
Metadata-protocol: none
9+
10+
<!-- adr-0087: not-required (no-migration-prescription) No key of any schema is added, removed, renamed or re-shaped, and no export, signature or answer shape changes. The adapter's two view readers now apply the rule the server's one-object view read (ADR-0017 section 3.5) and the view write door (#7741) already apply: a row is bound to an object by `object` plus `viewKind`. There is no key for a migration to rewrite; a row stored before the write door refused unbound rows is re-bound by saving the view again. -->
11+
12+
**BREAKING** read narrowing in `@object-ui/data-objectstack` (`ObjectStackAdapter.listViews`, `ObjectStackAdapter.listViewOverrides`), which feed the Console's saved-view tabs and per-view settings.
13+
14+
- **Before.** On every object route, both readers downloaded the whole published view list (`GET /api/v1/meta/view`, every view of every object; 7 KB on app-crm) and kept one object's rows in the browser, matching a row on `data.object` or `object`, with or without `viewKind`.
15+
- **Now.** While nothing on the page has loaded the whole list, they read `GET /api/v1/meta/view?object=OBJECT`, the read ADR-0017 declares for the view switcher, once for both readers. Once something has loaded the whole list, or while its read is on the wire (Studio, the MetadataProvider, a packaged app's object scope), they answer from it with no request of their own. Both paths keep the same rows in the same order: `viewKind` set, `object` naming the object, sorted by `order` and then `name`. The draft-preview read (`listViews` with `previewDrafts`) keeps its own `?preview=draft` request and narrows its rows by the same rule.
16+
- **Order.** Saved-view tabs follow the contract's order (`order`, then `name`). Before, they followed the order of the server's whole list, so tabs with no `order` could appear in a different order.
17+
- **Who sees it.** A deployment holding a `view` row stored before the write door refused rows without `object` and `viewKind` (#7741). That row was a saved-view tab and a per-view setting before, and is neither now. The server's one-object read never served it. Views the Console saves today carry both fields, and none of the rows on a fresh app-crm or showcase deployment were affected.
18+
19+
**The remedy.** Open the view in the Console and save it again: the save writes `object` and `viewKind`, and the view is listed again.

‎ui/packages/app-shell/src/providers/__tests__/MetadataProvider.oneMetadataRead-13044.test.tsx‎

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import { readObjectSortability } from '@object-ui/core';
3939
import { useMetadata } from '@object-ui/react';
4040
import { MetadataProvider } from '../MetadataProvider';
4141
import { PreviewModeProvider } from '../../preview/PreviewModeContext';
42+
import { serveObjectViews } from '../../views/__tests__/objectViewRoute';
4243

4344
type Ctx = ReturnType<typeof useMetadata>;
4445

@@ -86,6 +87,12 @@ function makeServer(): { server: Server; adapter: ObjectStackAdapter } {
8687
if (path.endsWith('/api/v1/discovery')) return json(200, { success: true, data: {} });
8788
if (path === '/api/v1/meta/view') return json(200, { success: true, data: { type: 'view', items: structuredClone(VIEWS) } });
8889
if (path === '/api/v1/meta/view?preview=draft') return json(200, { success: true, data: { type: 'view', items: [] } });
90+
// objectstack#29550: one object's views, by the server's rule.
91+
const oneObject = /^\/api\/v1\/meta\/view\?object=([^&]+)$/.exec(path);
92+
if (oneObject) {
93+
const items = serveObjectViews(structuredClone(VIEWS), decodeURIComponent(oneObject[1]));
94+
return json(200, { success: true, data: { type: 'view', items } });
95+
}
8996
if (path.startsWith('/api/v1/meta/view/')) return json(200, { success: true });
9097
const byName = /^\/api\/v1\/meta\/object\/([^/?]+)$/.exec(path);
9198
if (byName) {
@@ -145,6 +152,8 @@ function mount(adapter: ObjectStackAdapter, opts: { preview?: boolean } = {}) {
145152
const count = (calls: string[], path: string) => calls.filter((c) => c === path).length;
146153
const OBJECT_URL = '/api/v1/meta/object/sys_member';
147154
const VIEW_URL = '/api/v1/meta/view';
155+
/** objectstack#29550: one object's views, the read `listViews` asks while no whole list is held. */
156+
const ACCOUNT_VIEWS_URL = '/api/v1/meta/view?object=account';
148157

149158
afterEach(() => {
150159
cleanup();
@@ -330,10 +339,14 @@ describe('controls (objectui#13044)', () => {
330339
expect(count(server.calls, VIEW_URL)).toBe(1);
331340
await write(adapter);
332341
await adapter.listViews('account');
333-
// An object whose override map was never read: derived from the stored list.
334-
await adapter.listViewOverrides('contact');
335-
// The read after the write asked; the one after it reads what it stored.
336-
expect(count(server.calls, VIEW_URL)).toBe(2);
342+
// An override map never read: derived from what the read after the
343+
// write stored.
344+
await adapter.listViewOverrides('account');
345+
// The read after the write asked (objectstack#29550: one object's
346+
// views, as no whole list is held); the one after it reads what it
347+
// stored.
348+
expect(count(server.calls, ACCOUNT_VIEWS_URL)).toBe(1);
349+
expect(count(server.calls, VIEW_URL)).toBe(1);
337350
cleanup();
338351
}
339352
});
@@ -351,7 +364,11 @@ describe('controls (objectui#13044)', () => {
351364
await new Promise((resolve) => setTimeout(resolve, 0));
352365
adapter.invalidateViewKeys('account', 'account.mine');
353366
const after = adapter.listViews('account');
354-
await waitFor(() => expect(count(server.calls, VIEW_URL)).toBe(2));
367+
// objectstack#29550: the read after the write asks again, for one
368+
// object's views; it joins neither the whole-list request on the wire nor
369+
// anything stored before the write.
370+
await waitFor(() => expect(count(server.calls, ACCOUNT_VIEWS_URL)).toBe(1));
371+
expect(count(server.calls, VIEW_URL)).toBe(1);
355372
server.release();
356373
await Promise.all([before, after]);
357374
await waitFor(() => expect(ctx().getTypeStatus!('view')).toBe('ready'));
@@ -370,7 +387,11 @@ describe('controls (objectui#13044)', () => {
370387
// The shape a page uses when it writes a view without the adapter's seam.
371388
await adapter.getClient().meta.saveItem('view', 'account.mine', { name: 'account.mine', object: 'account' });
372389
const after = adapter.listViews('account');
373-
await waitFor(() => expect(count(server.calls, VIEW_URL)).toBe(2));
390+
// objectstack#29550: the read after the write asks again, for one
391+
// object's views; it joins neither the whole-list request on the wire nor
392+
// anything stored before the write.
393+
await waitFor(() => expect(count(server.calls, ACCOUNT_VIEWS_URL)).toBe(1));
394+
expect(count(server.calls, VIEW_URL)).toBe(1);
374395
server.release();
375396
await Promise.all([before, after]);
376397
await waitFor(() => expect(ctx().getTypeStatus!('view')).toBe('ready'));
@@ -386,7 +407,11 @@ describe('controls (objectui#13044)', () => {
386407
expect(adapter.getCached('list:view')).toBeUndefined();
387408
const published = await adapter.listViews('account');
388409
expect(published.map((v: any) => v.name).sort()).toEqual(['account.all', 'account.mine']);
389-
expect(count(server.calls, VIEW_URL)).toBe(1);
410+
// objectstack#29550: the published read asks the server (one object's
411+
// views), and still stores no whole list.
412+
expect(count(server.calls, ACCOUNT_VIEWS_URL)).toBe(1);
413+
expect(count(server.calls, VIEW_URL)).toBe(0);
414+
expect(adapter.getCached('list:view')).toBeUndefined();
390415
});
391416

392417
it('the preview path still reads through the preview client, never the adapter', async () => {

‎ui/packages/app-shell/src/providers/__tests__/MetadataProvider.switchDropsAdapter-13044.test.tsx‎

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ import { MetadataProvider } from '../MetadataProvider';
3737
type Ctx = ReturnType<typeof useMetadata>;
3838
const OBJECT_URL = '/api/v1/meta/object/sys_member';
3939
const VIEW_URL = '/api/v1/meta/view';
40+
/** objectstack#29550: one object's views, the read `listViews` asks while no whole list is held. */
41+
const ACCOUNT_VIEWS_URL = '/api/v1/meta/view?object=account';
4042

4143
const json = (body: unknown) =>
4244
new Response(JSON.stringify(body), { status: 200, headers: { 'content-type': 'application/json' } });
@@ -53,6 +55,8 @@ function makeServer() {
5355
return json({ success: true, data: { type: 'object', name: 'sys_member', item: { name: 'sys_member', fields: {} } } });
5456
}
5557
if (path === VIEW_URL) return json({ success: true, data: { type: 'view', items: [] } });
58+
// objectstack#29550: one object's views (none here, as in the whole list).
59+
if (path.startsWith(`${VIEW_URL}?object=`)) return json({ success: true, data: { type: 'view', items: [] } });
5660
return json({ success: true, data: { type: 'x', items: [] } });
5761
};
5862
const adapter = new ObjectStackAdapter({
@@ -126,11 +130,47 @@ describe('a switch drops the adapter metadata the provider read through it (obje
126130
await new Promise((resolve) => setTimeout(resolve, 0));
127131
});
128132
const views = adapter.listViews('account');
129-
await waitFor(() => expect(count(calls, VIEW_URL)).toBe(2));
133+
// objectstack#29550: the read after the switch asks again (one object's
134+
// views); it does not join the other organization's request on the wire.
135+
await waitFor(() => expect(count(calls, ACCOUNT_VIEWS_URL)).toBe(1));
136+
expect(count(calls, VIEW_URL)).toBe(1);
130137
release();
131138
await views;
132139
});
133140

141+
it('an organization or session switch drops a stored one-object view answer: the next read asks again (objectstack#29550)', async () => {
142+
for (const change of [
143+
() => {
144+
authState.activeOrganization = { id: 'org_b' };
145+
},
146+
() => {
147+
authState.user = { id: 'user_b' };
148+
},
149+
]) {
150+
const { adapter, calls } = makeServer();
151+
authState.activeOrganization = { id: 'org_a' };
152+
authState.user = { id: 'user_a' };
153+
const m = mount(adapter);
154+
// No whole list is read: the object route's read is one object's views,
155+
// and its answer serves the next read within the open.
156+
await adapter.listViews('account');
157+
await adapter.listViewOverrides('account');
158+
expect(count(calls, ACCOUNT_VIEWS_URL)).toBe(1);
159+
160+
change();
161+
m.rerender();
162+
await act(async () => {
163+
await new Promise((resolve) => setTimeout(resolve, 0));
164+
});
165+
await adapter.listViews('account');
166+
expect(count(calls, ACCOUNT_VIEWS_URL)).toBe(2);
167+
expect(count(calls, VIEW_URL)).toBe(0);
168+
cleanup();
169+
authState.activeOrganization = null;
170+
authState.user = null;
171+
}
172+
});
173+
134174
it('an organization or session switch drops the stored view list: the next list read asks again (objectui#13057)', async () => {
135175
for (const change of [
136176
() => {
@@ -160,7 +200,12 @@ describe('a switch drops the adapter metadata the provider read through it (obje
160200
await new Promise((resolve) => setTimeout(resolve, 0));
161201
});
162202
await adapter.listViews('account');
163-
expect(count(calls, VIEW_URL)).toBe(2);
203+
// objectstack#29550: it asks again, for one object's views; nothing
204+
// stored in the other organization or session answers it.
205+
expect(count(calls, ACCOUNT_VIEWS_URL)).toBe(1);
206+
expect(count(calls, VIEW_URL)).toBe(1);
207+
await adapter.listViews('account');
208+
expect(count(calls, ACCOUNT_VIEWS_URL)).toBe(1);
164209
cleanup();
165210
authState.activeOrganization = null;
166211
authState.user = null;

‎ui/packages/app-shell/src/views/InterfaceListPage.hollowOverlayHydration.test.tsx‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ vi.mock('@object-ui/react', async (importOriginal) => {
9191

9292
import { ObjectStackAdapter } from '@object-ui/data-objectstack';
9393
import { InterfaceListPage } from './InterfaceListPage';
94+
import { answerObjectViewRead } from './__tests__/objectViewRoute';
9495

9596
const OBJECT_NAME = 'crm_lead';
9697
const VIEW_ID = `${OBJECT_NAME}.default`;
@@ -133,15 +134,18 @@ function plantOverlay(rows: Map<string, any>, body: Record<string, unknown>) {
133134
function makeAdapter(meta: any) {
134135
const ds: any = new ObjectStackAdapter({
135136
baseUrl: 'http://test.local',
136-
fetch: vi.fn(async () =>
137-
new Response(JSON.stringify({ success: true, data: { capabilities: {}, routes: {} } }), {
137+
// objectstack#29550: the adapter reads one object's views on
138+
// `GET /meta/view?object=`, answered here from the same store.
139+
fetch: vi.fn(async (input: RequestInfo | URL) =>
140+
(await answerObjectViewRead(input, () => meta.getItems('view')))
141+
?? new Response(JSON.stringify({ success: true, data: { capabilities: {}, routes: {} } }), {
138142
status: 200,
139143
headers: { 'Content-Type': 'application/json' },
140144
})),
141145
});
142146
ds.connected = true;
143147
ds.connectionState = 'connected';
144-
ds.client = { meta };
148+
ds.client = { meta, getLocale: () => undefined };
145149
return ds;
146150
}
147151

‎ui/packages/app-shell/src/views/ObjectView.fallbackTabSessionOnly-11643.test.tsx‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ vi.mock('@object-ui/plugin-list', async (importOriginal) => ({
130130
import { toast } from 'sonner';
131131
import { ObjectView } from './ObjectView';
132132
import { ExpressionProvider } from '../providers/ExpressionProvider';
133+
import { answerObjectViewRead } from './__tests__/objectViewRoute';
133134

134135
const OBJECT_NAME = 'track_note';
135136
const SAVED_ID = `${OBJECT_NAME}.mine`;
@@ -231,15 +232,18 @@ function makeStore(seed: Record<string, any>[]) {
231232
function pageDataSource(meta: any) {
232233
const ds: any = new ObjectStackAdapter({
233234
baseUrl: 'http://test.local',
234-
fetch: vi.fn(async () =>
235-
new Response(JSON.stringify({ success: true, data: { capabilities: {}, routes: {} } }), {
235+
// objectstack#29550: the adapter reads one object's views on
236+
// `GET /meta/view?object=`, answered here from the same store.
237+
fetch: vi.fn(async (input: RequestInfo | URL) =>
238+
(await answerObjectViewRead(input, () => meta.getItems('view')))
239+
?? new Response(JSON.stringify({ success: true, data: { capabilities: {}, routes: {} } }), {
236240
status: 200,
237241
headers: { 'Content-Type': 'application/json' },
238242
})),
239243
});
240244
ds.connected = true;
241245
ds.connectionState = 'connected';
242-
ds.client = { meta };
246+
ds.client = { meta, getLocale: () => undefined };
243247
return {
244248
find: vi.fn(async () => ({ data: [], total: 0 })),
245249
findOne: vi.fn(async () => null),

‎ui/packages/app-shell/src/views/ObjectView.inlineEditSessionOnly-5144.test.tsx‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ vi.mock('@object-ui/plugin-list', async (importOriginal) => ({
104104
import { toast } from 'sonner';
105105
import { ObjectView } from './ObjectView';
106106
import { ExpressionProvider } from '../providers/ExpressionProvider';
107+
import { answerObjectViewRead } from './__tests__/objectViewRoute';
107108

108109
const OBJECT_NAME = 'track_note';
109110
const SAVED_ID = `${OBJECT_NAME}.mine`;
@@ -224,15 +225,18 @@ function makeStore(seed: Record<string, any>[]) {
224225
function pageDataSource(meta: any) {
225226
const ds: any = new ObjectStackAdapter({
226227
baseUrl: 'http://test.local',
227-
fetch: vi.fn(async () =>
228-
new Response(JSON.stringify({ success: true, data: { capabilities: {}, routes: {} } }), {
228+
// objectstack#29550: the adapter reads one object's views on
229+
// `GET /meta/view?object=`, answered here from the same store.
230+
fetch: vi.fn(async (input: RequestInfo | URL) =>
231+
(await answerObjectViewRead(input, () => meta.getItems('view')))
232+
?? new Response(JSON.stringify({ success: true, data: { capabilities: {}, routes: {} } }), {
229233
status: 200,
230234
headers: { 'Content-Type': 'application/json' },
231235
})),
232236
});
233237
ds.connected = true;
234238
ds.connectionState = 'connected';
235-
ds.client = { meta };
239+
ds.client = { meta, getLocale: () => undefined };
236240
return {
237241
find: vi.fn(async () => ({ data: [], total: 0 })),
238242
findOne: vi.fn(async () => null),

‎ui/packages/app-shell/src/views/ObjectView.overlayPatchOnly.test.ts‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ import type { DataSource } from '@object-ui/types';
5050
import * as dataObjectstack from '@object-ui/data-objectstack';
5151
import { ObjectStackAdapter } from '@object-ui/data-objectstack';
5252
import { buildViewTabs, loadViewOverrides, sanitizeViewOverride } from './ObjectView';
53+
import { answerObjectViewRead } from './__tests__/objectViewRoute';
5354
// @ts-expect-error — plain-JS shared helper, intentionally untyped (`allowJs: false`)
5455
import { stripComments as stripCommentsUntyped } from '../../../../scripts/js-comment-mask.mjs';
5556

@@ -105,25 +106,33 @@ function makeMetaStore() {
105106
function makeAdapter(meta: any) {
106107
const ds: any = new ObjectStackAdapter({
107108
baseUrl: 'http://test.local',
108-
fetch: vi.fn(async () =>
109-
new Response(JSON.stringify({ success: true, data: { capabilities: {}, routes: {} } }), {
109+
// objectstack#29550: the adapter reads one object's views on
110+
// `GET /meta/view?object=`, answered here from the same store.
111+
fetch: vi.fn(async (input: RequestInfo | URL) =>
112+
(await answerObjectViewRead(input, () => meta.getItems('view')))
113+
?? new Response(JSON.stringify({ success: true, data: { capabilities: {}, routes: {} } }), {
110114
status: 200,
111115
headers: { 'Content-Type': 'application/json' },
112116
})),
113117
});
114118
ds.connected = true;
115119
ds.connectionState = 'connected';
116-
ds.client = { meta };
120+
ds.client = { meta, getLocale: () => undefined };
117121
return ds;
118122
}
119123

120124
/**
121125
* Put a personalization overlay in the store the way the retired toolbar write
122126
* (`updateViewConfig`, objectui#12504) stored one: the body, with `object`,
123127
* `name` and the `_isOverride` marker stamped on it.
128+
*
129+
* objectstack#29550: and `viewKind`, as the row is stored. The server's save
130+
* inherits it from the registry entry the overlay shadows
131+
* (`normalizeViewMetadata`, objectstack#2555), and the one-object read serves
132+
* only rows that carry it.
124133
*/
125134
function plantOverlay(rows: Map<string, any>, body: Record<string, unknown>) {
126-
rows.set(`view::${VIEW_ID}`, { ...body, object: OBJECT_NAME, name: VIEW_ID, _isOverride: true });
135+
rows.set(`view::${VIEW_ID}`, { ...body, viewKind: 'list', object: OBJECT_NAME, name: VIEW_ID, _isOverride: true });
127136
}
128137

129138
const fallbackTab = () => ({ id: 'all', label: 'All records', type: 'grid', columns: [] });

‎ui/packages/app-shell/src/views/ObjectView.overrideMasquerade.test.ts‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import { describe, it, expect, vi } from 'vitest';
4343
import { ObjectStackAdapter } from '@object-ui/data-objectstack';
4444
import { buildViewTabs } from './ObjectView';
4545
import { viewRowId, isSavedViewId } from '../utils/viewIdentity';
46+
import { answerObjectViewRead } from './__tests__/objectViewRoute';
4647

4748
const OBJECT_NAME = 'crm_lead';
4849

@@ -66,15 +67,18 @@ function normalizeSavedViews(rows: any[]) {
6667
function makeAdapterWithItems(items: any[]) {
6768
const ds: any = new ObjectStackAdapter({
6869
baseUrl: 'http://test.local',
69-
fetch: vi.fn(async () =>
70-
new Response(JSON.stringify({ success: true, data: { capabilities: {}, routes: {} } }), {
70+
// objectstack#29550: the adapter reads one object's views on
71+
// `GET /meta/view?object=`, answered here from the same rows.
72+
fetch: vi.fn(async (input: RequestInfo | URL) =>
73+
(await answerObjectViewRead(input, () => items))
74+
?? new Response(JSON.stringify({ success: true, data: { capabilities: {}, routes: {} } }), {
7175
status: 200,
7276
headers: { 'Content-Type': 'application/json' },
7377
})),
7478
});
7579
ds.connected = true;
7680
ds.connectionState = 'connected';
77-
ds.client = { meta: { getItems: vi.fn(async () => ({ items })) } };
81+
ds.client = { meta: { getItems: vi.fn(async () => ({ items })) }, getLocale: () => undefined };
7882
return ds;
7983
}
8084

@@ -87,7 +91,10 @@ describe('a system view stays readonly even with a personalization row (objectui
8791
[
8892
'marked row (new writes, post-fix)',
8993
{
90-
name: 'crm_lead.default', object: 'crm_lead', type: 'grid',
94+
// objectstack#29550: `viewKind` as the server stores it, inherited
95+
// from the registry entry the row shadows (objectstack#2555), so the
96+
// marker alone is what excludes it.
97+
name: 'crm_lead.default', object: 'crm_lead', viewKind: 'list', type: 'grid',
9198
data: { provider: 'object', object: 'crm_lead' }, columns: ['name'],
9299
rowHeight: 40, _isOverride: true,
93100
},

0 commit comments

Comments
 (0)