Skip to content
Merged
13 changes: 13 additions & 0 deletions .changeset/35306-lookup-target-single-read.md
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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',
]),
);
});
Expand Down Expand Up @@ -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 () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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> = [];
Expand All @@ -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 : [];
Expand Down Expand Up @@ -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();
Expand All @@ -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');
Expand All @@ -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');
});

Expand Down Expand Up @@ -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 () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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']),
);
Expand Down Expand Up @@ -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']);
});
});

Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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');
});

Expand Down Expand Up @@ -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'));
});

Expand All @@ -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'));
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -44,6 +45,7 @@ vi.mock('../../layout/ConsoleLayout', async () => {
return (
<div data-testid="console-layout">
<span data-testid="gone-entry">{String(gates.checkCapability('object', 'gone_obj'))}</span>
<span data-testid="note-entry">{String(gates.checkCapability('object', 'note'))}</span>
{children}
</div>
);
Expand Down Expand Up @@ -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 = [];
Expand All @@ -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([]);
});
Expand All @@ -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([]);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
);
});

Expand Down
Loading
Loading