diff --git a/.changeset/35306-lookup-target-single-read.md b/.changeset/35306-lookup-target-single-read.md
new file mode 100644
index 00000000000..b0229743fb1
--- /dev/null
+++ b/.changeset/35306-lookup-target-single-read.md
@@ -0,0 +1,13 @@
+---
+'@object-ui/app-shell': patch
+'@object-ui/console': patch
+---
+
+fix(console): an object the presence read served is not read again by name
+
+Clause-②: no
+Metadata-protocol: none
+
+A list page whose object has a lookup to an object outside the app's package (on the showcase, `sys_user`) asked for that object twice: first in the `GET /api/v1/meta/object?names=` presence read, which already answers with the object's definition, and then by name (`GET /api/v1/meta/object/sys_user`) about 0.7 s later. The by-name read now takes the definition from the presence read when that read served it, so the lookup target costs one request. The same holds for the objects an app's entries require (`requiresObject`) and a dashboard's widget objects, which were also asked by name after their presence read had served them.
+
+What does not change: a name the presence read left out is still asked by name, so an object that is refused (`OBJECT_PACKAGE_DISABLED`) is still told apart from one that does not exist. A name the presence read has not answered yet is still asked by name. The draft preview still reads every object by name. The definition a scope holds is the same document the by-name read returned. No metadata key, value or default changes.
diff --git a/ui/packages/app-shell/src/console/__tests__/AppContent.dashboardRouteReads-28784.test.tsx b/ui/packages/app-shell/src/console/__tests__/AppContent.dashboardRouteReads-28784.test.tsx
index 78e3f718547..6205f92bce1 100644
--- a/ui/packages/app-shell/src/console/__tests__/AppContent.dashboardRouteReads-28784.test.tsx
+++ b/ui/packages/app-shell/src/console/__tests__/AppContent.dashboardRouteReads-28784.test.tsx
@@ -281,8 +281,9 @@ describe('a dashboard route reads from the app bundle and asks its widgets\' obj
// An object this runtime does not register is never asked by name: that
// read answers 404 on every open (a cloud-only `requiresObject`).
expect(objectCalls()).not.toContain('object/cloud_only');
- // A served widget object is still read by name for the route's scope.
- expect(objectCalls()).toContain('object/crm_case');
+ // A served widget object joins the route's scope from that read
+ // (objectstack#35306): it is not asked again by name.
+ expect(objectCalls()).not.toContain('object/crm_case');
expect(objectCalls()).not.toContain('object');
expect(server.calls).not.toContain('dashboard');
});
diff --git a/ui/packages/app-shell/src/console/__tests__/AppContent.emptyPackageScope-13046.test.tsx b/ui/packages/app-shell/src/console/__tests__/AppContent.emptyPackageScope-13046.test.tsx
index 6619dad8c52..93b24bf5d42 100644
--- a/ui/packages/app-shell/src/console/__tests__/AppContent.emptyPackageScope-13046.test.tsx
+++ b/ui/packages/app-shell/src/console/__tests__/AppContent.emptyPackageScope-13046.test.tsx
@@ -240,16 +240,14 @@ describe('an object route in an app whose package holds none of its objects read
expect(objectCalls()[0]).toBe(`object?package=${CLOUD}`);
// objectstack#34244 — the requiresObject entry and the lookup targets are
- // asked by name once the `?names=` presence read has answered them served.
+ // asked in `?names=` presence reads, whose served answers are their
+ // definitions (objectstack#35306): no by-name read of any of them.
expect(sorted(objectCalls())).toEqual(
sorted([
`object?package=${CLOUD}`,
'object?names=sys_member',
'object?names=sys_organization,sys_user',
'object/sys_environment',
- 'object/sys_organization',
- 'object/sys_user',
- 'object/sys_member',
]),
);
// The sidebar's capability gate answers from the same scope.
@@ -284,9 +282,6 @@ describe('a record route reads the objects its declared record page binds (objec
'object?names=sys_organization,sys_user',
'object/sys_environment',
'object/sys_environment_member',
- 'object/sys_organization',
- 'object/sys_user',
- 'object/sys_member',
]),
);
});
@@ -320,8 +315,9 @@ describe('CONTROLs: the shapes this card does not change ask what they asked bef
await waitFor(() => expect(screen.getByTestId('object-view')).toHaveTextContent('sys_user'));
await settle();
- // objectstack#34244 — the target outside the package after one presence read.
- expect(objectCalls()).toEqual([`object?package=${CRM}`, 'object?names=sys_user', 'object/sys_user']);
+ // objectstack#34244 — the target outside the package in one presence read,
+ // whose served answer is its definition (objectstack#35306).
+ expect(objectCalls()).toEqual([`object?package=${CRM}`, 'object?names=sys_user']);
});
it('a record route with no declared record page reads the whole registry, and nothing by name', async () => {
diff --git a/ui/packages/app-shell/src/console/__tests__/AppContent.objectScope-12811.test.tsx b/ui/packages/app-shell/src/console/__tests__/AppContent.objectScope-12811.test.tsx
index b1390e1b663..1db9b948f1d 100644
--- a/ui/packages/app-shell/src/console/__tests__/AppContent.objectScope-12811.test.tsx
+++ b/ui/packages/app-shell/src/console/__tests__/AppContent.objectScope-12811.test.tsx
@@ -117,9 +117,11 @@ interface Server {
calls: string[];
apps: unknown[];
holdByName: boolean;
+ /** objectstack#35306 — hold the `?names=` presence reads too. */
+ holdNames: boolean;
release: () => void;
}
-const server: Server = { calls: [], apps: [], holdByName: false, release: () => {} };
+const server: Server = { calls: [], apps: [], holdByName: false, holdNames: false, release: () => {} };
function makeAdapter() {
const held: Array<() => void> = [];
@@ -143,7 +145,9 @@ function makeAdapter() {
if (options?.names) {
server.calls.push(`${type}?names=${options.names.join(',')}`);
const named: any[] = type === 'object' ? OBJECTS.filter((o: any) => options.names!.includes(o.name)) : [];
- return Promise.resolve({ type, items: structuredClone(named) });
+ const answer = { type, items: structuredClone(named) };
+ if (!server.holdNames) return Promise.resolve(answer);
+ return new Promise((resolve) => held.push(() => resolve(answer)));
}
server.calls.push(options?.packageId ? `${type}?package=${options.packageId}` : type);
const all = type === 'object' ? OBJECTS : type === 'app' ? server.apps : [];
@@ -217,6 +221,7 @@ const splashUp = () => document.querySelector('[data-boot-splash]') !== null;
beforeEach(() => {
server.calls = [];
server.holdByName = false;
+ server.holdNames = false;
server.apps = [{ name: 'crm', label: 'CRM', _packageId: CRM, navigation: NAVIGATION }];
localStorage.clear();
sessionStorage.clear();
@@ -240,9 +245,10 @@ describe('one console open asks for the app\'s objects, not the whole registry (
// The route's lookup target outside the package, and the object the app's
// `requiresObject` entry names, each in a `?names=` presence read
// (objectstack#34244): the unregistered `cloud_only` is never asked by
- // name, and the gate still hides its entry; the served `sys_user` is.
+ // name, and the gate still hides its entry; the served `sys_user` is
+ // answered by its presence read and not asked again (objectstack#35306).
expect([...objectCalls()].sort()).toEqual(
- [`object?package=${CRM}`, 'object?names=cloud_only', 'object?names=sys_user', 'object/sys_user'].sort(),
+ [`object?package=${CRM}`, 'object?names=cloud_only', 'object?names=sys_user'].sort(),
);
// The route element and the chrome are handed the scope.
expect(screen.getByTestId('object-view')).toHaveTextContent('crm_account,crm_contact,sys_user');
@@ -259,7 +265,9 @@ describe('one console open asks for the app\'s objects, not the whole registry (
// target's, and (objectstack#34244) the `requiresObject` entry's.
expect([...objectCalls().filter((c) => c.startsWith('object?'))].sort()).toEqual(['object?names=cloud_only', 'object?names=sys_user']);
expect(objectCalls()).not.toContain('object/cloud_only');
- expect(objectCalls()).toEqual(expect.arrayContaining(['object/crm_account', 'object/sys_user']));
+ // objectstack#35306 — the lookup target's presence read served it: no by-name read of it.
+ expect(objectCalls()).toContain('object/crm_account');
+ expect(objectCalls()).not.toContain('object/sys_user');
expect(screen.getByTestId('object-view')).toHaveTextContent('crm_account');
});
@@ -299,20 +307,21 @@ describe('an object outside the package is read by name, behind the skeleton (ob
});
it('does not hold the route for its lookup targets: they are asked beside it, and the list renders meanwhile', async () => {
- server.holdByName = true;
+ server.holdNames = true;
boot('/apps/crm/crm_account');
await waitFor(() => expect(screen.getByTestId('object-view')).toHaveTextContent('crm_account,crm_contact'));
- // The lookup target's by-name read goes out once its `?names=` presence
- // read has answered it served (objectstack#34188), a render after the
- // package list let the route draw: wait for that read, never assume it
- // went out in the same render as the list's first paint. It is held, so
- // the list drawn without it is still the route not waiting for it.
- await waitFor(() => expect(server.calls).toContain('object/sys_user'));
+ // The lookup target is asked in a `?names=` presence read (objectstack#34188),
+ // whose served answer is its definition (objectstack#35306): wait for that
+ // read, never assume it went out in the same render as the list's first
+ // paint. It is held, so the list drawn without it is still the route not
+ // waiting for it.
+ await waitFor(() => expect(server.calls).toContain('object?names=sys_user'));
expect(screen.getByTestId('object-view')).toHaveTextContent('crm_account,crm_contact');
expect(screen.getByTestId('object-view')).not.toHaveTextContent('sys_user');
act(() => server.release());
await waitFor(() => expect(screen.getByTestId('object-view')).toHaveTextContent('sys_user'));
+ expect(server.calls).not.toContain('object/sys_user');
});
it('after the first paint, shows the route skeleton inside the chrome, never an empty route, until it lands', async () => {
diff --git a/ui/packages/app-shell/src/console/__tests__/AppContent.packagelessReads-29416.test.tsx b/ui/packages/app-shell/src/console/__tests__/AppContent.packagelessReads-29416.test.tsx
index 1bdd876516d..a3b2c99705c 100644
--- a/ui/packages/app-shell/src/console/__tests__/AppContent.packagelessReads-29416.test.tsx
+++ b/ui/packages/app-shell/src/console/__tests__/AppContent.packagelessReads-29416.test.tsx
@@ -276,7 +276,9 @@ describe('a package-less app reads what its routes name, by name (objectstack#29
expect(screen.getByTestId('object-view')).toHaveTextContent('note');
expect(screen.getByTestId('object-view').getAttribute('data-views')).toContain('note.all');
- expect(byNameCalls()).toEqual(expect.arrayContaining(['object/note', 'object/sys_user']));
+ expect(byNameCalls()).toContain('object/note');
+ // objectstack#35306 — the lookup target's presence read served it: no by-name read of it.
+ expect(byNameCalls()).not.toContain('object/sys_user');
// objectstack#34244 — the entries' required objects are asked in the presence read, never by name.
expect(byNameCalls()).not.toContain('object/gone_obj');
expect(byNameCalls()).not.toContain('object/crm_account');
@@ -357,12 +359,14 @@ describe('objectstack#34244 — a requiresObject the host does not register is n
expect(byNameCalls()).not.toContain('object/gone_obj');
});
- it('(e) CONTROL: in a packaged app a registered requiresObject outside the package is shown, and asked by name', async () => {
+ it('(e) CONTROL: in a packaged app a registered requiresObject outside the package is shown, and joins the scope from the presence read', async () => {
boot('/apps/app.crm/crm_account');
await waitFor(() => expect(screen.getByTestId('object-view')).toHaveTextContent('sys_user'));
await waitFor(() => expect(screen.getByTestId('gone-entry')).toHaveTextContent('false'));
expect(screen.getByTestId('user-entry')).toHaveTextContent('true');
- expect(byNameCalls()).toContain('object/sys_user');
+ // objectstack#35306 — the presence read served it, so it is not asked again by name.
+ expect(server.calls.filter((c) => c.startsWith('object?names=') && c.includes('sys_user')).length).toBeGreaterThan(0);
+ expect(byNameCalls()).not.toContain('object/sys_user');
});
});
diff --git a/ui/packages/app-shell/src/console/__tests__/AppContent.packagelessRecordRelated-29552.test.tsx b/ui/packages/app-shell/src/console/__tests__/AppContent.packagelessRecordRelated-29552.test.tsx
index 27211acae0a..dc8f5c97291 100644
--- a/ui/packages/app-shell/src/console/__tests__/AppContent.packagelessRecordRelated-29552.test.tsx
+++ b/ui/packages/app-shell/src/console/__tests__/AppContent.packagelessRecordRelated-29552.test.tsx
@@ -327,8 +327,9 @@ describe('a package-less app’s record route with no declared record page reads
await settle();
expect(objectCalls()).not.toContain('object');
- // Every bundled object is answered from the bundle; the lookup target outside it is asked by name.
- expect(objectCalls()).toEqual(['object?names=sys_user', 'object/sys_user']);
+ // Every bundled object is answered from the bundle; the lookup target outside it by the
+ // presence read that served it (objectstack#35306), with no by-name read.
+ expect(objectCalls()).toEqual(['object?names=sys_user']);
expect(sorted((screen.getByTestId('record-view').textContent ?? '').split(','))).toEqual(
sorted(['crm_account', 'crm_activity', 'crm_contact', 'crm_lead', 'crm_opportunity', 'sys_user']),
);
@@ -367,7 +368,7 @@ describe('a package-less app’s record route with no declared record page reads
land();
await waitFor(() => expect(screen.getByTestId('record-view')).toHaveTextContent('crm_activity'));
await settle();
- expect(objectCalls()).toEqual(['object?names=sys_user', 'object/sys_user']);
+ expect(objectCalls()).toEqual(['object?names=sys_user']);
});
});
@@ -469,8 +470,9 @@ describe('a packaged app’s record route with no declared record page reads its
expect(objectCalls()).not.toContain('object');
// The object of another package is answered from the bundle, asked of no route.
- // objectstack#34244 — the lookup target outside the package after one presence read.
- expect(objectCalls()).toEqual(['object?package=app.crm', 'object?names=sys_user', 'object/sys_user']);
+ // objectstack#34244 — the lookup target outside the package in one presence read, which
+ // answers it (objectstack#35306).
+ expect(objectCalls()).toEqual(['object?package=app.crm', 'object?names=sys_user']);
});
it('draws the registry’s related lists in the registry’s order, the object of another package in its place', async () => {
@@ -505,7 +507,7 @@ describe('a packaged app’s record route with no declared record page reads its
await waitFor(() => expect(screen.getByTestId('record-view')).toHaveTextContent('crm_contact'));
await settle();
- expect(objectCalls()).toEqual(['object?package=app.crm', 'object?names=sys_user', 'object/sys_user']);
+ expect(objectCalls()).toEqual(['object?package=app.crm', 'object?names=sys_user']);
expect(screen.getByTestId('record-view').textContent).not.toContain('ops_visit');
});
@@ -563,7 +565,7 @@ describe('a tracked object’s record route asks sys_audit_log by name (objectst
expect(firstRender()).toContain('sys_audit_log');
expect(objectCalls()).not.toContain('object');
- expect(sorted(objectCalls())).toEqual(sorted(['object?package=app.crm', 'object?names=sys_user', 'object/sys_user', 'object/sys_audit_log']));
+ expect(sorted(objectCalls())).toEqual(sorted(['object?package=app.crm', 'object?names=sys_user', 'object/sys_audit_log']));
expect(drawnRelated()).toEqual(registryRelated('crm_account'));
});
@@ -574,7 +576,7 @@ describe('a tracked object’s record route asks sys_audit_log by name (objectst
expect(firstRender()).toContain('sys_audit_log');
expect(objectCalls()).not.toContain('object');
- expect(sorted(objectCalls())).toEqual(sorted(['object?names=sys_user', 'object/sys_user', 'object/sys_audit_log']));
+ expect(sorted(objectCalls())).toEqual(sorted(['object?names=sys_user', 'object/sys_audit_log']));
expect(drawnRelated()).toEqual(registryRelated('crm_account'));
});
diff --git a/ui/packages/app-shell/src/console/__tests__/AppContent.packagelessRoot-29552.test.tsx b/ui/packages/app-shell/src/console/__tests__/AppContent.packagelessRoot-29552.test.tsx
index 9257df3c5b6..0a5509b3d5f 100644
--- a/ui/packages/app-shell/src/console/__tests__/AppContent.packagelessRoot-29552.test.tsx
+++ b/ui/packages/app-shell/src/console/__tests__/AppContent.packagelessRoot-29552.test.tsx
@@ -13,7 +13,8 @@
*
* Pins:
* (a) a root that stays on screen (its only entry is a link, so it has no
- * landing) asks the object its entry requires by name, and no list;
+ * landing) answers the object its entry requires from the bundle, through
+ * the presence read (objectstack#34211, objectstack#35306), and asks no list;
* (b) a root whose landing is a page lands on it, and no list is asked on
* the way;
* (c) CONTROL: with the lists already loaded, the root asks nothing by name;
@@ -44,6 +45,7 @@ vi.mock('../../layout/ConsoleLayout', async () => {
return (
{String(gates.checkCapability('object', 'gone_obj'))}
+ {String(gates.checkCapability('object', 'note'))}
{children}
);
@@ -249,6 +251,9 @@ function boot(url: string, options: { listsLoaded?: boolean } = {}) {
/** The calls that read a whole list of one of the three types. */
const listCalls = () => server.calls.filter((c) => c === 'object' || c === 'view' || c === 'page');
const byNameCalls = () => server.calls.filter((c) => c.startsWith('object/') || c.startsWith('page/'));
+/** Every object read that names `note`: by name, or in a `?names=` presence read. */
+const noteReads = () =>
+ server.calls.filter((c) => c === 'object/note' || (c.startsWith('object?names=') && c.slice('object?names='.length).split(',').includes('note')));
beforeEach(() => {
server.calls = [];
@@ -263,12 +268,17 @@ afterEach(() => {
});
describe('a package-less app’s root reads the objects it requires by name (objectstack#29552)', () => {
- it('(a) a root with no landing asks the object its entry requires by name, and no list', async () => {
+ it('(a) a root with no landing answers the object its entry requires from the bundle, and asks no list', async () => {
boot('/apps/links');
await waitFor(() => expect(screen.getByTestId('gone-entry')).toHaveTextContent('false'));
- await waitFor(() => expect(byNameCalls()).toContain('object/note'));
+ await waitFor(() => expect(screen.getByTestId('note-entry')).toHaveTextContent('true'));
await new Promise((resolve) => setTimeout(resolve, 50));
+ // objectstack#34211 — the bundle holds `note`, so the presence read answers
+ // it with no request; objectstack#35306 — and that answer is its definition,
+ // so it is not asked by name either.
+ expect(noteReads()).toEqual([]);
+
expect(screen.queryByTestId('object-view')).toBeNull();
expect(listCalls()).toEqual([]);
});
@@ -278,7 +288,9 @@ describe('a package-less app’s root reads the objects it requires by name (obj
await waitFor(() => expect(screen.getByTestId('page-blocks')).toHaveTextContent('Notes home'));
await waitFor(() => expect(screen.getByTestId('gone-entry')).toHaveTextContent('false'));
- expect(byNameCalls()).toContain('object/note');
+ // objectstack#35306 — the bundle answers it through the presence read: no request of its own.
+ expect(screen.getByTestId('note-entry')).toHaveTextContent('true');
+ expect(noteReads()).toEqual([]);
expect(listCalls()).toEqual([]);
});
diff --git a/ui/packages/app-shell/src/console/__tests__/AppContent.pageRouteObjects-12980.test.tsx b/ui/packages/app-shell/src/console/__tests__/AppContent.pageRouteObjects-12980.test.tsx
index 6b4b3c53617..a14370ee81b 100644
--- a/ui/packages/app-shell/src/console/__tests__/AppContent.pageRouteObjects-12980.test.tsx
+++ b/ui/packages/app-shell/src/console/__tests__/AppContent.pageRouteObjects-12980.test.tsx
@@ -297,9 +297,10 @@ describe('a page route reads the objects its page binds, never the whole registr
await waitFor(() => expect(screen.getByTestId('cloud-only-entry')).toHaveTextContent('false'));
// objectstack#34244 — the `requiresObject` entry and the lookup target in
- // presence reads; the unregistered `cloud_only` is never asked by name.
+ // presence reads; the unregistered `cloud_only` is never asked by name, and
+ // the served `sys_user` is answered by its read (objectstack#35306).
expect([...objectCalls()].sort()).toEqual(
- [`object?package=${CRM}`, 'object?names=cloud_only', 'object?names=sys_user', 'object/sys_user'].sort(),
+ [`object?package=${CRM}`, 'object?names=cloud_only', 'object?names=sys_user'].sort(),
);
});
diff --git a/ui/packages/app-shell/src/console/__tests__/appObjectScope-12811.test.tsx b/ui/packages/app-shell/src/console/__tests__/appObjectScope-12811.test.tsx
index 1da98096315..c090452cedd 100644
--- a/ui/packages/app-shell/src/console/__tests__/appObjectScope-12811.test.tsx
+++ b/ui/packages/app-shell/src/console/__tests__/appObjectScope-12811.test.tsx
@@ -9,9 +9,9 @@
* scope it alone asked for started one permission round trip later.
* `useAppObjectScopePrefetch` (mounted by `ConsoleShell`'s root action runtime)
* asks the scope as soon as the app list names the app: the package list,
- * then by name the route object's lookup targets outside the package, each
- * once the one `?names=` presence read has answered it served
- * (objectstack#34244).
+ * then the route object's lookup targets outside the package in one `?names=`
+ * presence read (objectstack#34244), whose served answer is each target's
+ * definition: none is asked again by name (objectstack#35306).
*
* CONTROLs: a route outside an app and a record form overlay ask nothing here
* (`AppContent` reads the whole registry there). An app item with no package
@@ -101,17 +101,20 @@ const APPS = [{ name: 'crm', _packageId: CRM, navigation: [] }];
afterEach(() => cleanup());
describe('the console root starts the app object scope (objectui#12811)', () => {
- it("asks the app's package list, then the route object's lookup targets by name, never the whole list", async () => {
+ it("asks the app's package list, then the route object's lookup targets in the presence read, never the whole list", async () => {
const calls = mount('/apps/crm/crm_account', APPS);
- await waitFor(() => expect(calls).toContain('object/sys_user'));
- // objectstack#34244 — the target outside the package is asked by name once the presence read answered it served.
- expect(objectCalls(calls)).toEqual([`object?package=${CRM}`, 'object?names=sys_user', 'object/sys_user']);
+ await waitFor(() => expect(calls).toContain('object?names=sys_user'));
+ await new Promise((resolve) => setTimeout(resolve, 50));
+ // objectstack#34244 — the target outside the package is asked in the presence read;
+ // objectstack#35306 — which answered it served, so it is not asked again by name.
+ expect(objectCalls(calls)).toEqual([`object?package=${CRM}`, 'object?names=sys_user']);
});
it('objectstack#27626 — under a record drawer it asks the scope of the list the drawer opens over', async () => {
const calls = mount('/apps/crm/crm_account?recordId=r1', APPS);
- await waitFor(() => expect(calls).toContain('object/sys_user'));
- expect(objectCalls(calls)).toEqual([`object?package=${CRM}`, 'object?names=sys_user', 'object/sys_user']);
+ await waitFor(() => expect(calls).toContain('object?names=sys_user'));
+ await new Promise((resolve) => setTimeout(resolve, 50));
+ expect(objectCalls(calls)).toEqual([`object?package=${CRM}`, 'object?names=sys_user']);
});
it('objectstack#28645 — enters the app\'s metadata bundle as it starts the scope, once the app list names the app', async () => {
@@ -156,8 +159,9 @@ describe('the console root starts the app object scope (objectui#12811)', () =>
await new Promise((resolve) => setTimeout(resolve, 50));
expect(objectCalls(outside)).toEqual([]);
expect(objectCalls(overlay)).toEqual([]);
- // objectstack#34188 — the lookup target is asked by name once the `?names=` read has answered it served.
- expect([...objectCalls(noPackage)].sort()).toEqual(['object/crm_account', 'object/sys_user', 'object?names=sys_user']);
+ // objectstack#34188 — the lookup target is asked in the `?names=` read, and
+ // (objectstack#35306) answered by it: no by-name read of its own.
+ expect([...objectCalls(noPackage)].sort()).toEqual(['object/crm_account', 'object?names=sys_user']);
});
});
@@ -252,11 +256,12 @@ describe('objectstack#29551 — a packaged app asks its lookup targets without v
const reads = (calls: string[]) => calls.filter((c) => c !== 'app');
- it('a lookup target outside the bundle is asked by name without views: no /meta/view list, and the route object keeps its views', async () => {
+ it('a lookup target outside the bundle is answered without views: no /meta/view list, and the route object keeps its views', async () => {
const { calls, scope } = mountBundled('/apps/crm/crm_account');
await waitFor(() => expect(scope()).toContain('sys_user['));
await new Promise((resolve) => setTimeout(resolve, 50));
- expect(reads(calls)).toEqual([`object?package=${CRM}`, 'object?names=sys_user', 'object/sys_user']);
+ // objectstack#35306 — the presence read that served it is its one read.
+ expect(reads(calls)).toEqual([`object?package=${CRM}`, 'object?names=sys_user']);
expect(scope()).toBe('crm_account[crm_account.all],crm_contact[crm_contact.all],sys_user[]');
});
@@ -292,27 +297,20 @@ describe('objectstack#33343 — a hidden lookup asks no definition of its target
{ name: 'sys_business_unit', _packageId: 'plugin.security', fields: {} },
];
- it('the route asks its drawn lookup target by name, and never the targets of its hidden lookups', async () => {
+ it('the route asks its drawn lookup target, and never the targets of its hidden lookups', async () => {
const calls = mount('/apps/crm/crm_account', APPS, withAnchors(true));
- await waitFor(() => expect(calls).toContain('object/sys_user'));
+ await waitFor(() => expect(calls).toContain('object?names=sys_user'));
await new Promise((resolve) => setTimeout(resolve, 50));
- expect(objectCalls(calls)).toEqual([`object?package=${CRM}`, 'object?names=sys_user', 'object/sys_user']);
+ expect(objectCalls(calls)).toEqual([`object?package=${CRM}`, 'object?names=sys_user']);
});
- it('CONTROL: the same lookups drawn ask every registered target by name, once one presence read has answered them', async () => {
+ it('CONTROL: the same lookups drawn ask every registered target, in one presence read', async () => {
const calls = mount('/apps/crm/crm_account', APPS, withAnchors(false));
- await waitFor(() => expect(calls).toContain('object/sys_business_unit'));
+ await waitFor(() => expect(calls).toContain('object?names=sys_user,sys_organization,sys_business_unit'));
await new Promise((resolve) => setTimeout(resolve, 50));
- // objectstack#34244 — the three targets outside the package are asked in ONE `?names=` read first.
- expect([...objectCalls(calls)].sort()).toEqual(
- [
- `object?package=${CRM}`,
- 'object?names=sys_user,sys_organization,sys_business_unit',
- 'object/sys_business_unit',
- 'object/sys_organization',
- 'object/sys_user',
- ].sort(),
- );
+ // objectstack#34244 — the three targets outside the package are asked in ONE `?names=` read;
+ // objectstack#35306 — it served all three, so none is asked again by name.
+ expect(objectCalls(calls)).toEqual([`object?package=${CRM}`, 'object?names=sys_user,sys_organization,sys_business_unit']);
});
});
@@ -411,7 +409,8 @@ describe('objectstack#34188 — a lookup target the host does not register is ne
])('CONTROL: on %s a registered target still resolves into the scope', async (_arm, subPath) => {
const { calls, scope } = mountRoute(subPath);
await waitFor(() => expect(scope()).toBe('sys_invitation,sys_user'));
- expect(calls).toContain('object/sys_user');
+ // objectstack#35306 — from the presence read that served it, not a by-name read.
+ expect(calls).not.toContain('object/sys_user');
});
});
@@ -487,13 +486,16 @@ describe('objectstack#34244 — a packaged app asks an off-package lookup target
await waitFor(() => expect(scope()).toBe('crm_account,sys_user'));
await new Promise((resolve) => setTimeout(resolve, 50));
expect(calls).not.toContain('object/cloud_billing');
- expect(calls).toContain('object/sys_user');
+ // objectstack#35306 — the served `sys_user` is answered by the presence read.
+ expect(calls).not.toContain('object/sys_user');
});
- it.each(ARMS)('CONTROL: on %s a registered off-package target and requiresObject still resolve by name', async (_arm, subPath) => {
+ it.each(ARMS)('CONTROL: on %s a registered off-package target and requiresObject still resolve, from the presence read', async (_arm, subPath) => {
const { calls, scope } = mountRoute(subPath);
await waitFor(() => expect(scope()).toBe('crm_account,sys_user'));
- expect(calls).toContain('object/sys_user');
+ await new Promise((resolve) => setTimeout(resolve, 50));
+ // objectstack#35306 — the presence read served it, so no by-name read follows.
+ expect(calls).not.toContain('object/sys_user');
expect(calls).toContain(`object?package=${CRM}`);
});
});
diff --git a/ui/packages/app-shell/src/console/appObjectScope.ts b/ui/packages/app-shell/src/console/appObjectScope.ts
index c30a9637ec0..cda1de6b128 100644
--- a/ui/packages/app-shell/src/console/appObjectScope.ts
+++ b/ui/packages/app-shell/src/console/appObjectScope.ts
@@ -793,7 +793,10 @@ function readObjectRouteNames(
// route's names: a lookup cell links and names its target and reads none of
// its views, and a target outside the app bundle (`sys_user`) composed with
// them read the whole `/meta/view` list (objectstack#29551). They join the
- // scope's objects as they land; the route's names keep their views.
+ // scope's objects as they land; the route's names keep their views. A
+ // target the presence read answered served is answered with the definition
+ // that read carried, and costs no request of its own (objectstack#35306,
+ // `readObjectScope`).
const readWithoutViews = readObjectScope as ReadNamesWithoutViews;
const readNames = (names: readonly string[]) =>
packageId ? readWithoutViews({ packageId, names, views: false }) : readWithoutViews({ names, views: false });
diff --git a/ui/packages/app-shell/src/console/home/__tests__/HomePage.recentDisabledPackage-34692.test.tsx b/ui/packages/app-shell/src/console/home/__tests__/HomePage.recentDisabledPackage-34692.test.tsx
index ae192f76b6e..563f5f6b82b 100644
--- a/ui/packages/app-shell/src/console/home/__tests__/HomePage.recentDisabledPackage-34692.test.tsx
+++ b/ui/packages/app-shell/src/console/home/__tests__/HomePage.recentDisabledPackage-34692.test.tsx
@@ -202,7 +202,9 @@ describe('Home leaves out a recent row whose object is not registered, and never
await waitFor(() => expect(icons()).toEqual(['building', 'briefcase']));
expect(titles()).toEqual(['Acme', 'Wayne Operations Module Rollout']);
await settle();
- expect(objectReads(enabled)).toContain('object/pm_project');
+ // The presence read served both, and answers their by-name scope: no
+ // `object/NAME` read follows it (objectstack#35306).
+ expect(objectReads(enabled)).toEqual(['object?names=crm_account,pm_project']);
cleanup();
// The package is disabled; the stored entry outlives it.
@@ -212,8 +214,9 @@ describe('Home leaves out a recent row whose object is not registered, and never
expect(titles()).toEqual(['Acme']);
await settle();
expect(titles()).toEqual(['Acme']);
- // One presence read for both names; by name only the served one.
- expect(objectReads(disabled).sort()).toEqual(['object/crm_account', 'object?names=crm_account,pm_project']);
+ // One presence read for both names; nothing by name: the served one is
+ // answered by that read (objectstack#35306), the left-out one is not asked.
+ expect(objectReads(disabled)).toEqual(['object?names=crm_account,pm_project']);
expect(objectReads(disabled)).not.toContain('object/pm_project');
});
diff --git a/ui/packages/app-shell/src/console/home/__tests__/HomePage.recentObjectReads-29121.test.tsx b/ui/packages/app-shell/src/console/home/__tests__/HomePage.recentObjectReads-29121.test.tsx
index 5c8b1057cef..91759e5538c 100644
--- a/ui/packages/app-shell/src/console/home/__tests__/HomePage.recentObjectReads-29121.test.tsx
+++ b/ui/packages/app-shell/src/console/home/__tests__/HomePage.recentObjectReads-29121.test.tsx
@@ -8,7 +8,9 @@
* label (`useNavTargetLabel`), an object row's title and a list-view row's
* label (`useRecentItemLabel`). Each loaded the whole object registry on every
* visit. Now each row reads its own object by name; a list-view row reads its
- * object with its views (the `/meta/view` list), which its label is.
+ * object with its views (the `/meta/view` list), which its label is. The rows'
+ * names go in one `?names=` presence read, and a name it served is not read
+ * again as `/meta/object/NAME` (objectstack#35306).
*
* Real subjects: `HomePage` and `MetadataProvider` over a fake adapter that
* records each read; the rest of the page is the harness of
@@ -238,7 +240,9 @@ describe('Home’s recent rows read the objects they name, by name (objectstack#
'Account',
]);
await settle();
- expect([...metaReads(calls)].sort()).toEqual(['object/crm_account', 'object/crm_contact', 'object?names=crm_account,crm_contact']);
+ // The presence read SERVED both objects, so it answers their by-name scope
+ // too: no `object/NAME` read follows it (objectstack#35306).
+ expect([...metaReads(calls)].sort()).toEqual(['object?names=crm_account,crm_contact']);
});
it('an object row reads its object by name; a list-view row its object with its views (the view list, never the object list)', async () => {
@@ -258,6 +262,7 @@ describe('Home’s recent rows read the objects they name, by name (objectstack#
expect(rows().map((row) => row.querySelector('span.truncate')?.textContent)).toEqual(['Accounts', 'Open Leads']),
);
await settle();
- expect([...metaReads(calls)].sort()).toEqual(['object/crm_account', 'object/crm_lead', 'object?names=crm_account,crm_lead', 'view']);
+ // Served by the presence read, each object is not read again by name (objectstack#35306).
+ expect([...metaReads(calls)].sort()).toEqual(['object?names=crm_account,crm_lead', 'view']);
});
});
diff --git a/ui/packages/app-shell/src/hooks/__tests__/packagelessChromeScope-12980.test.tsx b/ui/packages/app-shell/src/hooks/__tests__/packagelessChromeScope-12980.test.tsx
index f8b3cb04dc2..f3914960d74 100644
--- a/ui/packages/app-shell/src/hooks/__tests__/packagelessChromeScope-12980.test.tsx
+++ b/ui/packages/app-shell/src/hooks/__tests__/packagelessChromeScope-12980.test.tsx
@@ -112,9 +112,10 @@ describe('package-less app: the chrome readers read the names-only scope (object
expect(read().presence.presence).toBe('present');
expect(objectCalls(calls)).not.toContain('object');
- // objectstack#34244 — `note` is the entry's `requiresObject`: asked by name
- // once the `?names=` presence read has answered it served.
- expect([...objectCalls(calls)].sort()).toEqual(['object/note', 'object/sys_activity', 'object?names=note'].sort());
+ // objectstack#34244 — `note` is the entry's `requiresObject`: asked in the
+ // `?names=` presence read, whose served answer is its definition
+ // (objectstack#35306), so it is not asked again by name.
+ expect([...objectCalls(calls)].sort()).toEqual(['object/sys_activity', 'object?names=note'].sort());
});
it('(a) an object the deployment does not have reads absent, by name, with no whole-registry read', async () => {
@@ -180,14 +181,15 @@ describe('objectstack#34244 — the served view items ask no required object the
],
};
- it('asks both in the presence read, and by name only the one it serves', async () => {
+ it('asks both in the presence read, and by name neither: the one it serves is answered by that read', async () => {
const calls: string[] = [];
const read = mount(GATED_APP, calls);
await waitFor(() => expect(isServedView(read().served, 'note', 'note.recent')).toBe(true));
await new Promise((resolve) => setTimeout(resolve, 50));
expect(objectCalls(calls)).toContain('object?names=note,gone_obj');
- expect(objectCalls(calls)).toContain('object/note');
+ // objectstack#35306 — the served `note` is answered by the presence read.
+ expect(objectCalls(calls)).not.toContain('object/note');
expect(objectCalls(calls)).not.toContain('object/gone_obj');
});
});
diff --git a/ui/packages/app-shell/src/providers/MetadataProvider.tsx b/ui/packages/app-shell/src/providers/MetadataProvider.tsx
index e6bbea12adb..74386095634 100644
--- a/ui/packages/app-shell/src/providers/MetadataProvider.tsx
+++ b/ui/packages/app-shell/src/providers/MetadataProvider.tsx
@@ -189,7 +189,11 @@ const NAMES_ONLY_SCOPE = '';
* by-name envelope (no `sortability`), shares no request with the adapter's
* `getObjectSchema` (objectui#13044), and cannot tell an absent object from a
* refused one (`OBJECT_PACKAGE_DISABLED`), so a route's reader never takes
- * its answer for its own.
+ * its absences for its own: a name it left out is still asked by name. The
+ * one thing a route's reader does take from it is a definition it SERVED
+ * (objectstack#35306): the list door serves that definition through the same
+ * gate, mask and translation as the by-name door, and the by-name envelope's
+ * extras never reach a scope.
*/
const NAMES_BATCH_SCOPE: unique symbol = Symbol('names-batch');
@@ -1953,6 +1957,17 @@ export function MetadataProvider({ children, adapter, ttlMs = DEFAULT_TTL_MS }:
}
}
}
+ // objectstack#35306 — the definition the presence read (the batched
+ // names scope) answered for `name`, once that read has answered it
+ // served; `undefined` while it is asked, absent, failed or never asked.
+ const presence = batched ? undefined : scopesRef.current.get(NAMES_BATCH_SCOPE);
+ const presentDefinition = (name: string): unknown =>
+ presence?.names.get(name) === 'answered' ? presence.items.find((it: any) => it?.name === name) : undefined;
+ // A reader that asks a name for its side effect and reads the scope
+ // through an earlier read (a route's lookup targets) learns of a name
+ // answered here only on the render this bump causes, as it would of a
+ // by-name answer landing.
+ let answeredFromPresence = false;
let namesSettled = true;
const failedNames: string[] = [];
const toBatch: string[] = [];
@@ -1992,6 +2007,29 @@ export function MetadataProvider({ children, adapter, ttlMs = DEFAULT_TTL_MS }:
entry.items = [...entry.items, bundled.value];
continue;
}
+ } else {
+ // objectstack#35306 — the other way round: a name the presence
+ // read has answered SERVED is answered with the definition that
+ // read carried, and not asked again by name. The list door
+ // serves an object's definition through the same per-caller
+ // gate, mask and translation as the by-name door, and its
+ // switched-off actions beside it (`ingestObjectList`); what the
+ // by-name envelope adds (`sortability`, `cascadeDeleteObjects`)
+ // rides the adapter's own copy, never a scope's
+ // (`cloneServedObject`). So a lookup target the presence read
+ // answered costs no second request. Only a served answer is
+ // taken: a name the presence read left out may be
+ // absent or refused, which only a by-name read tells apart
+ // (`NAMES_BATCH_SCOPE`), so it is asked by name as before. Never
+ // under the draft preview, whose reads must see the drafts.
+ const present = previewClientRef.current ? undefined : presentDefinition(name);
+ if (present) {
+ entry.names.set(name, 'answered');
+ entry.items = [...entry.items, present];
+ if (entry.missing.includes(name)) entry.missing = entry.missing.filter((n) => n !== name);
+ answeredFromPresence = true;
+ continue;
+ }
}
namesSettled = false;
if (batched) toBatch.push(name);
@@ -2000,6 +2038,7 @@ export function MetadataProvider({ children, adapter, ttlMs = DEFAULT_TTL_MS }:
}
}
if (toBatch.length > 0) void fetchScopeNames(entry, toBatch);
+ if (answeredFromPresence) bump();
// objectui#13052 — `settled` stays false while a name's read has
// failed (a failure is not an answer, objectui#13009); `failed` names
// those reads once nothing else is still in flight, so a reader can stop
@@ -2046,7 +2085,7 @@ export function MetadataProvider({ children, adapter, ttlMs = DEFAULT_TTL_MS }:
views: scopeViews.views,
};
},
- [fetchScopeList, fetchScopeName, fetchScopeNames, getEntry, readBundledItem, readType, viewsForObjects],
+ [bump, fetchScopeList, fetchScopeName, fetchScopeNames, getEntry, readBundledItem, readType, viewsForObjects],
);
const value = useMemo(() => {
diff --git a/ui/packages/app-shell/src/providers/__tests__/MetadataProvider.scopeRefusal-13052.test.tsx b/ui/packages/app-shell/src/providers/__tests__/MetadataProvider.scopeRefusal-13052.test.tsx
index eea08e9a405..81b66e6b6a7 100644
--- a/ui/packages/app-shell/src/providers/__tests__/MetadataProvider.scopeRefusal-13052.test.tsx
+++ b/ui/packages/app-shell/src/providers/__tests__/MetadataProvider.scopeRefusal-13052.test.tsx
@@ -16,6 +16,10 @@
* `invalidate` of the name asks it exactly once more;
* (d) CONTROL: a served object is present, nothing failed, nothing refused,
* one request.
+ *
+ * objectstack#35306 — after a `?names=` presence read: a name it SERVED is
+ * answered with that definition and asked by name never; a name it left out
+ * is still asked by name, so a refusal is still told apart from an absence.
*/
import { act, cleanup, render, waitFor } from '@testing-library/react';
@@ -180,3 +184,95 @@ describe('a definite refusal is an answer; a failed read settles once (objectui#
expect(byName(m.server.calls)).toBe(1);
});
});
+
+describe('a name the presence read SERVED is answered from it; one it left out is still asked by name (objectstack#35306)', () => {
+ type Presence = 'serves' | 'leaves-out';
+ const PRESENCE = `/api/v1/meta/object?names=${NAME}`;
+ const SERVED_DEF = { name: NAME, label: 'Probe widget', fields: { title: { type: 'text', label: 'Title' } } };
+
+ /**
+ * The presence read first (`views: false`, `batch: true`, the `?names=`
+ * list door), then, once it has answered, the route's by-name read of the
+ * same name (`views: false`, as a lookup target is read).
+ */
+ function mountAfterPresence(presence: Presence, byNameAnswer: Answer) {
+ const server = { calls: [] as string[] };
+ const adapter = new ObjectStackAdapter({
+ baseUrl: `http://presence-35306-${(seq += 1)}.test`,
+ autoReconnect: false,
+ fetch: (async (input: RequestInfo | URL) => {
+ const url = new URL(String(input));
+ if (url.pathname.endsWith('/discovery')) return json(200, { success: true, data: {} });
+ server.calls.push(url.pathname + url.search);
+ if (url.pathname === BY_NAME) return respond(byNameAnswer);
+ if (url.pathname === '/api/v1/meta/object' && url.searchParams.get('names') === NAME) {
+ // The list door leaves an absent or refused name out alike.
+ const items = presence === 'serves' ? [SERVED_DEF] : [];
+ return json(200, { success: true, data: { type: 'object', items, disabledActions: {} } });
+ }
+ const list = /^\/api\/v1\/meta\/([a-z_]+)$/.exec(url.pathname);
+ if (list) return json(200, { success: true, data: { type: list[1], items: [] } });
+ return json(404, { success: false, error: { message: `no route ${url.pathname}` } });
+ }) as typeof fetch,
+ });
+ let latest: Ctx | null = null;
+ function Probe() {
+ latest = useMetadata();
+ const read = latest.readObjectScope! as unknown as (scope: Record) => { settled: boolean };
+ if (read({ names: [NAME], views: false, batch: true }).settled) read({ names: [NAME], views: false });
+ return null;
+ }
+ render(
+
+
+ ,
+ );
+ const read = (scope: Record) =>
+ (latest as unknown as Ctx).readObjectScope!(scope as Parameters>[0]) as ReturnType<
+ NonNullable
+ > & { refused?: Readonly>; failed?: readonly string[] };
+ // The test reads the route's scope only once the presence read has
+ // answered, as the route asks it: a read made before then is asked by
+ // name, as it always was.
+ const presenceSettled = () => read({ names: [NAME], views: false, batch: true }).settled;
+ const routeScope = () => read({ names: [NAME], views: false });
+ return { server, presenceSettled, routeScope };
+ }
+
+ it('a served name joins the route scope with the definition the presence read carried, and is not asked by name', async () => {
+ const m = mountAfterPresence('serves', 'served');
+ await waitFor(() => expect(m.presenceSettled()).toBe(true));
+ await waitFor(() => expect(m.routeScope().settled).toBe(true));
+ await settle();
+ const scope = m.routeScope();
+ expect(scope.objects).toEqual([SERVED_DEF]);
+ expect(scope.missing).toEqual([]);
+ expect(scope.refused).toEqual({});
+ expect(byName(m.server.calls)).toBe(0);
+ expect(m.server.calls.filter((c) => c === PRESENCE)).toHaveLength(1);
+ });
+
+ for (const envelope of ['disabled-flat', 'disabled-wrapped'] as const) {
+ it(`a name the presence read left out is asked by name, and its refusal is named (${envelope})`, async () => {
+ const m = mountAfterPresence('leaves-out', envelope);
+ await waitFor(() => expect(m.presenceSettled()).toBe(true));
+ await waitFor(() => expect(m.routeScope().settled).toBe(true));
+ await settle();
+ const scope = m.routeScope();
+ expect(scope.missing).toEqual([NAME]);
+ expect(scope.refused).toEqual({ [NAME]: 'OBJECT_PACKAGE_DISABLED' });
+ expect(byName(m.server.calls)).toBe(1);
+ });
+ }
+
+ it('CONTROL: a name the presence read left out that the by-name door answers absent is the plain absence', async () => {
+ const m = mountAfterPresence('leaves-out', 'absent');
+ await waitFor(() => expect(m.presenceSettled()).toBe(true));
+ await waitFor(() => expect(m.routeScope().settled).toBe(true));
+ await settle();
+ const scope = m.routeScope();
+ expect(scope.missing).toEqual([NAME]);
+ expect(scope.refused).toEqual({});
+ expect(byName(m.server.calls)).toBe(1);
+ });
+});