Skip to content

Start Session form keeps walkthrough values after the session ends instead of resetting to defaults #1650

Open

Description

@joshunrau

The Start Session page resets its form values to the defaults in an effect that fires when a session ends. That reset never reaches the form if the page was mounted with navigation state (location.state.initialValues) while a session was active. When the session then ends, the form comes back pre-filled with the navigation-state values instead of the defaults. The only producer of that state is the walkthrough (START_SESSION_DATA: subject ID 123, custom ID, in-person). Its history entry keeps the state, so one way to hit this is to go Back in the browser to that entry while a real session is running, then end the session. The user then sees a start-session form pre-filled with the walkthrough's demo subject.

Where

apps/web/src/routes/_app/session/start-session.tsx:27-41,50-61

const [initialValues, setInitialValues] = useState(location.state?.initialValues ?? defaultInitialValues);

useEffect(() => {
  if (currentSession === null) {
    setInitialValues(defaultInitialValues);
  }
}, [currentSession]);
...
{currentSession === null && <StartSessionForm initialValues={initialValues} ... />}

When the page mounts during an active session, initialValues holds the navigation-state values and the form is not rendered. When currentSession becomes null, StartSessionForm mounts in that same render with the stale values. The effect sets the defaults only after the mount. libui's Form reads initialValues once, on mount (useState(...) in @douglasneuroinformatics/libui src/components/Form/Form.tsx:90), and StartSessionForm has no key, so the later prop change is ignored. Ending a session from the sidebar or navbar navigates to /session/start-session, which keeps an already-mounted page mounted, so the stale state survives.

Reproduce

  1. Run the walkthrough past the "Start Session" step, which pushes a history entry for /session/start-session carrying initialValues: START_SESSION_DATA (apps/web/src/providers/WalkthroughProvider.tsx:211-216), then close it.
  2. Start a real session.
  3. Use the browser's Back button to return to that history entry (the page mounts with the walkthrough state while the session is active).
  4. End the session from the sidebar.

Actual: the Start Session form shows subject ID 123 and the walkthrough's other values.
Expected: the form shows the defaults (sessionType: 'IN_PERSON', the group's default identification method, no subject ID).

Tests

apps/web/src/__tests__/start-session-route.test.tsx, test should mount the form with the defaults once the session ends, not the values the walkthrough supplied (line 194), currently it.fails with a "Known defect" comment. When fixing, change it to a plain it and remove the comment. The test mounts with walkthrough state and an active session, ends the session, and checks the initialValues of the first StartSessionForm render afterwards.

Suggested fix

Reset initialValues while the form is unmounted, that is, when currentSession is non-null rather than when it becomes null, so the next mount reads the defaults. Alternatively, give StartSessionForm a key that changes with the reset.

Found while raising unit test coverage in #1632.

Activity

  1. added
    BugType: existing behavior is wrong
    Priority: LowNice to have, cosmetic or speculative
    Difficulty: LowIsolated change, about 2 hours or less
    Area: Webapps/web (clinician-facing React SPA)
    on Oct 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area: Webapps/web (clinician-facing React SPA)BugType: existing behavior is wrongDifficulty: LowIsolated change, about 2 hours or lessPriority: LowNice to have, cosmetic or speculative

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions