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 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__/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(/__ERROR__/g, stringify(posixify(`${path_to_routes}/_error.html`), false))
.replace(/__IGNORE__/g, `[${server_routes_to_ignore.map(route => route.pattern).join(', ')}]`) .replace(/__IGNORE__/g, `[${server_routes_to_ignore.map(route => route.pattern).join(', ')}]`)
.replace(/__COMPONENTS__/g, components) .replace(/__COMPONENTS__/g, components)

View File

@@ -6,3 +6,5 @@ export const stores = {
}; };
export const CONTEXT_KEY = {}; export const CONTEXT_KEY = {};
export const preload = () => ({});

View File

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