jupyterlite-sphinx icon indicating copy to clipboard operation
jupyterlite-sphinx copied to clipboard

Attempt to load `try_examples` configuration file only once per page

Open agriyakhetarpal opened this issue 11 months ago • 3 comments

Description

On pages where API reference examples to be made interactive are widespread and multiple ones exist, there are a lot of redundant error messages in the console (as noted below).

I'm testing this with scikit-image/scikit-image#7644, and here is an example of a sample page from the preview artifacts: https://output.circle-artifacts.com/output/job/048f37f1-2a97-4826-b310-3c66a77deb9c/artifacts/0/doc/build/html/api/skimage.measure.html

I assume this happens because we run the JavaScript file per iframe, but it would be nice to catch the error on the first iframe and cache it if it's being reported more than once, and check it exists in the console already.

Reproduce

Open the developer console when on the aforementioned link

Expected behavior

That we load and generate an error based on the missing config file just once

Context

  • JupyterLite version: 0.17.1 (latest stable release)
  • Operating System and version: macOS Sonoma 14.6.1
  • Browser and version: Arc Version 1.74.0 (57065), running Chromium Engine Version 131.0.6778.205
Browser Output
[PST]: Changed to dark mode using the dark theme.
pydata-sphinx-theme.js:151 [PST]: Scrolled sidebar using stored browser position...
jupyterlite_sphinx.js?v=d6bdf5f8:163 
   GET https://output.circle-artifacts.com/output/job/048f37f1-2a97-4826-b310-3c66a77deb9c/artifacts/0/doc/build/html/try_examples.json?cb=1734970953568 404 (Not Found)

window.loadTryExamplesConfig @ jupyterlite_sphinx.js?v=d6bdf5f8:163 (anonymous) @ skimage.measure.html:3068 jupyterlite_sphinx.js?v=d6bdf5f8:167 Optional try_examples config file not found. jupyterlite_sphinx.js?v=d6bdf5f8:163

   GET https://output.circle-artifacts.com/output/job/048f37f1-2a97-4826-b310-3c66a77deb9c/artifacts/0/doc/build/html/try_examples.json?cb=1734970953568 404 (Not Found)

window.loadTryExamplesConfig @ jupyterlite_sphinx.js?v=d6bdf5f8:163 (anonymous) @ skimage.measure.html:3162 jupyterlite_sphinx.js?v=d6bdf5f8:167 Optional try_examples config file not found. jupyterlite_sphinx.js?v=d6bdf5f8:163

   GET https://output.circle-artifacts.com/output/job/048f37f1-2a97-4826-b310-3c66a77deb9c/artifacts/0/doc/build/html/try_examples.json?cb=1734970953566 404 (Not Found)

window.loadTryExamplesConfig @ jupyterlite_sphinx.js?v=d6bdf5f8:163 (anonymous) @ skimage.measure.html:718 jupyterlite_sphinx.js?v=d6bdf5f8:167 Optional try_examples config file not found. jupyterlite_sphinx.js?v=d6bdf5f8:163

   GET https://output.circle-artifacts.com/output/job/048f37f1-2a97-4826-b310-3c66a77deb9c/artifacts/0/doc/build/html/try_examples.json?cb=1734970953567 404 (Not Found)

window.loadTryExamplesConfig @ jupyterlite_sphinx.js?v=d6bdf5f8:163 (anonymous) @ skimage.measure.html:807 jupyterlite_sphinx.js?v=d6bdf5f8:167 Optional try_examples config file not found. jupyterlite_sphinx.js?v=d6bdf5f8:163

   GET https://output.circle-artifacts.com/output/job/048f37f1-2a97-4826-b310-3c66a77deb9c/artifacts/0/doc/build/html/try_examples.json?cb=1734970953568 404 (Not Found)

window.loadTryExamplesConfig @ jupyterlite_sphinx.js?v=d6bdf5f8:163 (anonymous) @ skimage.measure.html:3279 jupyterlite_sphinx.js?v=d6bdf5f8:167 Optional try_examples config file not found. jupyterlite_sphinx.js?v=d6bdf5f8:163

   GET https://output.circle-artifacts.com/output/job/048f37f1-2a97-4826-b310-3c66a77deb9c/artifacts/0/doc/build/html/try_examples.json?cb=1734970953567 404 (Not Found)

window.loadTryExamplesConfig @ jupyterlite_sphinx.js?v=d6bdf5f8:163 (anonymous) @ skimage.measure.html:903 jupyterlite_sphinx.js?v=d6bdf5f8:167 Optional try_examples config file not found. jupyterlite_sphinx.js?v=d6bdf5f8:163

   GET https://output.circle-artifacts.com/output/job/048f37f1-2a97-4826-b310-3c66a77deb9c/artifacts/0/doc/build/html/try_examples.json?cb=1734970953568 404 (Not Found)

