Skip to content

Conversation

@VikramAditya33
Copy link
Contributor

@VikramAditya33 VikramAditya33 commented Nov 7, 2025

Fix: Add articleLoader and appstate updates to libzim message handler

Issues

Fixes #1385 and #1380

Issue #1385: Popovers not working in libzim mode

Popovers were not working consistently in libzim mode with Service Worker. Specifically:

  • When users opened a Wikivoyage ZIM and landed on the default landing page, popovers didn't work
  • Clicking links to navigate to other articles would load the articles successfully, but popovers still wouldn't work
  • Only after performing a search and navigating to an article would popovers start working

Issue #1380: Erratic sliding toolbars with Zimit classic archives

Sliding away toolbars were erratic with Zimit classic archives when using libzim backend due to not attaching the correct iframe for postprocessing in the libzim message channel.

Root Causes

For #1385:

The handleMessageChannelByLibzim() function was not updating appstate.expectedArticleURLToBeDisplayed when delivering HTML content to the Service Worker. This caused the variable to remain stuck at the landing page URL even after navigating to different articles.

The popover module checks this variable to determine if the current page is a landing page (where popovers are intentionally disabled to avoid interfering with interactive maps). Since the variable was never updated, the check would always think the user was still on the landing page, blocking popovers on all subsequent pages.

For #1380:

The libzim message channel was not calling articleLoader() to properly attach the iframe for postprocessing, causing the toolbar gesture detection to malfunction.

Solution

Updated handleMessageChannelByLibzim() to:

  1. Mirror the behavior of handleMessageChannelMessage() by updating appstate.baseUrl and appstate.expectedArticleURLToBeDisplayed when serving HTML content
  2. Add articleLoader() call to attach the correct iframe for postprocessing

This ensures proper state tracking and iframe attachment during link-based navigation in Service Worker + libzim mode.

Changes

  • Added state updates in handleMessageChannelByLibzim() (lines 1094-1098 in app.js)
  • Updates both appstate.baseUrl and appstate.expectedArticleURLToBeDisplayed for HTML content
  • Maintains consistency between libzim and non-libzim backend implementations
  • Added articleLoader() call to properly attach iframe for postprocessing

- handleMessageChannelByLibzim now updates expectedArticleURLToBeDisplayed
- This ensures popovers work when navigating via link clicks in SW mode
- Mirrors behavior of non-libzim handleMessageChannelMessage
- Fixes kiwix#1385
@Jaifroid Jaifroid self-requested a review November 7, 2025 17:59
@Jaifroid Jaifroid added backend bug-non-critical For bugs that it would be nice to fix rather than critical to fix labels Nov 7, 2025
@Jaifroid Jaifroid added this to the v4.3 milestone Nov 7, 2025
@Jaifroid
Copy link
Member

Jaifroid commented Nov 7, 2025

Thank you, code looks great, I'll do a bit of testing.

@Jaifroid
Copy link
Member

Jaifroid commented Nov 9, 2025

Could you kindly update this branch with the latest changes on main using the Update branch button below? This will allow me to test properly with latest changes.

@Jaifroid
Copy link
Member

Jaifroid commented Nov 9, 2025

PS don't forget to pull the changes to your own branch after.

@VikramAditya33
Copy link
Contributor Author

@Jaifroid I'm done updating the branch, now you can proceed with your testing.

Copy link
Member

@Jaifroid Jaifroid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this PR - please just attend to the small addition as per comment, and we'll be good to merge. Let me know if you've accepted the suggestion and are ready for me to merge. You can either use the accept suggestion button or do it yourself on your branch and push. If you use the button, please pull the changes to your local branch afterwards.

@Jaifroid
Copy link
Member

PS Adding the article loader fixes #1380!

@Jaifroid
Copy link
Member

So you could change the title of the PR to reflect both issues it would be fixing.

@VikramAditya33 VikramAditya33 changed the title Fix: Update appstate in libzim message handler to enable popovers Fix libzim message handler to enable popovers and fix erratic sliding toolbars (fixes #1385, #1380) Nov 10, 2025
@VikramAditya33
Copy link
Contributor Author

@Jaifroid I've done the changes as suggested.

@VikramAditya33
Copy link
Contributor Author

@Jaifroid I've fixed the indentation as suggested, i'm really sorry about the confusion earlier! I was looking at the wrong message channel (around line 2743) instead of the libzim channel (lines 1109-1110). Total brain fog moment on my part. 🤦‍♂️
Both changes are now complete:

  • Accepted your suggestion for the code addition
  • Fixed indentation for lines 1109-1110 in the libzim message channel
    The PR should be ready to merge now. Let me know if there's anything else that needs attention!

@Jaifroid Jaifroid merged commit 0c7582e into kiwix:main Nov 11, 2025
6 checks passed
@VikramAditya33 VikramAditya33 deleted the fix-libzim-appstate-update-issue-1385 branch November 11, 2025 23:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend bug-non-critical For bugs that it would be nice to fix rather than critical to fix user interface

Projects

None yet

2 participants