Skip to content
This repository was archived by the owner on Jan 11, 2023. It is now read-only.

Commit 971342a

Browse files
committed
set preloading: true when appropriate
1 parent 3becc1c commit 971342a

File tree

3 files changed

+45
-14
lines changed

3 files changed

+45
-14
lines changed

src/runtime/index.ts

+16-13
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,20 @@ function select_route(url: URL): Target {
4949
}
5050
}
5151

52-
let first_load = true;
5352
let current_token: {};
5453

5554
function render(Page: ComponentConstructor, props: any, scroll: ScrollPosition, token: {}) {
5655
if (current_token !== token) return;
5756

58-
if (first_load) {
57+
const data = {
58+
Page,
59+
props,
60+
preloading: false
61+
};
62+
63+
if (component) {
64+
component.set(data);
65+
} else {
5966
// first load — remove SSR'd <head> contents
6067
const start = document.querySelector('#sapper-head-start');
6168
const end = document.querySelector('#sapper-head-end');
@@ -68,20 +75,10 @@ function render(Page: ComponentConstructor, props: any, scroll: ScrollPosition,
6875

6976
component = new App({
7077
target,
71-
data: {
72-
Page,
73-
props
74-
},
78+
data,
7579
store,
7680
hydrate: true
7781
});
78-
79-
first_load = false;
80-
} else {
81-
component.set({
82-
Page,
83-
props
84-
});
8582
}
8683

8784
if (scroll) {
@@ -101,6 +98,12 @@ function prepare_route(Page: ComponentConstructor, props: RouteData) {
10198
return { Page, props: Object.assign(props, manifest.preloaded), redirect, error };
10299
}
103100

101+
if (component) {
102+
component.set({
103+
preloading: true
104+
});
105+
}
106+
104107
return Promise.resolve(Page.preload.call({
105108
store,
106109
fetch: (url: string, opts?: any) => window.fetch(url, opts),

test/app/app/App.html

+6-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
1-
<svelte:component this={Page} {...props}/>
1+
{#if preloading}
2+
<progress class='preloading-progress' value=0.5/>
3+
{/if}
4+
5+
<svelte:component this={Page} {...props}/>
6+

test/common/test.js

+23
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,29 @@ function run({ mode, basepath = '' }) {
574574
assert.ok(html.indexOf('service-worker.js') !== -1);
575575
});
576576
});
577+
578+
it('sets preloading true when appropriate', () => {
579+
return nightmare
580+
.goto(base)
581+
.init()
582+
.click('a[href="slow-preload"]')
583+
.wait(100)
584+
.evaluate(() => {
585+
const progress = document.querySelector('progress');
586+
return !!progress;
587+
})
588+
.then(hasProgressIndicator => {
589+
assert.ok(hasProgressIndicator);
590+
})
591+
.then(() => nightmare.evaluate(() => window.fulfil()))
592+
.then(() => nightmare.evaluate(() => {
593+
const progress = document.querySelector('progress');
594+
return !!progress;
595+
}))
596+
.then(hasProgressIndicator => {
597+
assert.ok(!hasProgressIndicator);
598+
});
599+
});
577600
});
578601

579602
describe('headers', () => {

0 commit comments

Comments
 (0)