mirror of
https://github.com/kevin-DL/sapper.git
synced 2026-01-18 21:45:12 +00:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e837b33c36 |
@@ -121,7 +121,7 @@ export function select_target(url: URL): Target {
|
|||||||
const part = route.parts[route.parts.length - 1];
|
const part = route.parts[route.parts.length - 1];
|
||||||
const params = part.params ? part.params(match) : {};
|
const params = part.params ? part.params(match) : {};
|
||||||
|
|
||||||
const page = { host: location.host, path, query, params };
|
const page = { path, query, params };
|
||||||
|
|
||||||
return { href: url.href, route, match, page };
|
return { href: url.href, route, match, page };
|
||||||
}
|
}
|
||||||
@@ -129,7 +129,7 @@ export function select_target(url: URL): Target {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function handle_error(url: URL) {
|
export function handle_error(url: URL) {
|
||||||
const { host, pathname, search } = location;
|
const { pathname, search } = location;
|
||||||
const { session, preloaded, status, error } = initial_data;
|
const { session, preloaded, status, error } = initial_data;
|
||||||
|
|
||||||
if (!root_preloaded) {
|
if (!root_preloaded) {
|
||||||
@@ -154,7 +154,7 @@ export function handle_error(url: URL) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
const query = extract_query(search);
|
const query = extract_query(search);
|
||||||
render(null, [], props, { host, path: pathname, query, params: {} });
|
render(null, [], props, { path: pathname, query, params: {} });
|
||||||
}
|
}
|
||||||
|
|
||||||
export function scroll_state() {
|
export function scroll_state() {
|
||||||
@@ -301,7 +301,6 @@ export async function hydrate_target(target: Target): Promise<{
|
|||||||
|
|
||||||
if (!root_preloaded) {
|
if (!root_preloaded) {
|
||||||
root_preloaded = initial_data.preloaded[0] || root_preload.call(preload_context, {
|
root_preloaded = initial_data.preloaded[0] || root_preload.call(preload_context, {
|
||||||
host: page.host,
|
|
||||||
path: page.path,
|
path: page.path,
|
||||||
query: page.query,
|
query: page.query,
|
||||||
params: {}
|
params: {}
|
||||||
@@ -339,7 +338,6 @@ export async function hydrate_target(target: Target): Promise<{
|
|||||||
if (ready || !initial_data.preloaded[i + 1]) {
|
if (ready || !initial_data.preloaded[i + 1]) {
|
||||||
preloaded = preload
|
preloaded = preload
|
||||||
? await preload.call(preload_context, {
|
? await preload.call(preload_context, {
|
||||||
host: page.host,
|
|
||||||
path: page.path,
|
path: page.path,
|
||||||
query: page.query,
|
query: page.query,
|
||||||
params: part.params ? part.params(target.match) : {}
|
params: part.params ? part.params(target.match) : {}
|
||||||
|
|||||||
@@ -56,7 +56,6 @@ export type Redirect = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export type Page = {
|
export type Page = {
|
||||||
host: string;
|
|
||||||
path: string;
|
path: string;
|
||||||
params: Record<string, string>;
|
params: Record<string, string>;
|
||||||
query: Record<string, string | string[]>;
|
query: Record<string, string | string[]>;
|
||||||
|
|||||||
@@ -149,7 +149,6 @@ export function get_page_handler(
|
|||||||
try {
|
try {
|
||||||
const root_preloaded = manifest.root_preload
|
const root_preloaded = manifest.root_preload
|
||||||
? manifest.root_preload.call(preload_context, {
|
? manifest.root_preload.call(preload_context, {
|
||||||
host: req.headers.host,
|
|
||||||
path: req.path,
|
path: req.path,
|
||||||
query: req.query,
|
query: req.query,
|
||||||
params: {}
|
params: {}
|
||||||
@@ -169,7 +168,6 @@ export function get_page_handler(
|
|||||||
|
|
||||||
return part.preload
|
return part.preload
|
||||||
? part.preload.call(preload_context, {
|
? part.preload.call(preload_context, {
|
||||||
host: req.headers.host,
|
|
||||||
path: req.path,
|
path: req.path,
|
||||||
query: req.query,
|
query: req.query,
|
||||||
params
|
params
|
||||||
@@ -220,7 +218,6 @@ export function get_page_handler(
|
|||||||
stores: {
|
stores: {
|
||||||
page: {
|
page: {
|
||||||
subscribe: writable({
|
subscribe: writable({
|
||||||
host: req.headers.host,
|
|
||||||
path: req.path,
|
path: req.path,
|
||||||
query: req.query,
|
query: req.query,
|
||||||
params
|
params
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ It lives in a `context="module"` script — see the [tutorial](https://svelte.de
|
|||||||
|
|
||||||
The `preload` function receives two arguments — `page` and `session`.
|
The `preload` function receives two arguments — `page` and `session`.
|
||||||
|
|
||||||
`page` is a `{ host, path, params, query }` object where `host` is the URL's host, `path` is its pathname, `params` is derived from `path` and the route filename, and `query` is an object of values in the query string.
|
`page` is a `{ path, params, query }` object where `path` is the URL's pathname, `params` is derived from `path` and the route filename, and `query` is an object of values in the query string.
|
||||||
|
|
||||||
So if the example above was `src/routes/blog/[slug].svelte` and the URL was `/blog/some-post?foo=bar&baz`, the following would be true:
|
So if the example above was `src/routes/blog/[slug].svelte` and the URL was `/blog/some-post?foo=bar&baz`, the following would be true:
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ Inside a component, get references to the stores like so:
|
|||||||
```
|
```
|
||||||
|
|
||||||
* `preloading` contains a readonly boolean value, indicating whether or not a navigation is pending
|
* `preloading` contains a readonly boolean value, indicating whether or not a navigation is pending
|
||||||
* `page` contains a readonly `{ host, path, params, query }` object, identical to that passed to `preload` functions
|
* `page` contains a readonly `{ path, params, query }` object, identical to that passed to `preload` functions
|
||||||
* `session` contains whatever data was seeded on the server. It is a [writable store](https://svelte.dev/tutorial/writable-stores), meaning you can update it with new data (for example, after the user logs in) and your app will be refreshed
|
* `session` contains whatever data was seeded on the server. It is a [writable store](https://svelte.dev/tutorial/writable-stores), meaning you can update it with new data (for example, after the user logs in) and your app will be refreshed
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ type Opts = {
|
|||||||
cwd?: string,
|
cwd?: string,
|
||||||
static?: string,
|
static?: string,
|
||||||
basepath?: string,
|
basepath?: string,
|
||||||
host_header?: string,
|
|
||||||
timeout?: number | false,
|
timeout?: number | false,
|
||||||
concurrent?: number,
|
concurrent?: number,
|
||||||
oninfo?: ({ message }: { message: string }) => void;
|
oninfo?: ({ message }: { message: string }) => void;
|
||||||
@@ -45,7 +44,6 @@ async function _export({
|
|||||||
build_dir = '__sapper__/build',
|
build_dir = '__sapper__/build',
|
||||||
export_dir = '__sapper__/export',
|
export_dir = '__sapper__/export',
|
||||||
basepath = '',
|
basepath = '',
|
||||||
host_header,
|
|
||||||
timeout = 5000,
|
timeout = 5000,
|
||||||
concurrent = 8,
|
concurrent = 8,
|
||||||
oninfo = noop,
|
oninfo = noop,
|
||||||
@@ -142,7 +140,6 @@ async function _export({
|
|||||||
|
|
||||||
const r = await Promise.race([
|
const r = await Promise.race([
|
||||||
fetch(url.href, {
|
fetch(url.href, {
|
||||||
headers: { host: host_header || host },
|
|
||||||
redirect: 'manual'
|
redirect: 'manual'
|
||||||
}),
|
}),
|
||||||
timeout_deferred.promise
|
timeout_deferred.promise
|
||||||
|
|||||||
@@ -194,7 +194,6 @@ prog.command('export [dest]')
|
|||||||
.describe('Export your app as static files (if possible)')
|
.describe('Export your app as static files (if possible)')
|
||||||
.option('--build', '(Re)build app before exporting', true)
|
.option('--build', '(Re)build app before exporting', true)
|
||||||
.option('--basepath', 'Specify a base path')
|
.option('--basepath', 'Specify a base path')
|
||||||
.option('--host', 'Host header to use when crawling site')
|
|
||||||
.option('--concurrent', 'Concurrent requests', 8)
|
.option('--concurrent', 'Concurrent requests', 8)
|
||||||
.option('--timeout', 'Milliseconds to wait for a page (--no-timeout to disable)', 5000)
|
.option('--timeout', 'Milliseconds to wait for a page (--no-timeout to disable)', 5000)
|
||||||
.option('--legacy', 'Create separate legacy build')
|
.option('--legacy', 'Create separate legacy build')
|
||||||
@@ -211,7 +210,6 @@ prog.command('export [dest]')
|
|||||||
legacy: boolean,
|
legacy: boolean,
|
||||||
bundler?: 'rollup' | 'webpack',
|
bundler?: 'rollup' | 'webpack',
|
||||||
basepath?: string,
|
basepath?: string,
|
||||||
host?: string,
|
|
||||||
concurrent: number,
|
concurrent: number,
|
||||||
timeout: number | false,
|
timeout: number | false,
|
||||||
cwd: string,
|
cwd: string,
|
||||||
@@ -238,7 +236,6 @@ prog.command('export [dest]')
|
|||||||
build_dir: opts['build-dir'],
|
build_dir: opts['build-dir'],
|
||||||
export_dir: dest,
|
export_dir: dest,
|
||||||
basepath: opts.basepath,
|
basepath: opts.basepath,
|
||||||
host_header: opts.host,
|
|
||||||
timeout: opts.timeout,
|
timeout: opts.timeout,
|
||||||
concurrent: opts.concurrent,
|
concurrent: opts.concurrent,
|
||||||
|
|
||||||
@@ -265,7 +262,7 @@ prog.command('export [dest]')
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
prog.parse(process.argv);
|
prog.parse(process.argv, { unknown: (arg: string) => `Unknown option: ${arg}` });
|
||||||
|
|
||||||
|
|
||||||
async function _build(
|
async function _build(
|
||||||
|
|||||||
@@ -1,6 +0,0 @@
|
|||||||
<script>
|
|
||||||
import { stores } from '@sapper/app';
|
|
||||||
const { page } = stores();
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<h1>{$page.host.replace(/:\d+$/, '')}</h1>
|
|
||||||
@@ -239,15 +239,6 @@ describe('basics', function() {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('can access host through page store', async () => {
|
|
||||||
await r.load('/host');
|
|
||||||
|
|
||||||
assert.equal(await r.text('h1'), 'localhost');
|
|
||||||
|
|
||||||
await r.sapper.start();
|
|
||||||
assert.equal(await r.text('h1'), 'localhost');
|
|
||||||
});
|
|
||||||
|
|
||||||
// skipped because Nightmare doesn't seem to focus the <a> correctly
|
// skipped because Nightmare doesn't seem to focus the <a> correctly
|
||||||
it('resets the active element after navigation', async () => {
|
it('resets the active element after navigation', async () => {
|
||||||
await r.load('/');
|
await r.load('/');
|
||||||
|
|||||||
@@ -1,13 +0,0 @@
|
|||||||
<script context="module">
|
|
||||||
export function preload(page) {
|
|
||||||
return {
|
|
||||||
host: page.host
|
|
||||||
};
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
export let host;
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<h1>{host.replace(/:\d+$/, '')}</h1>
|
|
||||||
@@ -27,15 +27,6 @@ describe('preloading', function() {
|
|||||||
assert.equal(await r.text('h1'), 'true');
|
assert.equal(await r.text('h1'), 'true');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('retrieves host from preload', async () => {
|
|
||||||
await r.load('/preload-values/host');
|
|
||||||
|
|
||||||
assert.equal(await r.text('h1'), 'localhost');
|
|
||||||
|
|
||||||
await r.sapper.start();
|
|
||||||
assert.equal(await r.text('h1'), 'localhost');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('prevent crash if preload return nothing', async () => {
|
it('prevent crash if preload return nothing', async () => {
|
||||||
await r.load('/preload-nothing');
|
await r.load('/preload-nothing');
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user