Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[unified-server] Dev mode requests for inline JS fail #4342

Open
timswanson-google opened this issue Feb 3, 2025 · 2 comments
Open

[unified-server] Dev mode requests for inline JS fail #4342

timswanson-google opened this issue Feb 3, 2025 · 2 comments

Comments

@timswanson-google
Copy link
Member

timswanson-google commented Feb 3, 2025

The Unified Server shows a blank page when running in dev mode. The page JS is never getting loaded due to the way Vite-Express handles the request for inline JS.


In its current form, the index.html for the unified server contains an inline script.1

https://github.com/breadboard-ai/breadboard/blob/4904e2a6b5cc486b722fe38b4fbf7f21408922a2/packages/unified-server/index.html

In production mode, this works fine. The JS is built into the compiled HTML and everything works as expected.

In dev mode, however, the Vite dev server moves the inline script into a JS file with a URL that looks like this:

/@id/__x00__/<repo-path>/index.html?html-proxy&index=0.js

The 0.js is a reference to the "first inline JS block in the HTML file". Vite extracts this script from the HTML and serves it separately. Presumably to enable things like hot module reload.

Vite-Express does not handle these URLs correctly. Instead, they fall through to the static routing logic, and index.html is returned again. Since the browser expects JS and gets HTML, it logs this error:

Failed to load module script: Expected a JavaScript module script
but the server responded with a MIME type of "text/html".
Strict MIME type checking is enforced for module scripts per HTML spec.

The JS is never loaded or executed, so the resulting page is blank.


In the board-server package, we have a hand-written handler for these requests that defer explicitly to the Vite dev server:

if (pathname.endsWith(".html") && !req.url?.includes("?html-proxy")) {

However, it doesn't look like Vite-Express has any such logic.

Need to dig into why this is happening and what can be done about it.

Footnotes

  1. This script was copied more-or-less verbatim from the same file in visual-editor. This is fine for the initial build-out, but will be a maintenance issue going forward, and a separate issue has been created to address it. [unified-server] Create a common bootstrap page for the visual editor #4350

timswanson-google added a commit to timswanson-google/vite-express-example that referenced this issue Feb 4, 2025
@timswanson-google
Copy link
Member Author

I've filed an issue with the Vite-Express project to see if this is a known issue or if there's something we can do to configure it.

szymmis/vite-express#158

dglazkov added a commit that referenced this issue Feb 9, 2025
- **Move initialization code out of `index.html` and make
`unified-server` work in dev mode.**
- **Teach `remote-board-server` some more about unified server URLs.**
- **Teach unified server to load assets.**
- **Fix build.**
- **docs(changeset): Make unified server run in dev mode.**

Progress on #4342.
@dglazkov
Copy link
Collaborator

This is now kind of fixed for us, since I moved all the inline code out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants