github →

New request

#21166: Bug: Home redirect always lands on first object alphabetically, ignores last-visited

We'll provision a sandbox, run an agent against the issue, and open a draft PR. You can pull the branch and iterate from there.

Issue
sonarly:mediumtype: bug

Description

Going to the workspace root (/) always redirects me to the same object: the first one alphabetically by nameSingular. It doesn't matter which object I visited last, and clearing browser cache/localStorage makes no difference. In my workspace a custom object called "Activities" (nameSingular: "activity") always wins because "a" sorts first.

Steps to reproduce

  1. Have multiple objects, with one that sorts first alphabetically by nameSingular.
  2. Visit a different object's index page, e.g. Companies.
  3. Go to the workspace root /.
  4. Expected: redirect to the last-visited object (Companies). Actual: redirect to the alphabetically-first object.

Root cause

useDefaultHomePagePath uses lastVisitedObjectMetadataItem if it's set, otherwise it falls back to the first of readableNonSystemObjectMetadataItems, which is sorted with a.nameSingular.localeCompare(b.nameSingular). The last-visited branch never fires, for two reasons.

First, lastVisitedObjectMetadataItemIdState is created via createAtomState({ useLocalStorage: true }), which calls atomWithStorage(key, default, undefined, undefined), so getOnInit is unset and defaults to false in jotai 2.x. The atom is only ever accessed imperatively through store.get/store.set and is never subscribed via a hook, so it never mounts or hydrates. On a fresh load store.get(...) returns the default null and the code falls through to the alphabetical fallback. Note that the useSessionStorage and useCookieStorage branches in the same factory do pass { getOnInit: true }, only the useLocalStorage branch doesn't.

Second, defaultHomePagePath is a useMemo that reads the atom imperatively and doesn't list it as a dependency, so it isn't reactive to in-session updates either.

Suggested fix

Pass { getOnInit: true } for the useLocalStorage branch in createAtomState, or for this atom specifically, so store.get returns the persisted value. Optionally have useDefaultHomePagePath subscribe to the atom (e.g. useAtomValue) and add it to the memo deps so it stays reactive. Worth adding a regression test that sets a last-visited id and asserts the redirect resolves to that object, since the current tests only cover the fallback.

Environment

  • Twenty main @ 6b5a956 (2026-06-02)
  • jotai ^2.17.1
Assessmentadvisory
bug easy95% confidence

Known hydration failure in a jotai atom used for last-visited object tracking causes the alphabetical fallback to always win.

Likely files
  • packages/twenty-front/src/modules/navigation/hooks/useDefaultHomePagePath.ts
  • packages/twenty-front/src/modules/object-metadata/states/lastVisitedObjectMetadataItemIdState.ts
  • packages/twenty-front/src/modules/ui/utilities/state/utils/createAtomState.ts
Create the request

This opens a fresh agent run and a draft PR for issue #21166.

Cancel