diff --git a/src/visualBuilder/components/__test__/fieldlabelwrapper/fieldLabelWrapper.renderFields.test.tsx b/src/visualBuilder/components/__test__/fieldlabelwrapper/fieldLabelWrapper.renderFields.test.tsx index 2867ebf1..7985144a 100644 --- a/src/visualBuilder/components/__test__/fieldlabelwrapper/fieldLabelWrapper.renderFields.test.tsx +++ b/src/visualBuilder/components/__test__/fieldlabelwrapper/fieldLabelWrapper.renderFields.test.tsx @@ -328,4 +328,31 @@ describe("FieldLabelWrapperComponent - Render Fields", () => { { timeout: 1000, interval: 10 } ); }); + + // Without an entry the builder resolves every entry on the page, one API + // call each, to fill in a tooltip that reads one row. + test("names the entry it needs when asking for the reference map", async () => { + await act(async () => { + render( + + ); + await new Promise((resolve) => + queueMicrotask(() => resolve()) + ); + }); + + expect(visualBuilderPostMessage!.send).toHaveBeenCalledWith( + VisualBuilderPostMessageEvents.REFERENCE_MAP, + { + entryUid: mockFieldMetadata.entry_uid, + contentTypeUid: mockFieldMetadata.content_type_uid, + locale: mockFieldMetadata.locale, + } + ); + }); }); diff --git a/src/visualBuilder/components/fieldLabelWrapper.tsx b/src/visualBuilder/components/fieldLabelWrapper.tsx index b92a2834..fa80eaf9 100644 --- a/src/visualBuilder/components/fieldLabelWrapper.tsx +++ b/src/visualBuilder/components/fieldLabelWrapper.tsx @@ -50,9 +50,21 @@ async function getContentTypeName(contentTypeUid: string) { } } -async function getReferenceParentMap() { +/** + * The parents of this field's entry. + * + * Names the entry rather than asking for the whole page: the builder resolved + * every entry on the page otherwise, one API call each (measured at 30 calls + * for a nav with roughly 24 links), while the label reads a single row. An + * older builder ignores the payload and still answers with the full map. + */ +async function getReferenceParentMap(fieldMetadata: CslpData) { try { - const result = await visualBuilderPostMessage?.send(VisualBuilderPostMessageEvents.REFERENCE_MAP, {}) ?? {}; + const result = await visualBuilderPostMessage?.send(VisualBuilderPostMessageEvents.REFERENCE_MAP, { + entryUid: fieldMetadata.entry_uid, + contentTypeUid: fieldMetadata.content_type_uid, + locale: fieldMetadata.locale, + }) ?? {}; return result; } catch(e) { console.warn("[getFieldLabelWrapper] Error getting reference parent map", e); @@ -240,7 +252,7 @@ function FieldLabelWrapperComponent( getContentTypeName( props.fieldMetadata.content_type_uid ), - getReferenceParentMap() + getReferenceParentMap(props.fieldMetadata) ]); const entryUid = props.fieldMetadata.entry_uid;