Repository navigation
fix: stop registering sphinx-book-theme.js, which is never copied - #455
Conversation
setup() calls app.setup_extension("sphinx_book_theme") for that
package's Python features, and sphinx_book_theme's own setup() runs
app.add_js_file("scripts/sphinx-book-theme.js"). The file lives in
sphinx_book_theme's static folder, which is only copied when that is the
active theme, so every page requested a script that 404'd and has never
loaded.
Drop the entry from app.registry.js_files straight after
setup_extension. The HTML builder builds its script list from the
registry in init_js_files(), which runs after the theme's setup() on
both paths that load it: from the sphinx.html_themes entry point inside
init_templates(), and from conf.py extensions before the builder exists.
The second covers Jupyter Book 1, which lists sphinx_book_theme in its
default extensions so its setup() runs before ours.
Adds tests/test_script_files.py, which builds the base test site both
ways with -W and checks that no page requests the script, that
quantecon-book-theme.js is still loaded, and that every local script a
page requests exists.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #455 +/- ##
=======================================
Coverage ? 59.48%
=======================================
Files ? 2
Lines ? 548
Branches ? 0
=======================================
Hits ? 326
Misses ? 222
Partials ? 0
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
🟢 Approval recommended
The fix is minimal and correctly targeted, its reliance on the internal app.registry.js_files shape is deliberately justified and guarded by a new build-marked regression test, and no objective issues were found in the change, test, or changelog.
0 open findings
What changed in this PR
This PR fixes issue #454, where every page built with the theme requested _static/scripts/sphinx-book-theme.js — a file that is never copied into the build (it lives in sphinx-book-theme's static folder, which is only copied when that is the active theme), producing a 404 on every page. The theme calls app.setup_extension("sphinx_book_theme") to obtain that package's Python features, and sphinx-book-theme's own setup() registers that script. The fix removes just that one registration from Sphinx's JS registry immediately after setting up the extension, so the script tag disappears and nothing else changes.
Changes:
- In
setup(), filterapp.registry.js_filesin place to drop thescripts/sphinx-book-theme.jsentry right aftersetup_extension("sphinx_book_theme"). - Add
tests/test_script_files.py(markedbuild) that buildstests/sites/basetwice (default, and withsphinx_book_themeappended toextensionsto mimic Jupyter Book 1's load order) and asserts the script is no longer requested,quantecon-book-theme.jsstill loads, and every local script resolves to a built file. - Add a
### Fixedentry toCHANGELOG.md.
| File | Description |
|---|---|
src/quantecon_book_theme/__init__.py |
Removes the scripts/sphinx-book-theme.js entry from the JS registry after setting up the sphinx-book-theme extension. |
tests/test_script_files.py |
New regression test verifying no page requests the missing script and all local scripts resolve, across both extension load orders. |
CHANGELOG.md |
Documents the fix under [Unreleased] → Fixed. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
🎭 Visual Regression Test ResultsDetails
Skipped testsdesktop-chrome › theme.spec.ts › Visual Regression Tests › prob-matrix - full page screenshot |
The build tests run setup() inside sphinx-build subprocesses, which coverage does not see, so codecov/patch reported the new filter as uncovered. Drive setup() with Sphinx's own SphinxComponentRegistry and check that only the sphinx-book-theme.js entry is dropped. This also pins the registry API the filter relies on. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Brings in #453. CHANGELOG.md conflicted because both PRs added a ### Fixed section under [Unreleased]; keep both entries in one section, #384's first. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Fixes #454
What was wrong
Every page requested
_static/scripts/sphinx-book-theme.js, which is never in the build, so it 404'd (live at https://jax.quantecon.org/_static/scripts/sphinx-book-theme.js; all 36 lecture pages in a lecture-jax build from main carry the tag).setup()callsapp.setup_extension("sphinx_book_theme")for that package's Python features, and sphinx-book-theme's ownsetup()runsapp.add_js_file("scripts/sphinx-book-theme.js"). The file lives in sphinx-book-theme's static folder, which is only copied when sphinx-book-theme is the active theme, so the script has never loaded on a quantecon-book-theme site.The change
Straight after
setup_extension,setup()removes that one entry fromapp.registry.js_files(in place). Nothing else changes: the script never loaded, and all other registered scripts are untouched.Why the registry route, and why it holds
I checked this against Sphinx 7.4.7 and 8.2.3 (the theme allows
>=7,<9):app.add_js_fileappends(filename, attrs)toapp.registry.js_filesin both versions, and also pushes straight to the builder if one already exists.StandaloneHTMLBuilder.init()runsinit_templates()and theninit_js_files().init_js_files()resets the builder's_js_filesand rebuilds it from the registry:self.app.registry.js_filesin 7.x, andself.env._registry.js_filesin 8.x, where_registryis a property returningapp.registry. So whatever the registry holds at that point is what pages get.setup()always runs beforeinit_js_files(), on both paths that load it. Withhtml_theme = "quantecon_book_theme"it runs from thesphinx.html_themesentry point insideinit_templates(). The direct push to the already-existing builder is then discarded by the reset. Via conf.pyextensions, it runs before the builder exists.sphinx_book_themein its defaultextensions, so in lecture builds sphinx-book-theme'ssetup()runs first and oursetup_extensioncall is a no-op. The entry is still in the registry when our filter runs, so it is removed either way. I confirmed both orders by wrapping the twosetup()functions in a test build, on both Sphinx versions: after setup, neither the registry nor the builder's script list holds the script.registry.js_filesshape and the sameinit_templates(), theninit_js_files()order. I checked that from the source only, not with a build, since the theme caps Sphinx below 9.I didn't use the alternative of filtering
context["script_files"]in anhtml-page-contexthook. It would run once per page rather than once per build, and it would need to handle the mixedstr/_JavaScriptentries that list can hold.app.registryis internal API, but it has had the same shape across 7.x, 8.x and 9.x, and the new test fails loudly if that ever changes.sphinx-book-theme's
hash_html_assetsIt still lists
scripts/sphinx-book-theme.jsand is unaffected:script_filesentry whose filename is exactlyscripts/sphinx-book-theme.js, but the builder stores_static/scripts/sphinx-book-theme.js, so it never matched before this change and doesn't now. The undigested<script src="_static/scripts/sphinx-book-theme.js">in today's output shows this; a match would have added a?digest=.-Wand pass.Tests
tests/test_script_files.py(markedbuild) buildstests/sites/basewith-Wtwice: as-is, and withsphinx_book_themeappended toextensionsto reproduce Jupyter Book 1's setup order. For each build it checks that:scripts/sphinx-book-theme.jsscripts/quantecon-book-theme.js<script src>on every page resolves to a file in the build, the general form of this bug (before the fix the only unresolved ones were the 11sphinx-book-theme.jstags)Without the change the first and third checks fail in both builds (4 failures); with it all 6 pass, on Sphinx 7.4.7 and 8.2.3.
Those builds run
setup()in a subprocess that coverage doesn't see, socodecov/patchfirst reported the new lines as uncovered. A second commit addstest_setup_drops_only_the_sphinx_book_theme_script, which runssetup()in-process against Sphinx's ownSphinxComponentRegistryand checks that only thesphinx-book-theme.jsentry is dropped. It fails against main's code and passes with the fix, on Sphinx 7.4.7 and 8.2.3.Verification
tests/sites/basebuilt in the same environment before and after: each of the 11 pages loses exactly one line, thesphinx-book-theme.jsscript tag._static/is identical, and no other HTML changed.quantecon-book-theme.jsstill loads on the same 17. No build warnings either way.tests/test_build/don't include the script tag and did not change.Merge note
#453 has merged, so
mainis merged into this branch (0465d67). The only conflict was the### Fixedsection both PRs added under[Unreleased]inCHANGELOG.md. It now holds both entries, #384's first, and againstmainthis PR's CHANGELOG change is just its own line. The full suite passes on the merged tree: 227 tests on Python 3.12 and 3.13 × Sphinx 7.4.7 and 8.2.3.🤖 Generated with Claude Code