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

fix: prevent iOS from loading webcontainer module #584

Merged
merged 1 commit into from
Mar 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions src/routes/tutorial/[slug]/Loading.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<script>
import { afterNavigate } from '$app/navigation';
import { page } from '$app/stores';
import { Icon } from '@sveltejs/site-kit/components';
import { load_webcontainer, reset } from './adapter';
import { files } from './state';

/** @type {boolean} */
export let initial;
Expand Down Expand Up @@ -62,6 +63,23 @@
<code>chrome://settings/cookies</code> and add <code>learn.svelte.dev</code> to 'Sites that
can always use cookies'.
</p>
<!-- TODO: remove this when webcontainers are properly supported on iOS
see https://github.com/stackblitz/webcontainer-core/issues/1120 -->
{:else if /iphone/i.test(navigator.userAgent)}
<p>
We couldn't start the app. It seems that you're using iOS, which does not support
WebContainers.
</p>
<p>
If this is not the case, you can try loading it by <button
type="button"
on:click={async () => {
error = null;
load_webcontainer();
await reset($files);
}}>clicking here</button
>.
</p>
{:else}
<p>
We couldn't start the app. Please ensure third party cookies are enabled for this site.
Expand All @@ -70,7 +88,7 @@

{#if is_svelte}
<a href="https://svelte.dev/tutorial/{$page.data.exercise.slug}">
Go to the legacy svelte tutorial instead <Icon name="arrow-right" />
Or go to the legacy svelte tutorial instead <Icon name="arrow-right" />
</a>
{/if}
</div>
Expand Down Expand Up @@ -148,6 +166,16 @@
margin: 0 0 1em 0;
}

button {
color: var(--sk-theme-1);
padding: 0 0 1px;
position: relative;
}

button:hover {
text-decoration: underline;
}

small {
font-size: var(--sk-text-xs);
color: var(--sk-text-3);
Expand Down
13 changes: 13 additions & 0 deletions src/routes/tutorial/[slug]/adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,22 @@ export const warnings = writable({});
/** @type {Promise<import('$lib/types').Adapter>} */
let ready = new Promise(() => {});

let initial_load = true;

if (browser) {
load_webcontainer();
initial_load = false;
}

export function load_webcontainer() {
ready = new Promise(async (fulfil, reject) => {
try {
// TODO: remove this when webcontainers are properly supported on iOS
// see https://github.com/stackblitz/webcontainer-core/issues/1120
if (initial_load && /iphone/i.test(navigator.userAgent)) {
throw new Error('iOS does not support WebContainers');
}

const module = await import('$lib/client/adapters/webcontainer/index.js');
const adapter = await module.create(base, error, progress, logs, warnings);

Expand Down
Loading