Skip to content

Commit 9b19caf

Browse files
authored
fix: prevent ios from loading webcontainers (#584)
1 parent 01f8718 commit 9b19caf

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

src/routes/tutorial/[slug]/Loading.svelte

+30-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<script>
2-
import { afterNavigate } from '$app/navigation';
32
import { page } from '$app/stores';
43
import { Icon } from '@sveltejs/site-kit/components';
4+
import { load_webcontainer, reset } from './adapter';
5+
import { files } from './state';
56
67
/** @type {boolean} */
78
export let initial;
@@ -62,6 +63,23 @@
6263
<code>chrome://settings/cookies</code> and add <code>learn.svelte.dev</code> to 'Sites that
6364
can always use cookies'.
6465
</p>
66+
<!-- TODO: remove this when webcontainers are properly supported on iOS
67+
see https://github.com/stackblitz/webcontainer-core/issues/1120 -->
68+
{:else if /iphone/i.test(navigator.userAgent)}
69+
<p>
70+
We couldn't start the app. It seems that you're using iOS, which does not support
71+
WebContainers.
72+
</p>
73+
<p>
74+
If this is not the case, you can try loading it by <button
75+
type="button"
76+
on:click={async () => {
77+
error = null;
78+
load_webcontainer();
79+
await reset($files);
80+
}}>clicking here</button
81+
>.
82+
</p>
6583
{:else}
6684
<p>
6785
We couldn't start the app. Please ensure third party cookies are enabled for this site.
@@ -70,7 +88,7 @@
7088

7189
{#if is_svelte}
7290
<a href="https://svelte.dev/tutorial/{$page.data.exercise.slug}">
73-
Go to the legacy svelte tutorial instead <Icon name="arrow-right" />
91+
Or go to the legacy svelte tutorial instead <Icon name="arrow-right" />
7492
</a>
7593
{/if}
7694
</div>
@@ -148,6 +166,16 @@
148166
margin: 0 0 1em 0;
149167
}
150168
169+
button {
170+
color: var(--sk-theme-1);
171+
padding: 0 0 1px;
172+
position: relative;
173+
}
174+
175+
button:hover {
176+
text-decoration: underline;
177+
}
178+
151179
small {
152180
font-size: var(--sk-text-xs);
153181
color: var(--sk-text-3);

src/routes/tutorial/[slug]/adapter.js

+13
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,22 @@ export const warnings = writable({});
2121
/** @type {Promise<import('$lib/types').Adapter>} */
2222
let ready = new Promise(() => {});
2323

24+
let initial_load = true;
25+
2426
if (browser) {
27+
load_webcontainer();
28+
initial_load = false;
29+
}
30+
31+
export function load_webcontainer() {
2532
ready = new Promise(async (fulfil, reject) => {
2633
try {
34+
// TODO: remove this when webcontainers are properly supported on iOS
35+
// see https://github.com/stackblitz/webcontainer-core/issues/1120
36+
if (initial_load && /iphone/i.test(navigator.userAgent)) {
37+
throw new Error('iOS does not support WebContainers');
38+
}
39+
2740
const module = await import('$lib/client/adapters/webcontainer/index.js');
2841
const adapter = await module.create(base, error, progress, logs, warnings);
2942

0 commit comments

Comments
 (0)