Skip to content

WebContainer integration #54

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

Merged
merged 15 commits into from
Jun 10, 2022
Merged

WebContainer integration #54

merged 15 commits into from
Jun 10, 2022

Conversation

Rich-Harris
Copy link
Member

Work-in-progress! Closes #2.

This creates a WebContainer, using @webcontainer/api, populates its filesystem, installs dependencies and calls npm run dev. For some reason the server-ready event isn't firing — need to investigate why.

Monaco workers are failing to load, probably because of the COOP/COEP headers. Remains to be seen if that will be fatal in production.

Am also seeing this — it's not possible to load <iframe src="https://github.com/loading.html"> apparently

image

@Rich-Harris
Copy link
Member Author

The issue was that third party cookies were blocked. Will need to add some messaging directing people to allow cookies.

On main, the app fetches modules from the Vite dev server so that it can compare what you've written with what's expected (without doing a brittle byte-for-byte comparison). That fails on this branch, because of the cross-origin fetch. Not sure if there's a way to work around that (could we make the Vite dev server add the relevant headers, and if so would that work?) — need to investigate.

@Rich-Harris
Copy link
Member Author

Some more breadcrumbs: the files fail to fetch initially, but are later fetched just fine via the webcontainer's service worker:

image

I wonder if this is just an order-of-operations thing — maybe the service worker isn't registered at the point we first try to fetch those files from the Vite dev server?

@Rich-Harris
Copy link
Member Author

This is what happens when a module imports App.svelte (which has a URL like https://localhost3000-2yz4--3005.local-corp.webcontainer.io/src/lib/App.svelte):

image

This is what happens when we fetch the same file:

image

By the time this fails, the service worker is already registered. Not sure why the request is going to Cloudfront instead of being handled by the worker.

@Rich-Harris Rich-Harris mentioned this pull request Jun 10, 2022
@vercel
Copy link

vercel bot commented Jun 10, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
learn-svelte-dev ✅ Ready (Inspect) Visit Preview Jun 10, 2022 at 8:43PM (UTC)

@Rich-Harris
Copy link
Member Author

holy shit it works! https://learn-svelte-n9hbykwwx-svelte.vercel.app/tutorial/welcome-to-svelte

I'm going to merge this, then open issues for the remaining TODOs

@Rich-Harris Rich-Harris merged commit ce9156f into main Jun 10, 2022
@Rich-Harris Rich-Harris deleted the gh-2 branch June 10, 2022 20:47
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

Successfully merging this pull request may close these issues.

Integrate WebContainers
2 participants