Skip to content

Handle ready() without /index.html, as in the README examples #70

Closed

Description

@kazupon

Summary

  • Goal: A ready() without /index.html, as in the README examples, behaves the same in both Workers and as documented.
  • Current gap: The Web Worker writes a default /index.html during setup, but the Service Worker never gets one. The Service Worker serves the preview HTML from its own virtual filesystem, so a ready() without /index.html leaves the preview without HTML. The Web Worker's default is never served.
  • Effect:
  • Request: Decide whether a default index.html is part of the API. Then make both Workers and the README agree (see the options in Details).
  • Verification status: Reproduced in the browser by deleting /index.html in the vrowzer integration playground (see Details). The README example itself was not run.
  • Related: Found while working on Return 404 for missing preview files instead of fetching them from the host #68.

Details

Current implementation, verification, options, and acceptance criteria

Current implementation

Reviewed at cdac4cd.

  • The README usage example and the example in the ready() section pass no /index.html.
  • The Web Worker's setupVirtualFiles() writes a default /index.html with <div id="app"><p>Loading...</p></div> and <script type="module" src="/main.js"></script>, then writes the files given to ready(). It was added in 72ee3f0, a WIP commit with no stated reason.
  • The Service Worker's initServiceWorker() writes only the client files and /public/.gitkeep. The files given to ready() arrive later in V_FS_INIT (index.ts). No default /index.html reaches it.
  • The Service Worker serves the preview HTML from its own virtual filesystem. indexHtmlMiddleware moves on when the file is missing, and notFoundMiddleware answers with 404.
  • Every test fixture passes /index.html: the integration fixtures (playground, custom-base, dispose) explicitly, and the e2e fixtures through the vite-plugin manifest or explicitly. No test runs ready() without /index.html. The test added in #69 reproduces a missing preview HTML by loading /favicon.ico instead.

Verification

I ran temporary tests in packages/vrowzer/integration/vrowzer.integration-test.ts against the integration playground, in Playwright's Chromium. The tests deleted /index.html with deleteFile(), then mounted a new preview session. This leaves the Service Worker in the same state as a ready() without /index.html. The tests were not committed.

Options

  • A. Give the Service Worker the same default.
    • In initialize(), add the default /index.html to the files sent to both Workers when ready() has none. The default then lives in one place.
    • Or write the same default in service-worker-core.ts too. The default then lives in two places.
  • B. Require /index.html.
    • Remove the Web Worker's default, and add /index.html to the README examples.
    • Make ready() warn, or fail, without /index.html.
  • C. Only add /index.html to the README examples, and keep the Web Worker's default as it is.

The choice depends on whether a default index.html is part of the API. The README examples are currently written as if it were.

Acceptance criteria

  • Both Workers agree on /index.html when ready() gets none: both have the same default, or neither has one.
  • The README examples work as written.
  • The behavior without /index.html is documented: a default page is shown, or the missing file is reported clearly.
  • A browser test covers ready() without /index.html.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions