Skip to content

Seamless asset refresh instead of the reload prompt#4810

Open
ernestdefoe wants to merge 1 commit into
flarum:2.xfrom
ernestdefoe:seamless-asset-refresh
Open

Seamless asset refresh instead of the reload prompt#4810
ernestdefoe wants to merge 1 commit into
flarum:2.xfrom
ernestdefoe:seamless-asset-refresh

Conversation

@ernestdefoe

Copy link
Copy Markdown

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.checkAssetsRevision compares 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:

  • It appears mid-read or mid-compose, interrupting whatever the user was doing.
  • Because an extension toggle rebuilds assets, it pops up for every visitor on the forum at once the moment an admin touches the admin area — which reads as the forum nagging everyone to reload.

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

  • checkAssetsRevision now sets a flag and lazily wires up refreshOnNextNavigation() instead of showing the alert. It's still public so 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" / download links, in-page anchors (#…), javascript: / mailto: / tel: links, external links, and bare hash changes on the current page. popstate reloads too.
  • Removed the now-unused Button import.

The core.lib.assets_updated.message / .reload_button locale 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:

  • No alert appears; the flag is set instead.
  • The next internal-link click / back-forward triggers a full page load onto the new assets, while modified clicks, new-tab/download, external, #, 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.

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.
@ernestdefoe ernestdefoe requested a review from a team as a code owner July 8, 2026 17:33
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.

1 participant