Adding the current icon theme to the URL of skin resources evaluated by the skin action

Hi devs,

While working on Loading... I’d like your agreement on how to fix it, since it adds a new (small) extension point.

The problem

Several JS/CSS files served by the skin action render icons server-side with $services.icon (xwiki.js for the section edit pencil, modalPopup.js, fullScreen.js, upload.js, tags.js, attachments/icons.js, xwiki.bundle.min.js, …). Their URL only carries cache-version (the file modification date), so when an admin switches the icon theme, browsers keep the cached file and show the old icons until a hard refresh.

Color themes don’t have this problem because we pass colorTheme explicitly on each ssfx.use() call. Doing the same for the icon theme on every jsfx.use() call isn’t great: it’s easy to forget, doesn’t cover $xwiki.getSkinFile(..., true) calls (e.g. the RequireJS paths in javascript.vm), and doesn’t cover extensions.

Proposal

Add the parameter centrally, wherever we generate a URL for a resource evaluated by the skin action (i.e. forceSkinAction=true and the skin document object properties):

  • New role in xwiki-platform-skin-api: org.xwiki.skin.SkinActionURLParametersProvider (@Unstable), with a single Map<String, Object> getParameters() method returning the query parameters to add to those URLs.
  • oldcore collects all the providers (ordered by hint so that URLs are stable) and adds their parameters next to cache-version, in XWiki#getSkinFile() (files under /resources), AbstractSkinResource#getURL() (files in the skin directory) and ObjectPropertyWikiResource (wiki skins).
  • xwiki-platform-icon-default implements it with iconTheme=<current icon set name>, and adds nothing when the default icon set is used (so URLs don’t change for wikis that never changed the icon theme).

Result: .../bin/skin/resources/js/xwiki/xwiki.js?cache-version=...&iconTheme=Silk. File-based skin extensions (jsfx/ssfx) get it for free since they go through XWiki#getSkinFile().

Points to discuss

  • Scope: the parameter is added to every skin-action URL, even files that don’t render icons. Pro: zero maintenance, works for extensions. Con: changing the icon theme invalidates the browser cache of all these files once (that’s a rare admin operation, so I think it’s fine). The alternative would be a per-file opt-in, which brings back the “easy to forget” problem.
  • Generic vs icon-specific: I made the extension point generic so that other configurations affecting evaluated resources could use it later (e.g. other extensions whose configuration changes what their evaluated JS/CSS contains). We could instead hardcode the icon theme in oldcore, but oldcore doesn’t depend on the icon module.
  • Java role vs UIXP: instead of a new Java role, oldcore could look up the UI extensions of a new org.xwiki.platform.skin.skinActionURLParameters extension point (like we do for org.xwiki.platform.requirejs.module in javascript.vm), and icon-ui would contribute a UIX with iconTheme=$services.icon.currentIconSetName. Pro: no new Java API, wiki apps can contribute. Con: Velocity evaluation inside low-level URL generation (XWiki#getSkinFile() is called from templates, PDF export, requests without a current wiki…), for a value that is already known in Java. I prefer the Java role, but I’m open.
  • Not covered: modifying the content of the current icon theme (rather than switching to another one) still doesn’t change the URL, same as today for color themes. We could add the icon theme document version to the parameter if we think it’s worth it. Document-based skin extensions (jsx/ssx, served by their own actions) aren’t covered either; they could use the same providers later if needed.
  • Cost: the providers are called for each evaluated resource URL generated in a request (a few dozens per page). The icon provider only calls IconSetManager#getCurrentIconSet(), which relies on the icon set cache.

PR: XWIKI-25589: Icons rendered in skin JavaScript files don't change after switching the icon theme until a browser hard refresh by vmassol · Pull Request #7167 · xwiki/xwiki-platform · GitHub (draft until we agree)

WDYT?

Thanks
PS: This post was co-written with Claude Code.

I’m not a fan of this proposal which seems to aim to fix bugs with a deprecated way of loading icons - Velocity should not be used in JavaScript/CSS code - instead of moving the JavaScript code to use xwiki-icon, the modern way of loading icons in JavaScript code. We should remove all Velocity code from skin files instead of adding new APIs to make it work better. If there are good arguments why we really need to keep loading icons with Velocity code in skin files, I would be -0, but with those generic arguments, it feels more like a -1.

Thanks @MichaelHamann, fair point. I’ve dropped the SkinActionURLParametersProvider idea and migrated the 13 skin-action JS files that were still calling $services.icon (xwiki.js, modalPopup.js, dataeditors.js, usersandgroups.js, editableProperty.js, dashboard.js, upload.js, flavor/picker.js, attachments/icons.js, exporter.js, suggestPages.js, syntaxPicker.js, suggestChildPages.js) to xwiki-icon. Since xwiki-icon was backported to 16.10.x and 17.10.x, the fix can be backported too.

Some notes:

  • Icons are now displayed asynchronously and each module makes one extra REST call.
  • A custom icon theme missing one of these icons used to render nothing; now render() fails, the same as for existing xwiki-icon users. We could make xwiki-icon more forgiving later.
  • Neither before nor after does a space-level icon theme apply to these icons: neither the skin URL nor the REST endpoint knows the current page.

I’ve closed XWIKI-25589: Icons rendered in skin JavaScript files don't change after switching the icon theme until a browser hard refresh by vmassol · Pull Request #7167 · xwiki/xwiki-platform · GitHub and opened XWIKI-25589: Icons rendered in skin JavaScript files don't change after switching the icon theme until a browser hard refresh by vmassol · Pull Request #7173 · xwiki/xwiki-platform · GitHub for XWIKI-25589. It’s a draft for now: more tests are needed to verify it, since the new functional test only covers the section edit icon.

Thanks
PS: This post was co-written with Claude Code.

Normally, we should fall back to the default icon theme in this case, if this isn’t working, I think there is a bug somewhere.

You’re right, I was wrong on this point: $services.icon.renderHTML() / getMetaData() fall back to the default icon set, so a missing icon didn’t “render nothing” before.

From what I see, the icon REST endpoint used by xwiki-icon (DefaultIconThemesResource) doesn’t fall back: icons that aren’t in the icon theme are returned in missingIcons instead. This was part of the original proposal (Exposing the Icon Theme through the REST API), but I couldn’t find any discussion there (or in the PR) about falling back to the default icon set for icons missing from the theme, so I’m not sure whether that was on purpose.

@mleduc since you designed this endpoint, what do you think? Should we make it fall back to the default icon set, like the Java/script API does (for the current icon theme only, or also when a theme is requested explicitly)? If so, I’d do it in a separate issue, since it would also affect the existing xwiki-icon users.

FTR, the new draft PR XWIKI-25589: Icons rendered in skin JavaScript files don't change after switching the icon theme until a browser hard refresh by vmassol · Pull Request #7173 · xwiki/xwiki-platform · GitHub is a possible implementation of the xwiki-icon approach, still to be validated (it would depend on the REST fallback fix, if we decide to do it).

Thanks
PS: This post was co-written with Claude Code.

Checking back the proposal, XWIKI-18604 and the review of the PR I think the case of an icon missing from the theme was overlooked.

So +1 to make the REST endpoint fall back to the default icon set to stay consistent with the Java API:

  • iconSetName should be the name of the set the icon was actually resolved from, so that clients can tell when the fallback was used
  • missingIcons then only lists the icons missing from both sets

+1 to do it in a separate issue. I wouldn’t object to consider it a bug, and to backport the fix.