@sveltejs/kit 1.0.0-next.271 → 1.0.0-next.275
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/assets/client/start.js +49 -27
- package/assets/server/index.js +15 -6
- package/dist/cli.js +2 -2
- package/package.json +1 -1
package/assets/client/start.js
CHANGED
|
@@ -83,6 +83,8 @@ class Router {
|
|
|
83
83
|
history.replaceState({ ...history.state, 'sveltekit:index': 0 }, '', location.href);
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
+
this.hash_navigating = false;
|
|
87
|
+
|
|
86
88
|
this.callbacks = {
|
|
87
89
|
/** @type {Array<({ from, to, cancel }: { from: URL, to: URL | null, cancel: () => void }) => void>} */
|
|
88
90
|
before_navigate: [],
|
|
@@ -210,9 +212,10 @@ class Router {
|
|
|
210
212
|
// Removing the hash does a full page navigation in the browser, so make sure a hash is present
|
|
211
213
|
const [base, hash] = url.href.split('#');
|
|
212
214
|
if (hash !== undefined && base === location.href.split('#')[0]) {
|
|
213
|
-
//
|
|
214
|
-
//
|
|
215
|
-
|
|
215
|
+
// set this flag to distinguish between navigations triggered by
|
|
216
|
+
// clicking a hash link and those triggered by popstate
|
|
217
|
+
this.hash_navigating = true;
|
|
218
|
+
|
|
216
219
|
const info = this.parse(url);
|
|
217
220
|
if (info) {
|
|
218
221
|
return this.renderer.update(info, [], false);
|
|
@@ -256,6 +259,19 @@ class Router {
|
|
|
256
259
|
});
|
|
257
260
|
}
|
|
258
261
|
});
|
|
262
|
+
|
|
263
|
+
addEventListener('hashchange', () => {
|
|
264
|
+
// if the hashchange happened as a result of clicking on a link,
|
|
265
|
+
// we need to update history, otherwise we have to leave it alone
|
|
266
|
+
if (this.hash_navigating) {
|
|
267
|
+
this.hash_navigating = false;
|
|
268
|
+
history.replaceState(
|
|
269
|
+
{ ...history.state, 'sveltekit:index': ++this.current_history_index },
|
|
270
|
+
'',
|
|
271
|
+
location.href
|
|
272
|
+
);
|
|
273
|
+
}
|
|
274
|
+
});
|
|
259
275
|
}
|
|
260
276
|
|
|
261
277
|
/**
|
|
@@ -720,11 +736,12 @@ class Renderer {
|
|
|
720
736
|
* status: number;
|
|
721
737
|
* error: Error;
|
|
722
738
|
* nodes: Array<Promise<CSRComponent>>;
|
|
723
|
-
* url: URL;
|
|
724
739
|
* params: Record<string, string>;
|
|
725
740
|
* }} selected
|
|
726
741
|
*/
|
|
727
|
-
async start({ status, error, nodes,
|
|
742
|
+
async start({ status, error, nodes, params }) {
|
|
743
|
+
const url = new URL(location.href);
|
|
744
|
+
|
|
728
745
|
/** @type {Array<import('./types').BranchNode | undefined>} */
|
|
729
746
|
const branch = [];
|
|
730
747
|
|
|
@@ -736,9 +753,6 @@ class Renderer {
|
|
|
736
753
|
|
|
737
754
|
let error_args;
|
|
738
755
|
|
|
739
|
-
// url.hash is empty when coming from the server
|
|
740
|
-
url.hash = window.location.hash;
|
|
741
|
-
|
|
742
756
|
try {
|
|
743
757
|
for (let i = 0; i < nodes.length; i += 1) {
|
|
744
758
|
const is_leaf = i === nodes.length - 1;
|
|
@@ -764,6 +778,7 @@ class Renderer {
|
|
|
764
778
|
|
|
765
779
|
if (props) {
|
|
766
780
|
node.uses.dependencies.add(url.href);
|
|
781
|
+
node.uses.url = true;
|
|
767
782
|
}
|
|
768
783
|
|
|
769
784
|
branch.push(node);
|
|
@@ -1277,9 +1292,11 @@ class Renderer {
|
|
|
1277
1292
|
/** @type {Record<string, any>} */
|
|
1278
1293
|
let props = {};
|
|
1279
1294
|
|
|
1280
|
-
|
|
1295
|
+
const is_shadow_page = has_shadow && i === a.length - 1;
|
|
1296
|
+
|
|
1297
|
+
if (is_shadow_page) {
|
|
1281
1298
|
const res = await fetch(
|
|
1282
|
-
`${url.pathname}${url.pathname.endsWith('/') ? '' : '/'}__data.json`,
|
|
1299
|
+
`${url.pathname}${url.pathname.endsWith('/') ? '' : '/'}__data.json${url.search}`,
|
|
1283
1300
|
{
|
|
1284
1301
|
headers: {
|
|
1285
1302
|
'x-sveltekit-load': 'true'
|
|
@@ -1315,25 +1332,31 @@ class Renderer {
|
|
|
1315
1332
|
});
|
|
1316
1333
|
}
|
|
1317
1334
|
|
|
1318
|
-
if (node
|
|
1319
|
-
if (
|
|
1320
|
-
|
|
1321
|
-
}
|
|
1322
|
-
if (node.loaded.error) {
|
|
1323
|
-
status = node.loaded.status;
|
|
1324
|
-
error = node.loaded.error;
|
|
1335
|
+
if (node) {
|
|
1336
|
+
if (is_shadow_page) {
|
|
1337
|
+
node.uses.url = true;
|
|
1325
1338
|
}
|
|
1326
1339
|
|
|
1327
|
-
if (node.loaded
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1340
|
+
if (node.loaded) {
|
|
1341
|
+
if (node.loaded.fallthrough) {
|
|
1342
|
+
return;
|
|
1343
|
+
}
|
|
1344
|
+
if (node.loaded.error) {
|
|
1345
|
+
status = node.loaded.status;
|
|
1346
|
+
error = node.loaded.error;
|
|
1347
|
+
}
|
|
1334
1348
|
|
|
1335
|
-
|
|
1336
|
-
|
|
1349
|
+
if (node.loaded.redirect) {
|
|
1350
|
+
return {
|
|
1351
|
+
redirect: node.loaded.redirect,
|
|
1352
|
+
props: {},
|
|
1353
|
+
state: this.current
|
|
1354
|
+
};
|
|
1355
|
+
}
|
|
1356
|
+
|
|
1357
|
+
if (node.loaded.stuff) {
|
|
1358
|
+
stuff_changed = true;
|
|
1359
|
+
}
|
|
1337
1360
|
}
|
|
1338
1361
|
}
|
|
1339
1362
|
} else {
|
|
@@ -1467,7 +1490,6 @@ class Renderer {
|
|
|
1467
1490
|
* status: number;
|
|
1468
1491
|
* error: Error;
|
|
1469
1492
|
* nodes: Array<Promise<import('types/internal').CSRComponent>>;
|
|
1470
|
-
* url: URL;
|
|
1471
1493
|
* params: Record<string, string>;
|
|
1472
1494
|
* };
|
|
1473
1495
|
* }} opts
|
package/assets/server/index.js
CHANGED
|
@@ -80,7 +80,7 @@ function is_pojo(body) {
|
|
|
80
80
|
|
|
81
81
|
// body could be a node Readable, but we don't want to import
|
|
82
82
|
// node built-ins, so we use duck typing
|
|
83
|
-
if (body._readableState && body.
|
|
83
|
+
if (body._readableState && typeof body.pipe === 'function') return false;
|
|
84
84
|
|
|
85
85
|
// similarly, it could be a web ReadableStream
|
|
86
86
|
if (typeof ReadableStream !== 'undefined' && body instanceof ReadableStream) return false;
|
|
@@ -1209,7 +1209,6 @@ async function render_response({
|
|
|
1209
1209
|
.map(({ node }) => `import(${s(options.prefix + node.entry)})`)
|
|
1210
1210
|
.join(',\n\t\t\t\t\t\t')}
|
|
1211
1211
|
],
|
|
1212
|
-
url: new URL(${s(url.href)}),
|
|
1213
1212
|
params: ${devalue(params)}
|
|
1214
1213
|
}` : 'null'}
|
|
1215
1214
|
});
|
|
@@ -1881,7 +1880,7 @@ async function load_shadow_data(route, event, options, prerender) {
|
|
|
1881
1880
|
const mod = await route.shadow();
|
|
1882
1881
|
|
|
1883
1882
|
if (prerender && (mod.post || mod.put || mod.del || mod.patch)) {
|
|
1884
|
-
throw new Error('Cannot prerender pages that have
|
|
1883
|
+
throw new Error('Cannot prerender pages that have endpoints with mutative methods');
|
|
1885
1884
|
}
|
|
1886
1885
|
|
|
1887
1886
|
const method = normalize_request_method(event);
|
|
@@ -1988,7 +1987,7 @@ function validate_shadow_output(result) {
|
|
|
1988
1987
|
if (headers instanceof Headers) {
|
|
1989
1988
|
if (headers.has('set-cookie')) {
|
|
1990
1989
|
throw new Error(
|
|
1991
|
-
'
|
|
1990
|
+
'Endpoint request handler cannot use Headers interface with Set-Cookie headers'
|
|
1992
1991
|
);
|
|
1993
1992
|
}
|
|
1994
1993
|
} else {
|
|
@@ -1996,7 +1995,7 @@ function validate_shadow_output(result) {
|
|
|
1996
1995
|
}
|
|
1997
1996
|
|
|
1998
1997
|
if (!is_pojo(body)) {
|
|
1999
|
-
throw new Error('Body returned from
|
|
1998
|
+
throw new Error('Body returned from endpoint request handler must be a plain object');
|
|
2000
1999
|
}
|
|
2001
2000
|
|
|
2002
2001
|
return { status, headers, body };
|
|
@@ -2602,7 +2601,17 @@ async function respond(request, options, state = {}) {
|
|
|
2602
2601
|
}
|
|
2603
2602
|
|
|
2604
2603
|
const is_data_request = decoded.endsWith(DATA_SUFFIX);
|
|
2605
|
-
|
|
2604
|
+
|
|
2605
|
+
if (is_data_request) {
|
|
2606
|
+
decoded = decoded.slice(0, -DATA_SUFFIX.length) || '/';
|
|
2607
|
+
|
|
2608
|
+
const normalized = normalize_path(
|
|
2609
|
+
url.pathname.slice(0, -DATA_SUFFIX.length),
|
|
2610
|
+
options.trailing_slash
|
|
2611
|
+
);
|
|
2612
|
+
|
|
2613
|
+
event.url = new URL(event.url.origin + normalized + event.url.search);
|
|
2614
|
+
}
|
|
2606
2615
|
|
|
2607
2616
|
for (const route of options.manifest._.routes) {
|
|
2608
2617
|
const match = route.pattern.exec(decoded);
|
package/dist/cli.js
CHANGED
|
@@ -998,7 +998,7 @@ async function launch(port, https) {
|
|
|
998
998
|
exec(`${cmd} ${https ? 'https' : 'http'}://localhost:${port}`);
|
|
999
999
|
}
|
|
1000
1000
|
|
|
1001
|
-
const prog = sade('svelte-kit').version('1.0.0-next.
|
|
1001
|
+
const prog = sade('svelte-kit').version('1.0.0-next.275');
|
|
1002
1002
|
|
|
1003
1003
|
prog
|
|
1004
1004
|
.command('dev')
|
|
@@ -1156,7 +1156,7 @@ async function check_port(port) {
|
|
|
1156
1156
|
function welcome({ port, host, https, open, loose, allow, cwd }) {
|
|
1157
1157
|
if (open) launch(port, https);
|
|
1158
1158
|
|
|
1159
|
-
console.log($.bold().cyan(`\n SvelteKit v${'1.0.0-next.
|
|
1159
|
+
console.log($.bold().cyan(`\n SvelteKit v${'1.0.0-next.275'}\n`));
|
|
1160
1160
|
|
|
1161
1161
|
const protocol = https ? 'https:' : 'http:';
|
|
1162
1162
|
const exposed = typeof host !== 'undefined' && host !== 'localhost' && host !== '127.0.0.1';
|