webR: synchronous metadata.rds probe re-runs on every app start and 404s

Open
#237 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
52/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Quiet
Tech stack
typescript

Research direction

Start in src/hooks/useWebR.tsx:274-287 at .mount_vfs_images() and trace how metadata_url and the probe result are used during app startup. Check the examples smoke test from #236 while switching examples to confirm the request is not repeated, that the fallback still works for a 404, and that startup is no longer blocked by the synchronous probe.

Written by the indexing model from the issue text.

Description

What

Every R app start fires a synchronous HEAD request for shinylive/webr/packages/metadata.rds, which 404s on shinylive's own build. Found while building the examples smoke test (#236) — it shows up once per R example in the CI logs:

[WebServer] "HEAD /r/shinylive/webr/packages/metadata.rds HTTP/1.1" 404 -

Where

src/hooks/useWebR.tsx:274-287, in .mount_vfs_images():

found <- webr::eval_js(glue::glue("
  var xhr = new XMLHttpRequest();
  xhr.open('HEAD', '{metadata_url}', false);
  xhr.send();
  (xhr.status >= 200 && xhr.status < 300)
"))

Why this isn't just log noise

The 404 itself is by design — the comment says as much ("Attempt this download quietly, if no metadata exists we can still continue"), and the fallback works correctly. Two things still look worth a second look:

  1. The XHR is synchronous (xhr.open(..., false)), so it blocks the webR worker thread for a full network round trip during app startup.

  2. It re-probes on every app start, not once per session. Measured in a warm session by counting requests while switching examples:

    after boot + first app:        1
    after switching to Shiny Text: 2
    after switching to Reactivity: 3
    after switching to Sliders:    4
    

    The result cannot change within a session, so runs 2..n are pure overhead on a path users wait on.

metadata.rds is presumably present in deployments that ship prebuilt VFS package images; it is absent from the build this repo produces, so shinylive.io pays the miss every time.

Suggested fix

Cache the probe result for the lifetime of the session, and make the request async if the surrounding code allows it. If metadata.rds is never expected in this repo's own build, skipping the probe unless something opts in would avoid it entirely.

Not blocking anything

webR swallows the 404 without raising a console error, so it does not fail the new smoke test and no example is broken by it. Filing separately per discussion on #236.

Dominant language
TypeScript
Stars
253
Forks
25
Avg merge
6d 22h
Merged PRs (30d)
13

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from posit-dev/shinylive

All issues in posit-dev/shinylive

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.