The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 23, 05:30 UTC
refactor(web): the changed files tree keeps its caching without "use memo" hooks (#20766)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Oct 16, 2026 at 23:21 UTC
36cde6fbc3575abe0ada67da2ff2f4fd8a44b11e
1 file changed
+9
-16
apps/web/src/components/chat/ChangedFilesTree.tsx
+9
-16
@@ -122,14 +122,6 @@ export const ChangedFilesCard = memo(function ChangedFilesCard(props: {
122
);
123
});
124
125
-// Building the tree walks every file, and the compiler would redo it each render
126
-// because the expansion state hook runs after it.
127
-function useTurnDiffTree(files: ReadonlyArray<TurnDiffFileChange>) {
128
- "use memo";
129
- const treeNodes = buildTurnDiffTree(files);
130
- return { treeNodes, directoryPathsKey: collectDirectoryPaths(treeNodes).join("\u0000") };
131
-}
132
-
125
export const ChangedFilesTree = memo(function ChangedFilesTree(props: {
126
runId: RunId;
127
files: ReadonlyArray<TurnDiffFileChange>;
@@ -140,16 +132,17 @@ export const ChangedFilesTree = memo(function ChangedFilesTree(props: {
132
}) {
133
const { files, allDirectoriesExpanded, onOpenTurnDiff, resolvedTheme, runId, onFileContextMenu } =
134
props;
143
- const { treeNodes, directoryPathsKey } = useTurnDiffTree(files);
144
- const hasDirectoryNodes = directoryPathsKey.length > 0;
145
- const expansionStateKey = `${allDirectoriesExpanded ? "expanded" : "collapsed"}\u0000${directoryPathsKey}`;
135
+ // Overrides apply only while their key matches the current one, so starting from no key is
136
+ // the same as starting with no overrides. That lets this hook run before the tree is built,
137
+ // and the compiler caches the tree on `files`.
138
const [directoryExpansionState, setDirectoryExpansionState] = useState<{
147
- key: string;
139
+ key: string | null;
140
overrides: Record<string, boolean>;
149
- }>(() => ({
150
- key: expansionStateKey,
151
- overrides: {},
152
- }));
141
+ }>({ key: null, overrides: {} });
142
+ const treeNodes = buildTurnDiffTree(files);
143
+ const directoryPathsKey = collectDirectoryPaths(treeNodes).join("\u0000");
144
+ const hasDirectoryNodes = directoryPathsKey.length > 0;
145
+ const expansionStateKey = `${allDirectoriesExpanded ? "expanded" : "collapsed"}\u0000${directoryPathsKey}`;
146
const expandedDirectories =
147
directoryExpansionState.key === expansionStateKey
148
? directoryExpansionState.overrides