Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
opt(soup): idToDisplayName, capture split state (#4892)
teoa19c8c1efe6d
diff --git a/apps/web/src/components/app/split-layout/layoutManager.ts b/apps/web/src/components/app/split-layout/layoutManager.tsindex 875e48b030..1223628acf 100644--- a/apps/web/src/components/app/split-layout/layoutManager.ts+++ b/apps/web/src/components/app/split-layout/layoutManager.ts@@ -16,6 +16,7 @@ import { activeTabId } from '@core/signal/settingsTab';import { useFocusLock } from '@core/util/createControlledOpenSignal';import {type Accessor,+ batch,createMemo,createSignal,type JSXElement,@@ -758,12 +759,14 @@ export function createSplitLayout(const split = state.splits[i];if (!split.history.canGoBack()) return;- captureCurrentEntryState(split);+ batch(() => {+ captureCurrentEntryState(split);- const prev = split.history.back();- if (!prev) return;+ const prev = split.history.back();+ if (!prev) return;- reattach(split, prev, undefined, 'history-back');+ reattach(split, prev, undefined, 'history-back');+ });}function forward(id: SplitId) {@@ -773,12 +776,14 @@ export function createSplitLayout(const split = state.splits[i];if (!split.history.canGoForward()) return;- captureCurrentEntryState(split);+ batch(() => {+ captureCurrentEntryState(split);- const next = split.history.forward();- if (!next) return;+ const next = split.history.forward();+ if (!next) return;- reattach(split, next, undefined, 'history-forward');+ reattach(split, next, undefined, 'history-forward');+ });}function removeFromHistory(@@ -813,14 +818,21 @@ export function createSplitLayout(const content = attachAliasContext(next);const split = state.splits[i];- captureCurrentEntryState(split);- if (mergeHistory) {- split.history.merge(content);- } else {- split.history.push(content);- }+ batch(() => {+ captureCurrentEntryState(split);+ if (mergeHistory) {+ split.history.merge(content);+ } else {+ split.history.push(content);+ }- reattach(split, content, referredFrom, mergeHistory ? 'replace' : 'fresh');+ reattach(+ split,+ content,+ referredFrom,+ mergeHistory ? 'replace' : 'fresh'+ );+ });}function reset(id: SplitId) {diff --git a/apps/web/src/lib/core/user/displayName.ts b/apps/web/src/lib/core/user/displayName.tsindex c99b443974..b22628ce00 100644--- a/apps/web/src/lib/core/user/displayName.ts+++ b/apps/web/src/lib/core/user/displayName.ts@@ -1,7 +1,7 @@import { debounce } from '@core/util/debounce';import { authServiceClient } from '@service-auth/client';-import { createEffect, createSignal } from 'solid-js';+import { batch } from 'solid-js';import { createStore, unwrap } from 'solid-js/store';import { type MacroId, macroIdToEmail } from './macroId';import type { UserNameItem, UserNamePreviewFetcher } from './types';@@ -49,13 +49,18 @@ const [userDisplayNames, setUserDisplayNames] = createStore<DisplayNameStore>({});-const [displayNameFetchQueue, setDisplayNameFetchQueue] = createSignal<- string[]->([]);+const displayNameFetchQueue = new Set<string>();/** Adds items to fetch queue and schedules processing */function queueItemsForFetch(items: string[]) {- setDisplayNameFetchQueue((prev) => [...prev, ...items]);+ let addedItem = false;+ for (const item of items) {+ if (displayNameFetchQueue.has(item)) continue;+ displayNameFetchQueue.add(item);+ addedItem = true;+ }++ if (addedItem) processFetchQueue();}type DisplayNameOptions = {@@ -120,28 +125,26 @@ async function fetchDisplayNames(ids: string[]): Promise<UserNameItem[]> {}const processFetchQueue = debounce(async () => {- const items = displayNameFetchQueue();+ const items = [...displayNameFetchQueue];if (items.length === 0) return;- setDisplayNameFetchQueue([]);+ displayNameFetchQueue.clear();await batchFetchNames(items);-}, 50);+}, 10);async function batchFetchNames(ids: string[]) {const [nameResults] = await Promise.all([ids.length > 0 ? fetchDisplayNames(ids) : Promise.resolve([]),]);- const updates = nameResults.reduce((acc, result) => {- acc[result.id] = result;- return acc;- }, {} as DisplayNameStore);-- setUserDisplayNames((prev) => ({ ...prev, ...updates }));+ batch(() => {+ for (const result of nameResults) {+ setUserDisplayNames(result.id, result);+ }+ });}-/** Shared hook that handles caching/fetching and returns the underlying UserNameItem */-function useUserNameItem(id: MacroId) {+function ensureUserNameItem(id: MacroId) {const cached = userDisplayNames[id];const cacheExpired =cached &&@@ -157,13 +160,25 @@ function useUserNameItem(id: MacroId) {});queueItemsForFetch([id]);}+}- createEffect(() => {- const queue = displayNameFetchQueue();- if (queue.length > 0) {- processFetchQueue();- }- });+function getUserNameItem(id: MacroId): UserNameItem {+ ensureUserNameItem(id);+ return unwrap(userDisplayNames[id]);+}++/** Resolves a display name from the shared reactive cache. */+export function getDisplayName(+ id: MacroId | undefined | null,+ options?: DisplayNameOptions+): string {+ if (!id) return '';+ return defaultNameTransform(getUserNameItem(id), options);+}++/** Shared hook that handles caching/fetching and returns the underlying UserNameItem */+function useUserNameItem(id: MacroId) {+ ensureUserNameItem(id);const getItem = () => unwrap(userDisplayNames[id]);diff --git a/apps/web/src/lib/core/user/util.ts b/apps/web/src/lib/core/user/util.tsindex 7e96507d14..95fe9534ab 100644--- a/apps/web/src/lib/core/user/util.ts+++ b/apps/web/src/lib/core/user/util.ts@@ -1,4 +1,4 @@-import { useDisplayName } from './displayName';+import { getDisplayName } from './displayName';import { tryMacroId } from './macroId';import type { IUser } from './types';@@ -20,11 +20,9 @@ export function emailToId(email: string): string {}export function idToDisplayName(id: string): string {- const macroId = tryMacroId(id);- const [displayName] = useDisplayName(macroId, {+ return getDisplayName(tryMacroId(id), {emailFallback: 'local-part',});- return displayName();}export function channelParticipantInfo(participant: {