Skip to content

Comments

feat: auto-reload monitors for user switch and config changes#404

Open
4eh5xitv6787h645ebv wants to merge 1 commit inton00bcodr:mainfrom
4eh5xitv6787h645ebv:fix/auto-reload-monitors
Open

feat: auto-reload monitors for user switch and config changes#404
4eh5xitv6787h645ebv wants to merge 1 commit inton00bcodr:mainfrom
4eh5xitv6787h645ebv:fix/auto-reload-monitors

Conversation

@4eh5xitv6787h645ebv
Copy link
Contributor

@4eh5xitv6787h645ebv 4eh5xitv6787h645ebv commented Feb 20, 2026

Summary

  • Adds user change monitor that detects SPA user switches and reloads the page, clearing stale JE_ sessionStorage keys (e.g. JE_IsAdmin) to prevent admin UI leaking to non-admin users
  • Adds config change monitor that snapshots plugin config (public + private) on entering the admin config page and compares on exit — reloads only if settings actually changed
  • Both monitors use location polling as primary detection since Jellyfin's router uses history.pushState() which does not fire hashchange/popstate events

Fixes #402
Mitigates #270 — config changes now auto-reload when leaving the config page
Mitigates #277 — stale session state is cleared on user switch

Implementation Notes

This PR was developed with AI assistance (Claude). All changes have been reviewed, tested manually, and verified with E2E tests against a live Jellyfin 10.11 dev instance.

Safety features:

  • 5s reload cooldown prevents infinite reload loops
  • Baseline userId adoption handles late plugin init (null initial user)
  • Monotonic snapshot token discards stale async responses on rapid navigation
  • In-flight snapshot await (1.5s) prevents missed changes on fast page exit
  • Graceful sessionStorage fallback for private browsing mode
  • Config page detection parses name= query param (not substring match)
  • decodeURIComponent guarded against malformed % sequences

Testing

  • Tested on Jellyfin 10.11
  • Verified no console errors
  • User switch correctly triggers reload and clears JE_ session state
  • Same-user re-login does NOT trigger reload
  • Visiting config page without saving does NOT trigger reload
  • Changing config via API then leaving config page triggers reload
  • Works on Chrome and Firefox
  • No breaking changes to existing functionality

Adds two monitors that run after plugin initialization:

1. User change monitor — polls ApiClient.getCurrentUserId() every 1s
   and reloads the page when a different user logs in via SPA navigation.
   Clears all JE_ sessionStorage keys (e.g. JE_IsAdmin) before reload
   to prevent stale admin state leaking to non-admin users.
   Fixes n00bcodr#402

2. Config change monitor — snapshots public-config and private-config
   on entering the JE admin config page, compares against current server
   config on exit, and reloads only if settings actually changed.

Both monitors use location polling as the primary detection mechanism
because Jellyfin's SPA router uses history.pushState() which does not
fire hashchange or popstate events. hashchange/popstate listeners are
kept as supplementary fast-path detectors.

Safety features:
- 5s reload cooldown (sessionStorage) prevents infinite reload loops
- Baseline userId adoption handles late plugin init (null initial user)
- Monotonic snapshot token discards stale async responses on rapid nav
- In-flight snapshot await (1.5s) prevents missed changes on fast exit
- Graceful sessionStorage fallback for private browsing mode
- Config page detection parses name= query param (not substring match)
- decodeURIComponent guarded against malformed % sequences

This PR was developed with AI assistance (Claude). All changes have been
reviewed, tested manually, and verified with E2E tests against a live
Jellyfin 10.11 dev instance.
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.

🐛[BUG] Radarr/Sonarr/Bazarr buttons can appear for non admin users

1 participant