Skip to content

Commit 13728b7

Browse files
authored
ENG-1694: Memoize getAllPageNames in Share Query Results dialog (#1096)
* ENG-1694: Memoize getAllPageNames in Share Query Results dialog getAllPageNames() was called inline in JSX, walking every page in the graph on each render of ExportDialog. On big graphs the 'Send to Page' autocomplete took seconds to populate. Hoist into useMemo so it runs once per dialog mount. Also cap AutocompleteInput's rendered dropdown at 50 items (default Infinity) to avoid rendering thousands of MenuItems per keystroke. * ENG-1694: Refresh page-name list when Share dialog opens Empty-dependency memo captured page names once when ResultsView mounted, not when the dialog opened. Pages created or renamed in between never appeared in the autocomplete. Gate the memo on isOpen so the list is recomputed each time the dialog is shown.
1 parent e527149 commit 13728b7

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

apps/roam/src/components/Export.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,10 @@ const ExportDialog: ExportDialogComponent = ({
193193
const currentPageTitle = getPageTitleByPageUid(currentPageUid);
194194
const [selectedPageTitle, setSelectedPageTitle] = useState(currentPageTitle);
195195
const [selectedPageUid, setSelectedPageUid] = useState(currentPageUid);
196+
const allPageNames = useMemo(
197+
() => (isOpen ? getAllPageNames() : []),
198+
[isOpen],
199+
);
196200
const isCanvasPage = checkForCanvasPage(selectedPageTitle);
197201
const [activeSendToDestination, setActiveSendToDestination] =
198202
useState<(typeof SEND_TO_DESTINATIONS)[number]>("page");
@@ -1011,7 +1015,8 @@ const ExportDialog: ExportDialogComponent = ({
10111015
value={selectedPageTitle}
10121016
setValue={(title) => handleSetSelectedPage(title)}
10131017
onBlur={(title) => handleSetSelectedPage(title)}
1014-
options={getAllPageNames()}
1018+
options={allPageNames}
1019+
maxItemsDisplayed={50}
10151020
/>
10161021
</div>
10171022
)}

0 commit comments

Comments
 (0)