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

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

perf(web): scoped model availability compiles without manual memoization (#20666)

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

Julius Marminge committed Oct 16, 2026 at 21:55 UTC aca2b2ab4e82afcf99482fdd09cf502112829842
1 file changed +27 -31
apps/web/src/components/settings/useScopedModelAvailability.ts
+27 -31
@@ -1,5 +1,4 @@
1 import type { ProviderInstanceId, UnifiedSettings } from "@t3tools/contracts";
2 -import { useCallback } from "react";
2
3 import { mergeEnvironmentSettings } from "../../hooks/useSettings";
4 import { getCustomModelOptionsByInstance } from "../../modelSelection";
@@ -17,35 +16,32 @@ export function useScopedModelDisabledReason(
16 ) {
17 const { targets } = useSettingsScope();
18 const { environments } = useEnvironments();
20 - return useCallback(
21 - (instanceId: ProviderInstanceId, model: string): string | null => {
22 - const sourceEntry = entries.find((entry) => entry.instanceId === instanceId);
23 - for (const candidate of targets) {
24 - const environment = environments.find(
25 - (entry) => entry.environmentId === candidate.environmentId,
26 - );
27 - const config = environment?.serverConfig;
28 - if (!config) continue;
29 - const entry = applyProviderInstanceSettings(
30 - deriveProviderInstanceEntries(config.providers),
31 - candidate.settings,
32 - candidate.projectId,
33 - ).find((option) => option.instanceId === instanceId);
34 - const options = getCustomModelOptionsByInstance(
35 - mergeEnvironmentSettings(candidate.settings, settings),
36 - config.providers,
37 - ).get(instanceId);
38 - if (
39 - !entry?.enabled ||
40 - !entry.isAvailable ||
41 - entry.driverKind !== sourceEntry?.driverKind ||
42 - !options?.some((option) => option.slug === model && !option.isUnavailable)
43 - ) {
44 - return `This model is unavailable on ${environment?.label ?? "a selected environment"}. Select that environment to choose its model separately.`;
45 - }
19 + return (instanceId: ProviderInstanceId, model: string): string | null => {
20 + const sourceEntry = entries.find((entry) => entry.instanceId === instanceId);
21 + for (const candidate of targets) {
22 + const environment = environments.find(
23 + (entry) => entry.environmentId === candidate.environmentId,
24 + );
25 + const config = environment?.serverConfig;
26 + if (!config) continue;
27 + const entry = applyProviderInstanceSettings(
28 + deriveProviderInstanceEntries(config.providers),
29 + candidate.settings,
30 + candidate.projectId,
31 + ).find((option) => option.instanceId === instanceId);
32 + const options = getCustomModelOptionsByInstance(
33 + mergeEnvironmentSettings(candidate.settings, settings),
34 + config.providers,
35 + ).get(instanceId);
36 + if (
37 + !entry?.enabled ||
38 + !entry.isAvailable ||
39 + entry.driverKind !== sourceEntry?.driverKind ||
40 + !options?.some((option) => option.slug === model && !option.isUnavailable)
41 + ) {
42 + return `This model is unavailable on ${environment?.label ?? "a selected environment"}. Select that environment to choose its model separately.`;
43 }
47 - return null;
48 - },
49 - [entries, environments, settings, targets],
50 - );
44 + }
45 + return null;
46 + };
47 }