window.loadTryExamplesConfig @ jupyterlite_sphinx.js?v=d6bdf5f8:163 (anonymous) @ skimage.measure.html:3402 jupyterlite_sphinx.js?v=d6bdf5f8:167 Optional try_examples config file not found. jupyterlite_sphinx.js?v=d6bdf5f8:163

   GET https://output.circle-artifacts.com/output/job/048f37f1-2a97-4826-b310-3c66a77deb9c/artifacts/0/doc/build/html/try_examples.json?cb=1734970953567 404 (Not Found)

window.loadTryExamplesConfig @ jupyterlite_sphinx.js?v=d6bdf5f8:163 (anonymous) @ skimage.measure.html:1027 jupyterlite_sphinx.js?v=d6bdf5f8:167 Optional try_examples config file not found. jupyterlite_sphinx.js?v=d6bdf5f8:163

   GET https://output.circle-artifacts.com/output/job/048f37f1-2a97-4826-b310-3c66a77deb9c/artifacts/0/doc/build/html/try_examples.json?cb=1734970953567 404 (Not Found)

window.loadTryExamplesConfig @ jupyterlite_sphinx.js?v=d6bdf5f8:163 (anonymous) @ skimage.measure.html:1299 jupyterlite_sphinx.js?v=d6bdf5f8:167 Optional try_examples config file not found. jupyterlite_sphinx.js?v=d6bdf5f8:163

   GET https://output.circle-artifacts.com/output/job/048f37f1-2a97-4826-b310-3c66a77deb9c/artifacts/0/doc/build/html/try_examples.json?cb=1734970953567 404 (Not Found)

window.loadTryExamplesConfig @ jupyterlite_sphinx.js?v=d6bdf5f8:163 (anonymous) @ skimage.measure.html:1723 jupyterlite_sphinx.js?v=d6bdf5f8:167 Optional try_examples config file not found. jupyterlite_sphinx.js?v=d6bdf5f8:163

   GET https://output.circle-artifacts.com/output/job/048f37f1-2a97-4826-b310-3c66a77deb9c/artifacts/0/doc/build/html/try_examples.json?cb=1734970953567 404 (Not Found)

window.loadTryExamplesConfig @ jupyterlite_sphinx.js?v=d6bdf5f8:163 (anonymous) @ skimage.measure.html:1794 jupyterlite_sphinx.js?v=d6bdf5f8:167 Optional try_examples config file not found. jupyterlite_sphinx.js?v=d6bdf5f8:163

   GET https://output.circle-artifacts.com/output/job/048f37f1-2a97-4826-b310-3c66a77deb9c/artifacts/0/doc/build/html/try_examples.json?cb=1734970953567 404 (Not Found)

window.loadTryExamplesConfig @ jupyterlite_sphinx.js?v=d6bdf5f8:163 (anonymous) @ skimage.measure.html:1849 jupyterlite_sphinx.js?v=d6bdf5f8:167 Optional try_examples config file not found. jupyterlite_sphinx.js?v=d6bdf5f8:163

   GET https://output.circle-artifacts.com/output/job/048f37f1-2a97-4826-b310-3c66a77deb9c/artifacts/0/doc/build/html/try_examples.json?cb=1734970953567 404 (Not Found)

window.loadTryExamplesConfig @ jupyterlite_sphinx.js?v=d6bdf5f8:163 (anonymous) @ skimage.measure.html:1929 jupyterlite_sphinx.js?v=d6bdf5f8:167 Optional try_examples config file not found. jupyterlite_sphinx.js?v=d6bdf5f8:163

   GET https://output.circle-artifacts.com/output/job/048f37f1-2a97-4826-b310-3c66a77deb9c/artifacts/0/doc/build/html/try_examples.json?cb=1734970953567 404 (Not Found)

window.loadTryExamplesConfig @ jupyterlite_sphinx.js?v=d6bdf5f8:163 (anonymous) @ skimage.measure.html:1995 jupyterlite_sphinx.js?v=d6bdf5f8:167 Optional try_examples config file not found. jupyterlite_sphinx.js?v=d6bdf5f8:163

   GET https://output.circle-artifacts.com/output/job/048f37f1-2a97-4826-b310-3c66a77deb9c/artifacts/0/doc/build/html/try_examples.json?cb=1734970953567 404 (Not Found)

window.loadTryExamplesConfig @ jupyterlite_sphinx.js?v=d6bdf5f8:163 (anonymous) @ skimage.measure.html:2063 jupyterlite_sphinx.js?v=d6bdf5f8:167 Optional try_examples config file not found. jupyterlite_sphinx.js?v=d6bdf5f8:163

   GET https://output.circle-artifacts.com/output/job/048f37f1-2a97-4826-b310-3c66a77deb9c/artifacts/0/doc/build/html/try_examples.json?cb=1734970953567 404 (Not Found)

