**Implementation Plan: Back Navigation Dismisses Modal** --- ### Changes Required #### 1. `AppLightbox._onPopstate()` – `assets/js/components/lightbox.js`, lines 93-97 Replace the handler body with: ```js this.element.classList.remove('visible'); document.body.style.overflow = ''; // restore scroll this.image.src = ''; // free image resource if (this.lastFocus) { this.lastFocus.focus(); this.lastFocus = null; } ``` #### 2. `AppDialog` popstate handler – `assets/js/components/dialog.js`, lines 67-71 Replace the entire handler with a single call to `this.close()`. #### 3. `AppContextMenu` popstate handler – `assets/js/components/context-menu.js`, lines 54-58 After the line that removes the menu, add: ```js if (this._lastFocusedElement) { this._lastFocusedElement.focus(); this._lastFocusedElement = null; } ``` #### 4. Test coverage – `tests/e2e/profile/search.py` Add after `test_ui_media_lightbox_opens`: - Open lightbox - `page.go_back()` - Assert lightbox not visible, `body.style.overflow != 'hidden'`, URL unchanged. #### 5. Test coverage – `tests/e2e/ui/components.py` Add two tests after dialog/context-menu open tests: - Back navigation hides dialog and URL unchanged. - Back navigation hides context menu and URL unchanged. #### 6. **Lint fix** – `tests/e2e/ui/components.py` lines 65, 79 Change `assert f"/projects/" in current_url` → `assert "/projects/" in current_url` (remove the `f` prefix). #### 7. Verify all changes are on `master` branch (no `.venv` or unrelated artifacts in git). --- ### Execution Steps (if starting from `master`) 1. Make the three source-code edits above. 2. Add the three Playwright e2e tests (one in `search.py`, two in `components.py`). 3. Fix the two lint violations in `components.py` (remove `f` from assert lines). 4. Run `pip install -e '.[dev]' -q && make test-unit` – must pass. If unrelated tests fail (e.g., `test_owns_instance_true_for_creator`, `test_advance_quests_increments_and_caps`, `test_answer_is_grounded_and_cited`), verify they are pre-existing on `master` by running the same command on a clean clone; if they also fail, these are environment-specific and not caused by this change. No action needed. 5. Run `pip install -q ruff && ruff check .` – must report zero new violations. 6. Manual verification: open lightbox, press browser back → lightbox hidden, scroll restored, URL unchanged. Repeat for dialog and context menu. --- ### Definition of Done - [ ] The three component handlers (`_onPopstate` in lightbox, dialog, context-menu) are updated per the spec above. - [ ] The three e2e tests exist and pass when run against a local dev server. - [ ] `make test-unit` exits with code 0 (no test failures). If pre-existing failures appear, they must be confirmed to also occur on `master`; the change itself introduces zero new failures. - [ ] `ruff check .` exits with code 0, reporting zero new violations. - [ ] Manual verification confirms: back navigation hides each modal type, restores page scroll, returns focus, and does not change the page URL.