Fix version selector stuck on "Loading …" after restarts#494
Merged
Conversation
The version dropdown on package pages was wired up by a per-page inline script that Yesod bundles into a dynamic /static/widget/<hash>.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 <select> element as data attributes, and Pursuit.js self-initializes on DOMContentLoaded.
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.
The version dropdown on package pages shows
Loading …indefinitely on any page that was cached before the last backend restart after the recent Nginx caching changes and #492 (e.g. https://pursuit.purescript.org/packages/purescript-yoga-fastify/0.5.2). The latest version of each package works; older/stale cached pages do not.The version selector was initialized by a per-page inline
juliusscript (versionSelector.julius) callinginitializeVersionSelector({...}). In production, Yesod bundles a page's inline scripts into a dynamic/static/widget/<hash>.jsfile whose bytes are in memory and not written to disk.When the backend restarts (any deploy), that store is emptied. nginx keeps serving the previously-cached HTML from
data/cache, which references widget hashes the new process has never generated, soGET /static/widget/<hash>.jsreturnsFile not foundandinitializeVersionSelectornever runs. Only pages re-rendered after the restart (e.g. the latest version, whose cache is cleared on publish) get a valid widget reference.To fix it, we can initialize the version selector, search form, and load-more link from the statically embedded
Pursuit.js, which is served from disk and is stable across restarts.