Skip to content

Commit e6085c1

Browse files
committed
Refactor cache management in Content component
- Replace local reference for previous content ID with a React ref to improve cache clearing logic. - Ensure cache is cleared immediately when content ID changes, maintaining accurate version data.
1 parent 34bd882 commit e6085c1

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

xp-archive/client/content/Content.tsx

+5-5
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ export const Content = () => {
3030
const { selectedContentId, selectedLocale, selectedVersion, setSelectedVersion } =
3131
useAppState();
3232

33+
const prevContentIdRef = React.useRef(selectedContentId);
34+
3335
useEffect(() => {
3436
const pathSegments = window.location.pathname.split('/');
3537
if (pathSegments.length >= 5) {
@@ -76,13 +78,11 @@ export const Content = () => {
7678
// Update this effect to clear the cache immediately when content ID changes
7779
useEffect(() => {
7880
// Clear the cache for the previous content ID when it changes
79-
const prevContentId = React.useRef(selectedContentId);
80-
81-
if (prevContentId.current && prevContentId.current !== selectedContentId) {
82-
clearCachedVersionSelector(prevContentId.current);
81+
if (prevContentIdRef.current && prevContentIdRef.current !== selectedContentId) {
82+
clearCachedVersionSelector(prevContentIdRef.current);
8383
}
8484

85-
prevContentId.current = selectedContentId;
85+
prevContentIdRef.current = selectedContentId;
8686

8787
// Also reset the local cache state when content ID changes
8888
if (data?.versions && selectedContentId) {

0 commit comments

Comments
 (0)