Skip to content

Commit ba86b3b

Browse files
committed
Enhance cache management in Content component
- Preserve the isOpen state when resetting the local cache on content ID changes. - Introduce a separate effect to handle data loading without affecting the panel state, ensuring accurate version data is maintained.
1 parent e6085c1 commit ba86b3b

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

xp-archive/client/content/Content.tsx

+14-4
Original file line numberDiff line numberDiff line change
@@ -84,16 +84,26 @@ export const Content = () => {
8484

8585
prevContentIdRef.current = selectedContentId;
8686

87-
// Also reset the local cache state when content ID changes
87+
// Also reset the local cache state when content ID changes, but preserve isOpen state
8888
if (data?.versions && selectedContentId) {
89-
setVersionSelectorCache({
89+
setVersionSelectorCache((prev) => ({
9090
component: null,
9191
versions: data.versions,
92-
isOpen: false,
93-
});
92+
isOpen: prev.isOpen, // Preserve the open state
93+
}));
9494
}
9595
}, [selectedContentId, data?.versions]);
9696

97+
// Add a separate effect to handle data loading without affecting panel state
98+
useEffect(() => {
99+
if (data?.versions && selectedContentId) {
100+
setVersionSelectorCache((prev) => ({
101+
...prev,
102+
versions: data.versions,
103+
}));
104+
}
105+
}, [data?.versions, selectedContentId]);
106+
97107
useEffect(() => {
98108
setSelectedView(getDefaultView(isWebpage, hasAttachment));
99109
}, [isWebpage, hasAttachment, selectedContentId]);

0 commit comments

Comments
 (0)