Skip to content
Source
Sign inSign up
pingdotgg/t3code

perf(web): typing no longer re-renders the composer's footer controls #32323

MergedOmarAlex24(GitHub profile, opens in a new tab)merged 3 commits intomain fromrefs/pull/32323/headmerged by juliusmarminge View on GitHub

Showing 2 changed files with 5 additions and 1 deletion.

x
0 of 2 viewed, 2 left
3 additions and 1 deletionapps/web/src/components/chat/ChatComposer.tsxModified
View file
@@ -910,13 +910,15 @@
? providerInstanceEntries.find((entry) => hasProviderSetup(entry.snapshot))?.instanceId
: undefined))
: undefined;
+ // Called before the derivation below: a hook between it and its uses stops React Compiler
+ // from caching the mode options, and the footer then re-renders on every keystroke.
+ const managedPolicy = useManagedPolicy(environmentId);
const { modes: compatibleRuntimeModes, mode: compatibleRuntimeMode } =
resolveCompatibleRuntimeMode(
runtimeMode,
selectedProviderEntry?.snapshot.supportedRuntimeModes,
// Modes above an administrator's ceiling stay listed, disabled with the reason.
- const managedPolicy = useManagedPolicy(environmentId);
const compatibleRuntimeModeOptions = resolveRuntimeModeOptions(
compatibleRuntimeModes,
managedPolicy,
2 additions and 0 deletionsapps/web/test/appScenarios.renders.tsxModified
View file
@@ -274,6 +274,8 @@
await userEvent.type(editor, TYPED_TEXT);
await expect.element(editor).toHaveTextContent(TYPED_TEXT);
});
+ // The footer controls re-render for the first character only, not per keystroke.
+ expect(counted.components.ComposerControlsBar).toBe(1);
await report("app-type-in-composer", [counted]);
});
​