This commit is contained in:
Richard Harris
2019-02-02 13:01:55 -05:00
parent 85c86b5562
commit b7fce99438
3 changed files with 14 additions and 18 deletions

View File

@@ -153,6 +153,7 @@ function generate_client(
return `// This file is generated by Sapper — do not edit it!\n` + template
.replace(/__ROOT__/g, stringify(get_file(path_to_routes, manifest_data.root), false))
.replace(/__ROOT_PRELOAD__/g, manifest_data.root.has_preload ? stringify(get_file(path_to_routes, manifest_data.root), false) : './internal')
.replace(/__ERROR__/g, stringify(posixify(`${path_to_routes}/_error.html`), false))
.replace(/__IGNORE__/g, `[${server_routes_to_ignore.map(route => route.pattern).join(', ')}]`)
.replace(/__COMPONENTS__/g, components)

View File

@@ -5,4 +5,6 @@ export const stores = {
page: writable(null)
};
export const CONTEXT_KEY = {};
export const CONTEXT_KEY = {};
export const preload = () => ({});

View File

@@ -1,6 +1,7 @@
import App from '@sapper/App.html';
import { stores } from '@sapper/internal';
import Root, * as RootStatic from '__ROOT__';
import Root from '__ROOT__';
import { preload as root_preload } from '__ROOT_PRELOAD__';
import ErrorComponent from '__ERROR__';
import {
Target,
@@ -24,8 +25,7 @@ export const routes: Route[] = __PAGES__;
let ready = false;
let root_component: Component;
let current_token: {};
let root_preload: Promise<any>;
let root_data: any;
let root_preloaded: Promise<any>;
let current_branch = [];
export let prefetching: {
@@ -171,8 +171,6 @@ async function render(branch: any[], props: any, page: Page, scroll: ScrollPosit
detach(end);
}
Object.assign(props, root_data); // TODO what is root_data, do we still need it?
root_component = new App({
target,
props: {
@@ -230,15 +228,12 @@ export async function hydrate_target(target: Target): Promise<{
}
};
if (!root_preload) {
const preload_fn = RootStatic['pre' + 'load']; // Rollup makes us jump through these hoops :(
root_preload = preload_fn
? initial_data.preloaded[0] || preload_fn.call(preload_context, {
path,
query,
params: {}
})
: {};
if (!root_preloaded) {
root_preloaded = initial_data.preloaded[0] || root_preload.call(preload_context, {
path,
query,
params: {}
});
}
let branch;
@@ -272,8 +267,6 @@ export async function hydrate_target(target: Target): Promise<{
branch = [];
}
if (!root_data) root_data = await root_preload;
if (redirect) return { redirect };
const page_data = {
@@ -298,7 +291,7 @@ export async function hydrate_target(target: Target): Promise<{
};
}
const props = { child: {} };
const props = Object.assign({}, await root_preloaded, { child: {} });
let level = props.child;
branch.forEach(node => {