File tree 2 files changed +21
-3
lines changed
content/tutorial/common/src
src/routes/tutorial/[slug]
2 files changed +21
-3
lines changed Original file line number Diff line number Diff line change
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
+
1
17
window . addEventListener ( 'message' , async ( e ) => {
2
18
if ( e . data . type === 'fetch' ) {
3
19
const names = e . data . names ;
@@ -59,7 +75,7 @@ function ping() {
59
75
) ;
60
76
}
61
77
62
- setInterval ( ping , 50 ) ;
78
+ setInterval ( ping , 100 ) ;
63
79
ping ( ) ;
64
80
65
81
if ( import . meta. hot ) {
Original file line number Diff line number Diff line change 254
254
if (e .origin !== adapter .base ) return ;
255
255
256
256
if (e .data .type === ' ping' ) {
257
- path = e .data .data .path ;
257
+ path = e .data .data .path ?? path ;
258
258
259
259
clearTimeout (timeout);
260
260
timeout = setTimeout (() => {
264
264
loading = true ;
265
265
set_iframe_src (adapter .base + path);
266
266
loading = false ;
267
- }, 500 );
267
+ }, 1000 );
268
+ } else if (e .data .type === ' ping-pause' ) {
269
+ clearTimeout (timeout);
268
270
}
269
271
}
270
272
You can’t perform that action at this time.
0 commit comments