fix: keep /web problem statements clear of the problem switcher

Merged
BO
11d ago
+26-2

What does this PR aim to accomplish?:

Closes #1072 — on the new /web contest problem pages, the fixed problem switcher covers the left edge of the problem statement.

How does this PR accomplish the above?:

On the legacy pages the content sat in a centred container, leaving room on the left for the switcher. In the /web app, the problem view's .jumbotron spans the full width (live DOM: #app > div > .jumbotron > .xmoj-problem-body > .cnt-row), so the switcher sits on top of the statement.

  • After the switcher is mounted, its width is measured and stored as --xmoj-problem-switcher-width on #app; a ResizeObserver on the switcher re-measures it (font loading, media queries, viewport changes) and is disconnected when the route's AbortController aborts
  • #app .jumbotron { margin-left: var(--xmoj-problem-switcher-width, 0px); } (the variable is only set on problem pages) — the width is 0 when the switcher is hidden (e.g. the ≤768px rule in MonochromeUI), so nothing moves then
  • ClearRoute() removes the variable when leaving the page

One custom CSS rule is unavoidable here: Bootstrap has no class for clearing a fixed element of measured width.

Does this PR need a documentation update?:

No

Testing / not yet verified:

  • node --check XMOJ.user.js passes; the 12 non-browser tests pass (same as on dev)
  • The 5 Playwright tests were not run (no matching Chromium installed locally)
  • Not yet tested in a browser, so item 11 (all four UI combinations) is not verified — the review checkbox below is left unchecked until a maintainer QA-tests it. The switcher is only created on the /web problem pages, so the classic pages should be unaffected

By submitting this pull request, I confirm the following:

  1. I have read and understood the contributor's guide, as well as this entire template. I understand which branch to base my commits and Pull Requests against. (dev for XMOJ-Script, master for everything else).
  2. I have commented on my proposed changes within the code.
  3. I have tested my changes.
  4. I am willing to help maintain this change if there are issues with it later.
  5. It is compatible with the GNU General Public License v3.0
  6. I have squashed any insignificant commits. (git rebase)
  7. I have checked that another pull request for this purpose does not exist.
  8. I have considered and confirmed that this submission will be valuable to others.
  9. I accept that this submission may not be used, and the pull request can be closed at the will of the maintainer.
  10. I give this submission freely and claim no ownership to its content.
  11. I have verified that my changes work correctly in all four UI combinations:
    • the script's monochrome UI on XMOJ's new UI (/web pages)
    • the script's monochrome UI on XMOJ's old/classic pages
    • the script's classic UI on XMOJ's new UI (/web pages)
    • the script's classic UI on XMOJ's old/classic pages

  • I have read the above and my PR is ready for review. Check this box to confirm

🤖 Generated with Claude Code

https://claude.ai/code/session_01JhQLfJB3LWW4vkNXK85xL1

Summary by Sourcery

Keep /web contest problem statements clear of the fixed problem switcher across layout changes.

Bug Fixes:

  • Prevent the fixed problem switcher from obscuring the left edge of problem statements on /web contest pages.

Enhancements:

  • Reserve responsive space for the problem switcher and clean up that layout state when navigating away.

Build:

  • Bump the project and userscript version to 4.0.7.

Summary by cubic

Keeps /web contest problem statements clear of the fixed problem switcher that previously covered the left edge of the statement (#1072). Bumps the project and userscript version to 4.0.7.

  • Measures the switcher after it mounts and applies its width as a left margin on the full-width problem view (#app .jumbotron); a ResizeObserver re-measures it whenever the width changes, including when fonts finish loading or a media query hides the switcher.
  • Clears the margin when leaving the route; it stays 0 while the switcher is hidden (e.g. on ≤768px screens), so the layout doesn't shift there.