Replace Reflux SessionStore and CurrentUserStore - #27552
Open
dennisoelkers wants to merge 15 commits into
Open
dennisoelkers wants to merge 15 commits into
dennisoelkers wants to merge 15 commits into
Conversation
Introduces a minimal external store, a `useExternalStore` hook, the `Session` state module and `SessionApi` (login/logout/validate) as replacement for the Reflux `SessionStore`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Removes the lazy `require` of `SessionStore`. Requests queued until login now wait on `Session.waitForLogin()`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`CurrentUser` follows the session and only reloads when the username changes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`validate()` uses the `SystemSessions` API stub. `LoginPage` ignores the result after unmount instead of calling the no-op `cancel()`. The `CurrentUser` test mocks `Users.get` with a typed mock function. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- A 401 triggers a real server-side logout again; concurrent logouts share one request. - `Session.endSession()` fires 'logout' only once and only when logged in. - `CurrentUser` retries after a failed load and `reload()` works before the first load succeeded. - `login` uses the `SystemSessions` stub; unused session state and routes are removed. - `useExternalStore` applies the selector outside of the snapshot. - Logged-in pages use `useCurrentUser()`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…store' into refactor/replace-reflux-session-store
- `FetchProvider` only depends on `Session`; `SessionApi` registers the server-side logout. This fixes the preflight build, which can't resolve `@graylog/server-api`. - Logouts are deduplicated in the `Session` singleton; a failed logout rejects and is reported by `useLogout`. - `createExternalStore` only notifies on actual changes; `CurrentUser` skips deep-equal reloads, ignores outdated responses and retries a failed initial load. - `LoginPage` shows the login form when session validation fails. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…store' into refactor/replace-reflux-session-store
- Drop retrying the current user load and reporting failed logouts; a page refresh recovers from both. - `AppFacade` starts session validation right away and `LoginPage` reuses the pending request. - Restore spies after tests and disable pre-existing lint errors in `LoginPage`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Note: Needs to be merged together with Graylog2/graylog-plugin-enterprise#15810, which migrates the enterprise usages of the removed stores.
Description
Replaces the Reflux
SessionStore/SessionActionsandCurrentUserStorewith framework-free modules:logic/createExternalStore.ts+hooks/useExternalStore.ts: minimal state container, read from React viauseSyncExternalStore.logic/session/Session.ts: session state,waitForLogin()andlogout/validatedevents.logic/session/SessionApi.ts:login,logout,validate.logic/users/CurrentUser.ts: current user state following the session, withget()/reload()./prd Graylog2/graylog-plugin-enterprise#15810
Motivation and Context
FetchProviderneeds the session outside of React (isLoggedIn(), queuing requests until login, handling 401s). With Reflux this required a lazyrequireto work around an import cycle, and the queued-login listener leaked (see #27542). The session module has no REST dependencies, soFetchProviderimports it directly andwaitForLogin()can't leak listeners.This deliberately deviates from the state management options in
CONTRIBUTING.md(useState/useContext/Redux, react-query for replacing Reflux stores). The session and current user are needed outside of React:FetchProviderchecks the session for every request, andCurrentUser.reload()is called from non-React API modules.QueryClients are created inside providers and Redux stores are created per view, so neither is reachable from there.createExternalStoreis kept minimal and React reads it viauseSyncExternalStore.Behavior differences:
CurrentUseronly reloads when the username changes.CurrentUserStorerefetched on everySessionStoreupdate, includingvalidatingSessiontoggles. Responses for a previous user are ignored.logoutevent fires only once per logout and only if the user was logged in.How Has This Been Tested?
Added unit tests for
SessionApiandCurrentUser, plus aFetchProvidertest for requests queued until login.yarn tsgois clean, and tests for all touched areas pass.Screenshots (if appropriate):
Types of changes
Checklist:
🤖 Generated with Claude Code
/nocl Internal refactoring of frontend session state.