window.loadTryExamplesConfig @ jupyterlite_sphinx.js?v=d6bdf5f8:163 (anonymous) @ skimage.measure.html:2203 jupyterlite_sphinx.js?v=d6bdf5f8:167 Optional try_examples config file not found. jupyterlite_sphinx.js?v=d6bdf5f8:163

   GET https://output.circle-artifacts.com/output/job/048f37f1-2a97-4826-b310-3c66a77deb9c/artifacts/0/doc/build/html/try_examples.json?cb=1734970953567 404 (Not Found)

window.loadTryExamplesConfig @ jupyterlite_sphinx.js?v=d6bdf5f8:163 (anonymous) @ skimage.measure.html:2271 jupyterlite_sphinx.js?v=d6bdf5f8:167 Optional try_examples config file not found. jupyterlite_sphinx.js?v=d6bdf5f8:163

   GET https://output.circle-artifacts.com/output/job/048f37f1-2a97-4826-b310-3c66a77deb9c/artifacts/0/doc/build/html/try_examples.json?cb=1734970953567 404 (Not Found)

window.loadTryExamplesConfig @ jupyterlite_sphinx.js?v=d6bdf5f8:163 (anonymous) @ skimage.measure.html:2400 jupyterlite_sphinx.js?v=d6bdf5f8:167 Optional try_examples config file not found. jupyterlite_sphinx.js?v=d6bdf5f8:163

   GET https://output.circle-artifacts.com/output/job/048f37f1-2a97-4826-b310-3c66a77deb9c/artifacts/0/doc/build/html/try_examples.json?cb=1734970953567 404 (Not Found)

window.loadTryExamplesConfig @ jupyterlite_sphinx.js?v=d6bdf5f8:163 (anonymous) @ skimage.measure.html:2579 jupyterlite_sphinx.js?v=d6bdf5f8:167 Optional try_examples config file not found. jupyterlite_sphinx.js?v=d6bdf5f8:163

   GET https://output.circle-artifacts.com/output/job/048f37f1-2a97-4826-b310-3c66a77deb9c/artifacts/0/doc/build/html/try_examples.json?cb=1734970953567 404 (Not Found)

window.loadTryExamplesConfig @ jupyterlite_sphinx.js?v=d6bdf5f8:163 (anonymous) @ skimage.measure.html:2863 jupyterlite_sphinx.js?v=d6bdf5f8:167 Optional try_examples config file not found. jupyterlite_sphinx.js?v=d6bdf5f8:163

   GET https://output.circle-artifacts.com/output/job/048f37f1-2a97-4826-b310-3c66a77deb9c/artifacts/0/doc/build/html/try_examples.json?cb=1734970953567 404 (Not Found)

window.loadTryExamplesConfig @ jupyterlite_sphinx.js?v=d6bdf5f8:163 (anonymous) @ skimage.measure.html:3007 jupyterlite_sphinx.js?v=d6bdf5f8:167 Optional try_examples config file not found.

agriyakhetarpal avatar Dec 23 '24 16:12 agriyakhetarpal

That would be there:

jupyterlite_sphinx/jupyterlite_sphinx.js
152:window.loadTryExamplesConfig = async (configFilePath) => {

As far as I can tell we are explicitly retrying on fail:

window.loadTryExamplesConfig = async (configFilePath) => {
  if (tryExamplesConfigLoaded) {
    return;
  }
  try {
    // Add a timestamp as query parameter to ensure a cached version of the
    // file is not used.

But we can likely add a throttled / batched version, or if 404, mark as loaded = true, note that regardless we may want to batched, as it is likely we trigger concurent requests as this is an async function.

Carreau avatar Jan 06 '25 09:01 Carreau

Thanks for the suggestion – I've assigned myself to the issue as I have a throttled version ready which seems to do the job.

agriyakhetarpal avatar Jan 10 '25 01:01 agriyakhetarpal

Adding for completeness as to why I modified the milestone: see @gabalafou's review in https://github.com/jupyterlite/jupyterlite-sphinx/pull/249#pullrequestreview-2560026476 on #249.

We can make changes across the following lines:

https://github.com/jupyterlite/jupyterlite-sphinx/blob/7702294bb97dba7451c97f96c1d4ed5919a84275/jupyterlite_sphinx/jupyterlite_sphinx.py#L899-L907

so that the iframes can load the contents of the try_examples.json file (if it exists) that has been loaded into the browser's memory via another function, instead of each iframe trying to load it every time and making several requests across the page where there exist multiple iframes.

agriyakhetarpal avatar Feb 14 '25 18:02 agriyakhetarpal