Skip to content

Commit 409ec1c

Browse files
committed
fix(widget): register the recent-entries widget in window.openStationWidgets
OpenStation looks up mount callbacks by id in window.openStationWidgets (window.desktopModeWidgets on older Desktop Mode builds). The widget only exported render on window.allTerrainFormsWidget, so the shell never found it and logged a mount failure on every desktop load. Fixes #59
1 parent ac01c63 commit 409ec1c

3 files changed

Lines changed: 18 additions & 4 deletions

File tree

‎assets/js/widget.js‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,10 @@ var allTerrainFormsWidget = function(exports) {
284284
unsubscribe?.();
285285
};
286286
}
287+
const registryHost = window;
288+
const registry = registryHost.openStationWidgets || registryHost.desktopModeWidgets || {};
289+
registry["allterrain-forms/recent"] = renderWidget;
290+
registryHost.openStationWidgets = registryHost.desktopModeWidgets = registry;
287291
function mountStandalone() {
288292
document.querySelectorAll("[data-atfw-root]").forEach((host) => {
289293
if (host.dataset.atfwMounted) {

‎assets/js/widget.min.js‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/widget.ts‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,22 @@ export function renderWidget( host: HTMLElement ): () => void {
135135
* overwritten a moment later by the bundle itself, which is a bug that only
136136
* shows up in the built file and never in a test.
137137
*
138-
* So the contract is expressed as an export instead: the shell finds
139-
* `window.allTerrainFormsWidget.render` because `render` is what this module
140-
* exports.
138+
* The export stays for anything that reads that global. The shell itself does
139+
* not: OpenStation looks up mount callbacks by widget id in
140+
* `window.openStationWidgets` (`window.desktopModeWidgets` on older Desktop
141+
* Mode builds), so the callback is registered there too. That is a different
142+
* global from the one the IIFE overwrites, so assigning it here is safe.
141143
*/
142144
export { renderWidget as render };
143145

146+
type WidgetRegistry = Record< string, ( host: HTMLElement ) => ( () => void ) | void >;
147+
148+
// Merge, never replace: other plugins' widgets live in the same object.
149+
const registryHost = window as unknown as { openStationWidgets?: WidgetRegistry; desktopModeWidgets?: WidgetRegistry };
150+
const registry: WidgetRegistry = registryHost.openStationWidgets || registryHost.desktopModeWidgets || {};
151+
registry[ 'allterrain-forms/recent' ] = renderWidget;
152+
registryHost.openStationWidgets = registryHost.desktopModeWidgets = registry;
153+
144154
/**
145155
* Mounts into a plain container, for the admin page.
146156
*

0 commit comments

Comments
 (0)