Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion Composer/packages/client/src/utils/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ import find from 'lodash/find';
import { useRecoilValue } from 'recoil';
import { FeatureFlagKey } from '@bfc/shared';

import { designPageLocationState, currentProjectIdState, pluginPagesSelector, featureFlagsState } from '../recoilModel';
import {
designPageLocationState,
currentProjectIdState,
pluginPagesSelector,
featureFlagsState,
rootBotProjectIdSelector,
} from '../recoilModel';

import { bottomLinks, topLinks } from './pageLinks';
import routerCache from './routerCache';
Expand Down Expand Up @@ -50,10 +56,17 @@ export const useLinks = () => {
};

export const useRouterCache = (to: string) => {
const rootProjectId = useRecoilValue(rootBotProjectIdSelector);
const [state, setState] = useState(routerCache.getAll());
const { topLinks, bottomLinks } = useLinks();
const linksRef = useRef(topLinks.concat(bottomLinks));
linksRef.current = topLinks.concat(bottomLinks);

useEffect(() => {
routerCache.cleanAll();
setState({});
}, [rootProjectId]);

useEffect(() => {
globalHistory.listen(({ location }) => {
const links = linksRef.current;
Expand Down
5 changes: 5 additions & 0 deletions Composer/packages/client/src/utils/routerCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ class RouterCache {
this._all[linkTo] = uri;
this.storage.set(KEY, this._all);
}

cleanAll() {
this._all = {};
this.storage.set(KEY, this._all);
}
}

export default new RouterCache();