Fix diff view on the /latest/ URL #120

Merged
qwc merged 2 commits from fix/diff-view-on-latest into main 2026-06-18 11:01:52 +02:00
Owner

Follow-up to #119. Using the compare / diff view from a /project/{slug}/latest/ page was broken: the "Showing changes from version …" header and Exit Diff View button didn't appear — only a faint amber background bar.

Root cause (two compounding bugs)

  1. Compare used the wrong version segment for path math. The compare handler computed the in-doc sub-path by stripping /project/{slug}/{current} from window.location.pathname, where current is the resolved tag (e.g. v1.5). On a /latest/ URL the path actually contains latest, so the slice was off and the target-version fetch URL came out malformed → the diff fetch 404'd. (#119 switched the version-switcher and link-interception copies to urlVersion; this third copy was missed due to its indentation.)

  2. The error bar was mispositioned. showError showed the diff-indicator bar but — unlike showDiffIndicator — never set its top, so it fell back to the CSS default top:auto and rendered behind the main overlay. All you saw was the background sliver; the text and Exit button were hidden underneath.

Bug 1 triggered bug 2 specifically on /latest/, which is why it looked like an empty bar there.

Fix

  • Compare handler now strips urlVersion (the segment actually in the URL — latest when served via the permalink), matching the other path-math sites. The diff fetch now resolves correctly and the success path (showDiffIndicator, which positions the bar below the overlay) shows the full header + Exit button.
  • showError now sets indicator.style.top = overlay height, so any genuine error bar is visible too.

One file, static/js/overlay.js. current is still used where the concrete tag is correct (compare target, download link). Worth a manual check on deploy: open a multi-version project at /project/{slug}/latest/, run a compare, confirm the header/Exit button appear and the diff loads.

🤖 Generated with Claude Code

Follow-up to #119. Using the **compare / diff view** from a `/project/{slug}/latest/` page was broken: the "Showing changes from version …" header and **Exit Diff View** button didn't appear — only a faint amber background bar. ## Root cause (two compounding bugs) 1. **Compare used the wrong version segment for path math.** The compare handler computed the in-doc sub-path by stripping `/project/{slug}/{current}` from `window.location.pathname`, where `current` is the *resolved* tag (e.g. `v1.5`). On a `/latest/` URL the path actually contains `latest`, so the slice was off and the target-version fetch URL came out malformed → the diff fetch 404'd. (#119 switched the version-switcher and link-interception copies to `urlVersion`; this third copy was missed due to its indentation.) 2. **The error bar was mispositioned.** `showError` showed the diff-indicator bar but — unlike `showDiffIndicator` — never set its `top`, so it fell back to the CSS default `top:auto` and rendered *behind* the main overlay. All you saw was the background sliver; the text and Exit button were hidden underneath. Bug 1 triggered bug 2 specifically on `/latest/`, which is why it looked like an empty bar there. ## Fix - Compare handler now strips `urlVersion` (the segment actually in the URL — `latest` when served via the permalink), matching the other path-math sites. The diff fetch now resolves correctly and the success path (`showDiffIndicator`, which positions the bar below the overlay) shows the full header + Exit button. - `showError` now sets `indicator.style.top = overlay height`, so any genuine error bar is visible too. One file, `static/js/overlay.js`. `current` is still used where the concrete tag is correct (compare target, download link). Worth a manual check on deploy: open a multi-version project at `/project/{slug}/latest/`, run a compare, confirm the header/Exit button appear and the diff loads. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Fix diff on /latest/: compare suffix + mispositioned error bar
All checks were successful
CI / test (pull_request) Successful in 1m7s
CI / build (pull_request) Successful in 42s
CI / docker (pull_request) Has been skipped
720783d0a4
Two issues surfaced using the diff view from a /latest/ URL:

1. The compare handler still computed the in-doc path suffix by stripping
   the resolved tag (`current`, e.g. v1.5) from window.location.pathname —
   but the path contains "latest", so the target-version fetch URL came out
   malformed and the diff failed. (The version-switcher and link-intercept
   copies were already switched to urlVersion; this third copy was missed
   because of its indentation.) Use urlVersion here too.

2. showError displayed the diff-indicator bar without setting its `top`,
   so it fell back to the CSS default (top:auto) and rendered *behind* the
   main overlay — you saw only the amber background sliver, with the
   "Showing changes from version …" text and Exit Diff View button hidden.
   The failed compare from (1) is what made this visible on /latest/. Set
   indicator.style.top = overlay height, same as showDiffIndicator.

With (1) fixed the compare now succeeds on /latest/ (showing the indicator
via the correctly-positioned success path); (2) ensures any genuine error
bar is visible too.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Add browserless E2E tests for the doc overlay
All checks were successful
CI / test (pull_request) Successful in 1m9s
CI / build (pull_request) Successful in 46s
CI / docker (pull_request) Has been skipped
bc759b53ef
Guards the overlay regressions that broke the diff view on the /latest/
permalink. Loads the real static/js/overlay.js into jsdom (no browser
binary; Node is already in CI), mocks the versions API and document fetch,
and drives the compare flow:

- compare from a /latest/ URL must fetch /project/docs/v1.0.0/guide.html,
  not a mangled path built from the resolved tag — the exact bug fixed in
  this branch (caught against the pre-fix code).
- compare from an explicit version URL still builds the right path.
- the error bar is shown with style.top set, so it sits below the overlay
  instead of hidden behind it.

Uses Node's built-in test runner + jsdom only; `npm ci && npm test`. Wired
into the CI test job (which already had nodejs; added npm). node_modules is
gitignored.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
qwc merged commit bbac98f74a into main 2026-06-18 11:01:52 +02:00
qwc deleted branch fix/diff-view-on-latest 2026-06-18 11:01:52 +02:00
Sign in to join this conversation.
No reviewers
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
qwc-open/asiakirjat!120
No description provided.