Skip to content

Commit 4717856

Browse files
committed
[fix] signal that pings pause prio to alert opening
Fixes sveltejs#126
1 parent d4ef7c9 commit 4717856

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

content/tutorial/common/src/__client.js

+17-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
// Hack into the alert that's used in some tutorials and send a message prior to the alert,
2+
// else the parent thinks we lost contact and wrongfully reloads the page.
3+
// The drawback is that alert is no longer blocking, but no tutorial relies on this.
4+
const alert = window.alert;
5+
window.alert = (message) => {
6+
parent.postMessage(
7+
{
8+
type: 'ping-pause'
9+
},
10+
'*'
11+
);
12+
setTimeout(() => {
13+
alert(message);
14+
});
15+
};
16+
117
window.addEventListener('message', async (e) => {
218
if (e.data.type === 'fetch') {
319
const names = e.data.names;
@@ -59,7 +75,7 @@ function ping() {
5975
);
6076
}
6177

62-
setInterval(ping, 50);
78+
setInterval(ping, 100);
6379
ping();
6480

6581
if (import.meta.hot) {

src/routes/tutorial/[slug]/+page.svelte

+4-2
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@
254254
if (e.origin !== adapter.base) return;
255255
256256
if (e.data.type === 'ping') {
257-
path = e.data.data.path;
257+
path = e.data.data.path ?? path;
258258
259259
clearTimeout(timeout);
260260
timeout = setTimeout(() => {
@@ -264,7 +264,9 @@
264264
loading = true;
265265
set_iframe_src(adapter.base + path);
266266
loading = false;
267-
}, 500);
267+
}, 1000);
268+
} else if (e.data.type === 'ping-pause') {
269+
clearTimeout(timeout);
268270
}
269271
}
270272

0 commit comments

Comments
 (0)