Skip to content

feat: sync current slide with a URL query parameter - #190

Merged
KristjanESPERANTO merged 3 commits into
shbatm:developfrom
HeikoGr:feat/url-hash
Sep 29, 2026
Merged

KristjanESPERANTO merged 3 commits into
shbatm:developfrom
HeikoGr:feat/url-hash

Conversation

@HeikoGr

@HeikoGr HeikoGr commented Sep 27, 2026

Copy link
Copy Markdown

What

New option urlHash (default false). When enabled:

  • On start, the carousel jumps to the slide given in the URL hash, e.g. http://localhost:8080/#3.
  • Changing the hash while the page is open (link, bookmark, address bar) navigates as well.
  • A number selects the slide 1-indexed, the same as CAROUSEL_GOTO. In slides mode, a slide name works too, e.g. #Home.
  • Every slide change writes the current slide number back to the hash, so the address bar always shows a link to the visible page.

Why

Many setups show the mirror in a browser (tablet, second screen, serveronly). A URL per page makes it possible to bookmark a page, share a link to it, or have a kiosk browser start on a given page. Before this change, there was no way to do that without a remote-control module.

How

  • Hash parsing (decodeUrlHash, parseUrlHash) returns the same payloads that handleCarouselGoto accepts. Navigation therefore goes through the existing CAROUSEL_GOTO path, including restartTimer, so transitionTimeout and homeSlide behave the same as with any other manual navigation.
  • moduleTransition calls updateUrlHash, which uses history.replaceState. This does not fire hashchange, so there is no feedback loop, and automatic rotation does not add browser history entries.
  • updateUrlHash is inactive until setupUrlHash has run. Without that guard, the initial transition would overwrite the start hash with #1 before it was read.
  • Unknown slide names log a warning and are ignored.
  • positional mode is not supported, because each position has its own index. A warning is logged, the same as for enableKeyboardControl.

Tests

  • New unit tests for parseUrlHash, setupUrlHash and updateUrlHash. The window mock in the test context is now a named object so tests can stub location, history and addEventListener.
  • node --run test passes: unit tests, eslint, prettier and cspell.
  • Tested manually in headless Chrome with slides mode and MMM-KeyBindings 3.1.0:
    • start with #2
    • hash change to a name and to a number
    • arrow key and next button update the hash
    • an unknown name is ignored with a warning

🤖 Generated with Claude Code

With urlHash enabled, the carousel jumps to the slide given in the URL
hash on start and on hashchange (shbatm#3 = third slide, or a slide name in
slides mode) and writes the current slide number back on every
transition via history.replaceState, so no feedback loop and no history
entries. Navigation reuses handleCarouselGoto, so transitionTimeout and
homeSlide behave as with any manual navigation. Not supported in
positional mode.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@KristjanESPERANTO

Copy link
Copy Markdown
Collaborator

Thanks for the PR! This seems like a useful feature. What do you think of a namespaced query parameter such as ?carousel=3 or ?carousel=Home instead of the raw URL hash? The hash is shared with page anchors and other modules, while URLSearchParams would avoid collisions.

@HeikoGr

HeikoGr commented Sep 27, 2026

Copy link
Copy Markdown
Author

you are right about the namespace. ?carousel=n would be fine.

@KristjanESPERANTO

Copy link
Copy Markdown
Collaborator

Nice. Would you like to adapt your PR? :)

@HeikoGr

HeikoGr commented Sep 29, 2026

Copy link
Copy Markdown
Author

@KristjanESPERANTO yes. i let claude rework the patch

@KristjanESPERANTO

Copy link
Copy Markdown
Collaborator

Thanks :) I saw your commit. I'll need a little time to review it.

@KristjanESPERANTO KristjanESPERANTO changed the title feat: add urlHash option to open slides via URL hash feat: sync current slide with a URL query parameter Sep 29, 2026
@KristjanESPERANTO
KristjanESPERANTO changed the base branch from master to develop September 29, 2026 19:50
@KristjanESPERANTO
KristjanESPERANTO merged commit cf4fc00 into shbatm:develop Sep 29, 2026
1 check passed
@KristjanESPERANTO KristjanESPERANTO mentioned this pull request Sep 29, 2026
@KristjanESPERANTO

Copy link
Copy Markdown
Collaborator

I did some more fine-tuning and included it in the new release 😃 Thanks again!

@HeikoGr
HeikoGr deleted the feat/url-hash branch September 30, 2026 05:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants