fix(sidebar): keep room list visible when category mutations fire from an enclave page #134

Merged
nrupard merged 1 commit from fix/sidebar-categories-respect-current-enclave into main 2026-05-18 17:54:38 +02:00
Owner

Bug

After LC-79 merged, creating a category, toggling collapsed, assigning a room, or reordering anything from /enclave/{id} or /room/{id} wiped the "All rooms" section (and any expanded category's room list) from the returned sidebar swap. Refreshing the page brought the rooms back.

Root cause

render_sidebar_fragment in routes/sidebar_categories.rs always called super::load_sidebar(state, user, None). None means "Home view" to load_sidebar, which returns an empty sidebar_rooms (Home shows DMs only). Every category mutation therefore re-rendered the sidebar as if the user had clicked Home, hiding their current enclave's rooms.

Fix

Read HX-Current-URL (or Referer as fallback) and parse the path:

  • /enclave/{id} -> use the id.
  • /room/{id} -> resolve the room's enclave via the existing enclave_for_room helper.
  • Anything else -> None (Home shape preserved on purpose).

Threaded through every handler in the module via an extra headers: HeaderMap extractor. render_sidebar_fragment now takes the header map and calls current_enclave_from_headers to derive context.

Test plan

  • New regression test create_category_preserves_room_list_when_viewing_enclave posts to /sidebar/categories with HX-Current-URL: http://localhost:8080/enclave/1 and asserts the rebuilt fragment still contains /room/1" (the seeded General room link).
  • just check (fmt + clippy across standalone + saas).
  • ./dev/cargo test -p lets-chat-server --test routes_sidebar_categories - 11 tests pass (10 existing + 1 new).
  • Manual: while viewing an enclave, click + Add to create a category - verify the room list stays put.
## Bug After LC-79 merged, creating a category, toggling collapsed, assigning a room, or reordering anything from `/enclave/{id}` or `/room/{id}` wiped the "All rooms" section (and any expanded category's room list) from the returned sidebar swap. Refreshing the page brought the rooms back. ## Root cause `render_sidebar_fragment` in `routes/sidebar_categories.rs` always called `super::load_sidebar(state, user, None)`. `None` means "Home view" to `load_sidebar`, which returns an empty `sidebar_rooms` (Home shows DMs only). Every category mutation therefore re-rendered the sidebar as if the user had clicked Home, hiding their current enclave's rooms. ## Fix Read `HX-Current-URL` (or `Referer` as fallback) and parse the path: - `/enclave/{id}` -> use the id. - `/room/{id}` -> resolve the room's enclave via the existing `enclave_for_room` helper. - Anything else -> `None` (Home shape preserved on purpose). Threaded through every handler in the module via an extra `headers: HeaderMap` extractor. `render_sidebar_fragment` now takes the header map and calls `current_enclave_from_headers` to derive context. ## Test plan - [x] New regression test `create_category_preserves_room_list_when_viewing_enclave` posts to `/sidebar/categories` with `HX-Current-URL: http://localhost:8080/enclave/1` and asserts the rebuilt fragment still contains `/room/1"` (the seeded General room link). - [x] `just check` (fmt + clippy across standalone + saas). - [x] `./dev/cargo test -p lets-chat-server --test routes_sidebar_categories` - 11 tests pass (10 existing + 1 new). - [ ] Manual: while viewing an enclave, click `+ Add` to create a category - verify the room list stays put.
fix(sidebar): derive current enclave from HX-Current-URL on category mutations
Some checks failed
Check / clippy + fmt + tests (pull_request) Failing after 9s
92bbb91285
The five sidebar-category endpoints all rebuild the sidebar fragment via `render_sidebar_fragment(state, user, None)`, where `None` means "Home view" to `load_sidebar`. The Home view's sidebar shows only DMs - rooms are empty - so the swap response that came back from creating a category, toggling collapsed, assigning a room, or reordering wiped the "All rooms" section and any open category's room list whenever the user was actually on `/enclave/{id}` or `/room/{id}`.

Reads HTMX's `HX-Current-URL` header (falling back to `Referer` for non-HTMX callers) and parses the path: `/enclave/{id}` -> the id; `/room/{id}` -> the room's enclave via the existing `enclave_for_room` helper; anything else -> `None` and the Home shape is preserved on purpose. Missing / malformed URLs drop to `None` silently rather than erroring.

Threaded through every handler in the module via an additional `headers: HeaderMap` extractor; `render_sidebar_fragment` now takes the header map and calls `current_enclave_from_headers` to derive context. New regression test `create_category_preserves_room_list_when_viewing_enclave` posts to /sidebar/categories with `HX-Current-URL: .../enclave/1` and asserts the rebuilt fragment still contains the seeded General room link.
nrupard deleted branch fix/sidebar-categories-respect-current-enclave 2026-05-18 17:54:38 +02:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
psa-systems/lets-chat!134
No description provided.