website icon indicating copy to clipboard operation
website copied to clipboard

Documentation Navigation preferences bug

Open jmcapra opened this issue 5 months ago • 0 comments

Possibly related PR - https://github.com/payloadcms/website/pull/439

If you navigate directly to a page (e.g. via URL or external navigation), the current nav group is highlighted, but not expanded. The expanded state is determined by the last page you clicked on or navigated to via the nav itself, however arriving at a page through other means results in this buggy state.

image

The issue seems to be related to the "openTopicPreferences" state in the DocsNavigation component. Claude Code suggested this fix, however it seems it might defeat the entire purpose of the "preferences" idea. Personally, I'd prefer an accurate nav bar over one that remember what I clicked on at 3am this morning.

// src/components/DocsNavigation/index.tsx:56
useEffect(() => {
    const preference = window.localStorage.getItem(openTopicsLocalStorageKey)
    if (preference) {
      const parsedPreference = JSON.parse(preference)
      // Ensure the current topic is always included in the open topics
      if (!parsedPreference.includes(currentTopic)) {
        const updatedPreference = [...parsedPreference, currentTopic]
        setOpenTopicPreferences(updatedPreference)
        window.localStorage.setItem(openTopicsLocalStorageKey, JSON.stringify(updatedPreference))
      } else {
        setOpenTopicPreferences(parsedPreference)
      }
    } else {
      setOpenTopicPreferences([currentTopic])
    }
  }, [currentTopic])

jmcapra avatar Aug 24 '25 07:08 jmcapra