@devries-cameron20 / t3code-1 / commits / d4314e8e16
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

refactor(web): the composer builds model options without a "use memo" hook (#20780)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Julius Marminge committed Oct 16, 2026 at 23:24 UTC d4314e8e1627e2ea46ddea20de9e9deda40b1dcc
1 file changed +21 -31
apps/web/src/components/chat/ChatComposer.tsx
+21 -31
@@ -1777,7 +1777,9 @@ function useComposerProviderSelection(
1777 readonly activeProjectId: ProjectId | null;
1778 },
1779 ) {
1780 - // Calls no hooks, so the compiler needs the directive to memoize it.
1780 + // Kept: `providerInstanceEntries` is read by plain functions on both sides of
1781 + // `useEffectiveComposerModelState` and `useProviderWorkspaceSnapshotRefresh` (the
1782 + // `hasProviderSetup` lookup before, the model picker's `.find` after), so inline it loses its cache.
1783 "use memo";
1784 const { providerStatuses, settings, activeProjectId, ...selection } = input;
1785 const providerInstanceEntries: ReadonlyArray<ProviderInstanceEntry> = sortProviderInstanceEntries(
@@ -1793,28 +1795,6 @@ function useComposerProviderSelection(
1795 };
1796 }
1797
1796 -function useModelOptionsByInstance(
1797 - settings: UnifiedSettings,
1798 - entries: ReadonlyArray<ProviderInstanceEntry>,
1799 - selectedInstanceId: ProviderInstanceId,
1800 - selectedModel: string | null,
1801 -): ReadonlyMap<ProviderInstanceId, ReadonlyArray<AppModelOption>> {
1802 - // Calls no hooks, so the compiler needs the directive to memoize it.
1803 - "use memo";
1804 - const out = new Map<ProviderInstanceId, ReadonlyArray<AppModelOption>>();
1805 - for (const entry of entries) {
1806 - out.set(
1807 - entry.instanceId,
1808 - getAppModelOptionsForInstance(
1809 - settings,
1810 - entry,
1811 - entry.instanceId === selectedInstanceId ? selectedModel : null,
1812 - ),
1813 - );
1814 - }
1815 - return out;
1816 -}
1817 -
1798 /** Splits the draft's images into pending SnapShots and standalone images. */
1799 function useComposerImageGroups(
1800 pendingSnapShotAnimations: ReturnType<typeof getPendingSnapShotAnimations>,
@@ -1822,7 +1802,9 @@ function useComposerImageGroups(
1802 composerImages: ReadonlyArray<ComposerImageAttachment>,
1803 composerPreviewAnnotations: ReadonlyArray<{ readonly id: string }>,
1804 ) {
1825 - // Calls no hooks, so the compiler needs the directive to memoize it.
1805 + // Kept: these arrays go through plain functions here and again ~2,700 lines later
1806 + // (`.some`, `.filter`, `.slice` in the resting layout), past dozens of hook calls. Inline, the
1807 + // compiler gives them no cache scope, and moving every later use above those hooks is not possible.
1808 "use memo";
1809 const pendingSnapShotIds = pendingSnapShotAnimationIdsForTarget(
1810 pendingSnapShotAnimations,
@@ -1845,7 +1827,9 @@ const NO_PROVIDER_SKILLS: ServerProvider["skills"] = [];
1827 const NO_PROVIDER_SLASH_COMMANDS: ServerProvider["slashCommands"] = [];
1828
1829 function useComposerProviderState(input: Parameters<typeof getComposerProviderState>[0]) {
1848 - // Calls no hooks, so the compiler needs the directive to memoize it.
1830 + // Kept: inline, `composerProviderState`, `selectedModelSelection` and `providerInputInputs` lose
1831 + // their cache scope. The inputs come from `useEffectiveComposerModelState`, and the results are
1832 + // read past later hooks such as `useProviderWorkspaceSnapshotRefresh`.
1833 "use memo";
1834 return getComposerProviderState(input);
1835 }
@@ -2345,12 +2329,18 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
2329 selectedModelOptionsForDispatch,
2330 );
2331 const selectedModelForPicker = selectedModel;
2348 - const modelOptionsByInstance = useModelOptionsByInstance(
2349 - settings,
2350 - providerInstanceEntries,
2351 - selectedInstanceId,
2352 - selectedModelForPicker,
2353 - );
2332 + const modelOptionsByInstance = new Map<ProviderInstanceId, ReadonlyArray<AppModelOption>>();
2333 + for (const entry of providerInstanceEntries) {
2334 + modelOptionsByInstance.set(
2335 + entry.instanceId,
2336 + getAppModelOptionsForInstance(
2337 + settings,
2338 + entry,
2339 + entry.instanceId === selectedInstanceId ? selectedModelForPicker : null,
2340 + ),
2341 + );
2342 + }
2343 +
2344 const selectedModelForPickerWithCustomFallback = (() => {
2345 const currentOptions = modelOptionsByInstance.get(selectedInstanceId) ?? [];
2346 return currentOptions.some((option) => option.slug === selectedModelForPicker)