Seamless asset refresh instead of the reload prompt#4810
Open
ernestdefoe wants to merge 1 commit into
Open
Conversation
When the forum's assets are rebuilt (a deploy, or an admin toggling an extension), core detects the new revision and immediately shows a dismissible "a new version of this page is available — reload" alert. It appears mid-read or mid-compose, and because an extension toggle rebuilds assets, it pops up for every visitor on the forum at once. Following luceos's proposal, don't interrupt: when newer assets are detected, flag it and turn the user's next navigation into a full page load, so fresh assets are picked up naturally without ever interrupting a reading or typing session. Modified clicks, new-tab/download links, in-page anchors and external links are left untouched; back/forward reloads too.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Background
When the forum's assets are rebuilt — a deploy, or simply an admin enabling/disabling an extension — every API response starts carrying a new
X-Flarum-Assets-Revision.ForumApplication.checkAssetsRevisioncompares it to the revision the page booted with and, if it differs, immediately shows a dismissible "A new version of this page is available — Reload" alert.Two problems with showing it right away:
What this does
Implements the middle ground @luceos proposed — don't interrupt, don't ignore. When newer assets are detected we just remember it (
assetsRefreshPending) and say nothing. The user's next real navigation — clicking a link, opening a discussion, back/forward — is turned into a full page load, so the fresh assets are picked up naturally.The result: an actively reading or typing user is never interrupted, there's no modal and no timing guesswork, no risk of discarding an open draft — and the very next navigation is already on the new assets.
Details
checkAssetsRevisionnow sets a flag and lazily wires uprefreshOnNextNavigation()instead of showing the alert. It's stillpublicso the realtime extension's pushed revision token flows through the same path.refreshOnNextNavigation()adds a capture-phase click listener (stops propagation so it runs before the router's<Link>handling) that only acts on a plain left-click of an internal, same-origin link. It deliberately leaves untouched: modified clicks (Ctrl/⌘/Shift/middle → open in new tab/window),target="_blank"/downloadlinks, in-page anchors (#…),javascript:/mailto:/tel:links, external links, and bare hash changes on the current page.popstatereloads too.Buttonimport.The
core.lib.assets_updated.message/.reload_buttonlocale strings are now unused. I left them in place to avoid churning existing translations — happy to remove them if you'd prefer.Testing
Verified against a forum whose assets were rebuilt after load:
#,javascript:links, and same-page hash changes all behave normally.I've also been running this as a userland extension (overriding the same method) on two production forums.