From df5e5b8ec4d1ba0a128f4c8dc0ac099de7bcb8ce Mon Sep 17 00:00:00 2001 From: Thomas Honeyman Date: Tue, 7 Jul 2026 16:01:05 -0400 Subject: [PATCH] Initialize version selector from static Pursuit.js The version dropdown on package pages was wired up by a per-page inline script that Yesod bundles into a dynamic /static/widget/.js file. That file's contents live only in the running backend's in-memory EmbeddedStatic store, so any backend restart orphaned it: nginx keeps serving already-cached HTML referencing the old hash, the script 404s, and the selector stays stuck on 'Loading ...'. Drive the version selector, search form, and load-more link from the statically embedded Pursuit.js instead. It is served from disk and is stable across restarts. Per-page config for the selector now rides on the element, which carries its per-page + * configuration in data attributes: + * - data-current-version (String): * the version of docs that is being shown on this page. - * - elementId (String): - * the HTML id of the version selector element. - * - availableVersionsUrl (String): + * - data-available-versions-url (String): * The URL to fetch the available versions for this package from. + * + * This initializer is invoked from this (statically served) script rather than + * from an inline per-page script, so that it keeps working across backend + * restarts. Inline widget scripts are served from the backend's in-memory + * EmbeddedStatic store and are orphaned when it restarts, which would leave + * already-cached pages stuck showing "Loading …". */ -function initializeVersionSelector(args) { +function initializeVersionSelector(selector) { + var currentVersion = selector.getAttribute('data-current-version') + var availableVersionsUrl = selector.getAttribute('data-available-versions-url') + function getJSON(url, callback) { var req = new XMLHttpRequest() req.open('GET', url, true) @@ -30,7 +38,7 @@ function initializeVersionSelector(args) { el.setAttribute("value", url) // Set the 'selected' attribute on the current version - if (version === args.currentVersion) { + if (version === currentVersion) { el.setAttribute('selected', null) } @@ -52,13 +60,12 @@ function initializeVersionSelector(args) { // Set an onchange handler so that selecting a version in the +