Skip to content
Open
Changes from 1 commit
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
5 changes: 4 additions & 1 deletion src/components/MarketSwitcher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,6 @@ export const MarketSwitcher = ({ hideDescription }: MarketSwitcherProps) => {
const [hovered, setHovered] = useState(false);
const [focused, setFocused] = useState(false);
const [searchQuery, setSearchQuery] = useState('');
const [showLegacy, setShowLegacy] = useState(false);
const searchRef = useRef<HTMLInputElement>(null);
const triggerRowRef = useRef<HTMLDivElement>(null);

Expand All @@ -307,6 +306,10 @@ export const MarketSwitcher = ({ hideDescription }: MarketSwitcherProps) => {
const toggleFavoriteMarket = useRootStore((store) => store.toggleFavoriteMarket);
const favoriteMarkets = useRootStore((store) => store.favoriteMarkets);

// A legacy market the user is actually on must not be missing from the list: the legacy

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Accepted — good catch, and the case is stronger than described.

setQueryParameter uses Router.push(..., { shallow: true }), so a market change never remounts the header. On top of that, src/store/root.ts hydrates currentMarket from ?marketName/localStorage inside document.onreadystatechange, i.e. after the store initialises to availableMarkets[0] (Core, non-legacy). If the switcher mounts before that fires, the initialiser latches false on exactly the deep-link path #3128 is about. My manual check only passed because hydration won that race locally.

Applied your suggestion. The effect only ever sets true and only on a currentMarket change, so a deliberate toggle-off is still respected while the user stays on that market; the lazy initialiser is kept so there's no flash when the market is already known at mount.

One behaviour worth flagging: because the effect never sets false, once a legacy market has been visited the section stays expanded for the rest of that mount, even after switching to a non-legacy market (a fresh page load still starts collapsed). I verified all three paths locally. Mirroring both ways would override a user's deliberate "on" toggle whenever they moved to a non-legacy market, which seemed worse — happy to change it if you'd prefer the stricter behaviour.

// group is only rendered while this is on, so default it from the market being viewed.
const [showLegacy, setShowLegacy] = useState(() => getMarketCategory(currentMarket) === 'legacy');

const handleOpen = () => {
setOpen(true);
};
Expand Down