@sveltejs/kit 1.0.0-next.221 → 1.0.0-next.222
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/kit.js +66 -24
- package/assets/runtime/app/stores.js +4 -6
- package/dist/chunks/index.js +0 -1
- package/dist/chunks/index3.js +0 -1
- package/dist/cli.js +10 -3
- package/dist/ssr.js +66 -24
- package/package.json +1 -1
- package/types/config.d.ts +0 -1
- package/types/hooks.d.ts +9 -2
- package/types/index.d.ts +2 -1
- package/types/internal.d.ts +0 -3
package/assets/kit.js
CHANGED
|
@@ -544,11 +544,12 @@ const s = JSON.stringify;
|
|
|
544
544
|
* branch: Array<import('./types').Loaded>;
|
|
545
545
|
* options: import('types/internal').SSRRenderOptions;
|
|
546
546
|
* $session: any;
|
|
547
|
-
* page_config: { hydrate: boolean, router: boolean
|
|
547
|
+
* page_config: { hydrate: boolean, router: boolean };
|
|
548
548
|
* status: number;
|
|
549
|
-
* error?: Error
|
|
549
|
+
* error?: Error;
|
|
550
550
|
* url: URL;
|
|
551
|
-
* params: Record<string, string
|
|
551
|
+
* params: Record<string, string>;
|
|
552
|
+
* ssr: boolean;
|
|
552
553
|
* stuff: Record<string, any>;
|
|
553
554
|
* }} opts
|
|
554
555
|
*/
|
|
@@ -561,6 +562,7 @@ async function render_response({
|
|
|
561
562
|
error,
|
|
562
563
|
url,
|
|
563
564
|
params,
|
|
565
|
+
ssr,
|
|
564
566
|
stuff
|
|
565
567
|
}) {
|
|
566
568
|
const css = new Set(options.manifest._.entry.css);
|
|
@@ -579,7 +581,7 @@ async function render_response({
|
|
|
579
581
|
error.stack = options.get_stack(error);
|
|
580
582
|
}
|
|
581
583
|
|
|
582
|
-
if (
|
|
584
|
+
if (ssr) {
|
|
583
585
|
branch.forEach(({ node, loaded, fetched, uses_credentials }) => {
|
|
584
586
|
if (node.css) node.css.forEach((url) => css.add(url));
|
|
585
587
|
if (node.js) node.js.forEach((url) => js.add(url));
|
|
@@ -682,9 +684,9 @@ async function render_response({
|
|
|
682
684
|
throw new Error(`Failed to serialize session data: ${error.message}`);
|
|
683
685
|
})},
|
|
684
686
|
route: ${!!page_config.router},
|
|
685
|
-
spa: ${!
|
|
687
|
+
spa: ${!ssr},
|
|
686
688
|
trailing_slash: ${s(options.trailing_slash)},
|
|
687
|
-
hydrate: ${
|
|
689
|
+
hydrate: ${ssr && page_config.hydrate ? `{
|
|
688
690
|
status: ${status},
|
|
689
691
|
error: ${serialize_error(error)},
|
|
690
692
|
nodes: [
|
|
@@ -1220,9 +1222,18 @@ async function load_node({
|
|
|
1220
1222
|
* $session: any;
|
|
1221
1223
|
* status: number;
|
|
1222
1224
|
* error: Error;
|
|
1225
|
+
* ssr: boolean;
|
|
1223
1226
|
* }} opts
|
|
1224
1227
|
*/
|
|
1225
|
-
async function respond_with_error({
|
|
1228
|
+
async function respond_with_error({
|
|
1229
|
+
request,
|
|
1230
|
+
options,
|
|
1231
|
+
state,
|
|
1232
|
+
$session,
|
|
1233
|
+
status,
|
|
1234
|
+
error,
|
|
1235
|
+
ssr
|
|
1236
|
+
}) {
|
|
1226
1237
|
try {
|
|
1227
1238
|
const default_layout = await options.manifest._.nodes[0](); // 0 is always the root layout
|
|
1228
1239
|
const default_error = await options.manifest._.nodes[1](); // 1 is always the root error
|
|
@@ -1269,15 +1280,15 @@ async function respond_with_error({ request, options, state, $session, status, e
|
|
|
1269
1280
|
$session,
|
|
1270
1281
|
page_config: {
|
|
1271
1282
|
hydrate: options.hydrate,
|
|
1272
|
-
router: options.router
|
|
1273
|
-
ssr: options.ssr
|
|
1283
|
+
router: options.router
|
|
1274
1284
|
},
|
|
1275
1285
|
stuff: error_loaded.stuff,
|
|
1276
1286
|
status,
|
|
1277
1287
|
error,
|
|
1278
1288
|
branch: [layout_loaded, error_loaded],
|
|
1279
1289
|
url: request.url,
|
|
1280
|
-
params
|
|
1290
|
+
params,
|
|
1291
|
+
ssr
|
|
1281
1292
|
});
|
|
1282
1293
|
} catch (err) {
|
|
1283
1294
|
const error = coalesce_to_error(err);
|
|
@@ -1319,15 +1330,30 @@ function is_prerender_enabled(options, node, state) {
|
|
|
1319
1330
|
* $session: any;
|
|
1320
1331
|
* route: import('types/internal').SSRPage;
|
|
1321
1332
|
* params: Record<string, string>;
|
|
1333
|
+
* ssr: boolean;
|
|
1322
1334
|
* }} opts
|
|
1323
1335
|
* @returns {Promise<ServerResponse | undefined>}
|
|
1324
1336
|
*/
|
|
1325
1337
|
async function respond$1(opts) {
|
|
1326
|
-
const { request, options, state, $session, route } = opts;
|
|
1338
|
+
const { request, options, state, $session, route, ssr } = opts;
|
|
1327
1339
|
|
|
1328
1340
|
/** @type {Array<SSRNode | undefined>} */
|
|
1329
1341
|
let nodes;
|
|
1330
1342
|
|
|
1343
|
+
if (!ssr) {
|
|
1344
|
+
return await render_response({
|
|
1345
|
+
...opts,
|
|
1346
|
+
branch: [],
|
|
1347
|
+
page_config: {
|
|
1348
|
+
hydrate: true,
|
|
1349
|
+
router: true
|
|
1350
|
+
},
|
|
1351
|
+
status: 200,
|
|
1352
|
+
url: request.url,
|
|
1353
|
+
stuff: {}
|
|
1354
|
+
});
|
|
1355
|
+
}
|
|
1356
|
+
|
|
1331
1357
|
try {
|
|
1332
1358
|
nodes = await Promise.all(
|
|
1333
1359
|
route.a.map((n) => options.manifest._.nodes[n] && options.manifest._.nodes[n]())
|
|
@@ -1343,7 +1369,8 @@ async function respond$1(opts) {
|
|
|
1343
1369
|
state,
|
|
1344
1370
|
$session,
|
|
1345
1371
|
status: 500,
|
|
1346
|
-
error
|
|
1372
|
+
error,
|
|
1373
|
+
ssr
|
|
1347
1374
|
});
|
|
1348
1375
|
}
|
|
1349
1376
|
|
|
@@ -1375,7 +1402,7 @@ async function respond$1(opts) {
|
|
|
1375
1402
|
|
|
1376
1403
|
let stuff = {};
|
|
1377
1404
|
|
|
1378
|
-
ssr: if (
|
|
1405
|
+
ssr: if (ssr) {
|
|
1379
1406
|
for (let i = 0; i < nodes.length; i += 1) {
|
|
1380
1407
|
const node = nodes[i];
|
|
1381
1408
|
|
|
@@ -1438,7 +1465,6 @@ async function respond$1(opts) {
|
|
|
1438
1465
|
}
|
|
1439
1466
|
|
|
1440
1467
|
try {
|
|
1441
|
-
// there's no fallthough on an error page, so we know it's not undefined
|
|
1442
1468
|
const error_loaded = /** @type {import('./types').Loaded} */ (
|
|
1443
1469
|
await load_node({
|
|
1444
1470
|
...opts,
|
|
@@ -1480,7 +1506,8 @@ async function respond$1(opts) {
|
|
|
1480
1506
|
state,
|
|
1481
1507
|
$session,
|
|
1482
1508
|
status,
|
|
1483
|
-
error
|
|
1509
|
+
error,
|
|
1510
|
+
ssr
|
|
1484
1511
|
}),
|
|
1485
1512
|
set_cookie_headers
|
|
1486
1513
|
);
|
|
@@ -1530,8 +1557,14 @@ async function respond$1(opts) {
|
|
|
1530
1557
|
* @param {SSRRenderOptions} options
|
|
1531
1558
|
*/
|
|
1532
1559
|
function get_page_config(leaf, options) {
|
|
1560
|
+
// TODO remove for 1.0
|
|
1561
|
+
if ('ssr' in leaf) {
|
|
1562
|
+
throw new Error(
|
|
1563
|
+
'`export const ssr` has been removed — use the handle hook instead: https://kit.svelte.dev/docs#hooks-handle'
|
|
1564
|
+
);
|
|
1565
|
+
}
|
|
1566
|
+
|
|
1533
1567
|
return {
|
|
1534
|
-
ssr: 'ssr' in leaf ? !!leaf.ssr : options.ssr,
|
|
1535
1568
|
router: 'router' in leaf ? !!leaf.router : options.router,
|
|
1536
1569
|
hydrate: 'hydrate' in leaf ? !!leaf.hydrate : options.hydrate
|
|
1537
1570
|
};
|
|
@@ -1554,9 +1587,10 @@ function with_cookies(response, set_cookie_headers) {
|
|
|
1554
1587
|
* @param {RegExpExecArray} match
|
|
1555
1588
|
* @param {import('types/internal').SSRRenderOptions} options
|
|
1556
1589
|
* @param {import('types/internal').SSRRenderState} state
|
|
1590
|
+
* @param {boolean} ssr
|
|
1557
1591
|
* @returns {Promise<import('types/hooks').ServerResponse | undefined>}
|
|
1558
1592
|
*/
|
|
1559
|
-
async function render_page(request, route, match, options, state) {
|
|
1593
|
+
async function render_page(request, route, match, options, state, ssr) {
|
|
1560
1594
|
if (state.initiator === route) {
|
|
1561
1595
|
// infinite request cycle detected
|
|
1562
1596
|
return {
|
|
@@ -1576,7 +1610,8 @@ async function render_page(request, route, match, options, state) {
|
|
|
1576
1610
|
state,
|
|
1577
1611
|
$session,
|
|
1578
1612
|
route,
|
|
1579
|
-
params
|
|
1613
|
+
params,
|
|
1614
|
+
ssr
|
|
1580
1615
|
});
|
|
1581
1616
|
|
|
1582
1617
|
if (response) {
|
|
@@ -1831,20 +1866,25 @@ async function respond(incoming, options, state = {}) {
|
|
|
1831
1866
|
print_error('path', 'pathname');
|
|
1832
1867
|
print_error('query', 'searchParams');
|
|
1833
1868
|
|
|
1869
|
+
let ssr = true;
|
|
1870
|
+
|
|
1834
1871
|
try {
|
|
1835
1872
|
return await options.hooks.handle({
|
|
1836
1873
|
request,
|
|
1837
|
-
resolve: async (request) => {
|
|
1874
|
+
resolve: async (request, opts) => {
|
|
1875
|
+
if (opts && 'ssr' in opts) ssr = /** @type {boolean} */ (opts.ssr);
|
|
1876
|
+
|
|
1838
1877
|
if (state.prerender && state.prerender.fallback) {
|
|
1839
1878
|
return await render_response({
|
|
1840
1879
|
url: request.url,
|
|
1841
1880
|
params: request.params,
|
|
1842
1881
|
options,
|
|
1843
1882
|
$session: await options.hooks.getSession(request),
|
|
1883
|
+
page_config: { router: true, hydrate: true },
|
|
1844
1884
|
stuff: {},
|
|
1845
|
-
page_config: { ssr: false, router: true, hydrate: true },
|
|
1846
1885
|
status: 200,
|
|
1847
|
-
branch: []
|
|
1886
|
+
branch: [],
|
|
1887
|
+
ssr: false
|
|
1848
1888
|
});
|
|
1849
1889
|
}
|
|
1850
1890
|
|
|
@@ -1857,7 +1897,7 @@ async function respond(incoming, options, state = {}) {
|
|
|
1857
1897
|
const response =
|
|
1858
1898
|
route.type === 'endpoint'
|
|
1859
1899
|
? await render_endpoint(request, route, match)
|
|
1860
|
-
: await render_page(request, route, match, options, state);
|
|
1900
|
+
: await render_page(request, route, match, options, state, ssr);
|
|
1861
1901
|
|
|
1862
1902
|
if (response) {
|
|
1863
1903
|
// inject ETags for 200 responses
|
|
@@ -1897,7 +1937,8 @@ async function respond(incoming, options, state = {}) {
|
|
|
1897
1937
|
state,
|
|
1898
1938
|
$session,
|
|
1899
1939
|
status: 404,
|
|
1900
|
-
error: new Error(`Not found: ${request.url.pathname}`)
|
|
1940
|
+
error: new Error(`Not found: ${request.url.pathname}`),
|
|
1941
|
+
ssr
|
|
1901
1942
|
});
|
|
1902
1943
|
}
|
|
1903
1944
|
}
|
|
@@ -1915,7 +1956,8 @@ async function respond(incoming, options, state = {}) {
|
|
|
1915
1956
|
state,
|
|
1916
1957
|
$session,
|
|
1917
1958
|
status: 500,
|
|
1918
|
-
error
|
|
1959
|
+
error,
|
|
1960
|
+
ssr
|
|
1919
1961
|
});
|
|
1920
1962
|
} catch (/** @type {unknown} */ e) {
|
|
1921
1963
|
const error = coalesce_to_error(e);
|
|
@@ -2,8 +2,6 @@ import { getContext } from 'svelte';
|
|
|
2
2
|
import { browser } from './env.js';
|
|
3
3
|
import '../env.js';
|
|
4
4
|
|
|
5
|
-
const ssr = !browser;
|
|
6
|
-
|
|
7
5
|
// TODO remove this (for 1.0? after 1.0?)
|
|
8
6
|
let warned = false;
|
|
9
7
|
function stores() {
|
|
@@ -59,9 +57,9 @@ const navigating = {
|
|
|
59
57
|
/** @param {string} verb */
|
|
60
58
|
const throw_error = (verb) => {
|
|
61
59
|
throw new Error(
|
|
62
|
-
|
|
63
|
-
? `
|
|
64
|
-
: `
|
|
60
|
+
browser
|
|
61
|
+
? `Cannot ${verb} session store before subscribing`
|
|
62
|
+
: `Can only ${verb} session store in browser`
|
|
65
63
|
);
|
|
66
64
|
};
|
|
67
65
|
|
|
@@ -70,7 +68,7 @@ const session = {
|
|
|
70
68
|
subscribe(fn) {
|
|
71
69
|
const store = getStores().session;
|
|
72
70
|
|
|
73
|
-
if (
|
|
71
|
+
if (browser) {
|
|
74
72
|
session.set = store.set;
|
|
75
73
|
session.update = store.update;
|
|
76
74
|
}
|
package/dist/chunks/index.js
CHANGED
|
@@ -234,7 +234,6 @@ async function create_plugin(config, output, cwd) {
|
|
|
234
234
|
read: (file) => fs__default.readFileSync(path__default.join(config.kit.files.assets, file)),
|
|
235
235
|
root,
|
|
236
236
|
router: config.kit.router,
|
|
237
|
-
ssr: config.kit.ssr,
|
|
238
237
|
target: config.kit.target,
|
|
239
238
|
template: ({ head, body, assets }) => {
|
|
240
239
|
let rendered = load_template(cwd, config)
|
package/dist/chunks/index3.js
CHANGED
|
@@ -314,7 +314,6 @@ export class App {
|
|
|
314
314
|
root,
|
|
315
315
|
service_worker: ${has_service_worker ? "'/service-worker.js'" : 'null'},
|
|
316
316
|
router: ${s(config.kit.router)},
|
|
317
|
-
ssr: ${s(config.kit.ssr)},
|
|
318
317
|
target: ${s(config.kit.target)},
|
|
319
318
|
template,
|
|
320
319
|
trailing_slash: ${s(config.kit.trailingSlash)}
|
package/dist/cli.js
CHANGED
|
@@ -575,7 +575,14 @@ const options = object(
|
|
|
575
575
|
files: fun((filename) => !/\.DS_STORE/.test(filename))
|
|
576
576
|
}),
|
|
577
577
|
|
|
578
|
-
|
|
578
|
+
// TODO remove this for 1.0
|
|
579
|
+
ssr: validate(null, (input) => {
|
|
580
|
+
if (input !== undefined) {
|
|
581
|
+
throw new Error(
|
|
582
|
+
'config.kit.ssr has been removed — use the handle hook instead: https://kit.svelte.dev/docs#hooks-handle'
|
|
583
|
+
);
|
|
584
|
+
}
|
|
585
|
+
}),
|
|
579
586
|
|
|
580
587
|
target: string(null),
|
|
581
588
|
|
|
@@ -846,7 +853,7 @@ async function launch(port, https) {
|
|
|
846
853
|
exec(`${cmd} ${https ? 'https' : 'http'}://localhost:${port}`);
|
|
847
854
|
}
|
|
848
855
|
|
|
849
|
-
const prog = sade('svelte-kit').version('1.0.0-next.
|
|
856
|
+
const prog = sade('svelte-kit').version('1.0.0-next.222');
|
|
850
857
|
|
|
851
858
|
prog
|
|
852
859
|
.command('dev')
|
|
@@ -998,7 +1005,7 @@ async function check_port(port) {
|
|
|
998
1005
|
function welcome({ port, host, https, open, loose, allow, cwd }) {
|
|
999
1006
|
if (open) launch(port, https);
|
|
1000
1007
|
|
|
1001
|
-
console.log($.bold().cyan(`\n SvelteKit v${'1.0.0-next.
|
|
1008
|
+
console.log($.bold().cyan(`\n SvelteKit v${'1.0.0-next.222'}\n`));
|
|
1002
1009
|
|
|
1003
1010
|
const protocol = https ? 'https:' : 'http:';
|
|
1004
1011
|
const exposed = typeof host !== 'undefined' && host !== 'localhost' && host !== '127.0.0.1';
|
package/dist/ssr.js
CHANGED
|
@@ -513,11 +513,12 @@ function escape(str, dict, unicode_encoder) {
|
|
|
513
513
|
* branch: Array<import('./types').Loaded>;
|
|
514
514
|
* options: import('types/internal').SSRRenderOptions;
|
|
515
515
|
* $session: any;
|
|
516
|
-
* page_config: { hydrate: boolean, router: boolean
|
|
516
|
+
* page_config: { hydrate: boolean, router: boolean };
|
|
517
517
|
* status: number;
|
|
518
|
-
* error?: Error
|
|
518
|
+
* error?: Error;
|
|
519
519
|
* url: URL;
|
|
520
|
-
* params: Record<string, string
|
|
520
|
+
* params: Record<string, string>;
|
|
521
|
+
* ssr: boolean;
|
|
521
522
|
* stuff: Record<string, any>;
|
|
522
523
|
* }} opts
|
|
523
524
|
*/
|
|
@@ -530,6 +531,7 @@ async function render_response({
|
|
|
530
531
|
error,
|
|
531
532
|
url,
|
|
532
533
|
params,
|
|
534
|
+
ssr,
|
|
533
535
|
stuff
|
|
534
536
|
}) {
|
|
535
537
|
const css = new Set(options.manifest._.entry.css);
|
|
@@ -548,7 +550,7 @@ async function render_response({
|
|
|
548
550
|
error.stack = options.get_stack(error);
|
|
549
551
|
}
|
|
550
552
|
|
|
551
|
-
if (
|
|
553
|
+
if (ssr) {
|
|
552
554
|
branch.forEach(({ node, loaded, fetched, uses_credentials }) => {
|
|
553
555
|
if (node.css) node.css.forEach((url) => css.add(url));
|
|
554
556
|
if (node.js) node.js.forEach((url) => js.add(url));
|
|
@@ -651,9 +653,9 @@ async function render_response({
|
|
|
651
653
|
throw new Error(`Failed to serialize session data: ${error.message}`);
|
|
652
654
|
})},
|
|
653
655
|
route: ${!!page_config.router},
|
|
654
|
-
spa: ${!
|
|
656
|
+
spa: ${!ssr},
|
|
655
657
|
trailing_slash: ${s(options.trailing_slash)},
|
|
656
|
-
hydrate: ${
|
|
658
|
+
hydrate: ${ssr && page_config.hydrate ? `{
|
|
657
659
|
status: ${status},
|
|
658
660
|
error: ${serialize_error(error)},
|
|
659
661
|
nodes: [
|
|
@@ -1150,9 +1152,18 @@ async function load_node({
|
|
|
1150
1152
|
* $session: any;
|
|
1151
1153
|
* status: number;
|
|
1152
1154
|
* error: Error;
|
|
1155
|
+
* ssr: boolean;
|
|
1153
1156
|
* }} opts
|
|
1154
1157
|
*/
|
|
1155
|
-
async function respond_with_error({
|
|
1158
|
+
async function respond_with_error({
|
|
1159
|
+
request,
|
|
1160
|
+
options,
|
|
1161
|
+
state,
|
|
1162
|
+
$session,
|
|
1163
|
+
status,
|
|
1164
|
+
error,
|
|
1165
|
+
ssr
|
|
1166
|
+
}) {
|
|
1156
1167
|
try {
|
|
1157
1168
|
const default_layout = await options.manifest._.nodes[0](); // 0 is always the root layout
|
|
1158
1169
|
const default_error = await options.manifest._.nodes[1](); // 1 is always the root error
|
|
@@ -1199,15 +1210,15 @@ async function respond_with_error({ request, options, state, $session, status, e
|
|
|
1199
1210
|
$session,
|
|
1200
1211
|
page_config: {
|
|
1201
1212
|
hydrate: options.hydrate,
|
|
1202
|
-
router: options.router
|
|
1203
|
-
ssr: options.ssr
|
|
1213
|
+
router: options.router
|
|
1204
1214
|
},
|
|
1205
1215
|
stuff: error_loaded.stuff,
|
|
1206
1216
|
status,
|
|
1207
1217
|
error,
|
|
1208
1218
|
branch: [layout_loaded, error_loaded],
|
|
1209
1219
|
url: request.url,
|
|
1210
|
-
params
|
|
1220
|
+
params,
|
|
1221
|
+
ssr
|
|
1211
1222
|
});
|
|
1212
1223
|
} catch (err) {
|
|
1213
1224
|
const error = coalesce_to_error(err);
|
|
@@ -1249,15 +1260,30 @@ function is_prerender_enabled(options, node, state) {
|
|
|
1249
1260
|
* $session: any;
|
|
1250
1261
|
* route: import('types/internal').SSRPage;
|
|
1251
1262
|
* params: Record<string, string>;
|
|
1263
|
+
* ssr: boolean;
|
|
1252
1264
|
* }} opts
|
|
1253
1265
|
* @returns {Promise<ServerResponse | undefined>}
|
|
1254
1266
|
*/
|
|
1255
1267
|
async function respond$1(opts) {
|
|
1256
|
-
const { request, options, state, $session, route } = opts;
|
|
1268
|
+
const { request, options, state, $session, route, ssr } = opts;
|
|
1257
1269
|
|
|
1258
1270
|
/** @type {Array<SSRNode | undefined>} */
|
|
1259
1271
|
let nodes;
|
|
1260
1272
|
|
|
1273
|
+
if (!ssr) {
|
|
1274
|
+
return await render_response({
|
|
1275
|
+
...opts,
|
|
1276
|
+
branch: [],
|
|
1277
|
+
page_config: {
|
|
1278
|
+
hydrate: true,
|
|
1279
|
+
router: true
|
|
1280
|
+
},
|
|
1281
|
+
status: 200,
|
|
1282
|
+
url: request.url,
|
|
1283
|
+
stuff: {}
|
|
1284
|
+
});
|
|
1285
|
+
}
|
|
1286
|
+
|
|
1261
1287
|
try {
|
|
1262
1288
|
nodes = await Promise.all(
|
|
1263
1289
|
route.a.map((n) => options.manifest._.nodes[n] && options.manifest._.nodes[n]())
|
|
@@ -1273,7 +1299,8 @@ async function respond$1(opts) {
|
|
|
1273
1299
|
state,
|
|
1274
1300
|
$session,
|
|
1275
1301
|
status: 500,
|
|
1276
|
-
error
|
|
1302
|
+
error,
|
|
1303
|
+
ssr
|
|
1277
1304
|
});
|
|
1278
1305
|
}
|
|
1279
1306
|
|
|
@@ -1305,7 +1332,7 @@ async function respond$1(opts) {
|
|
|
1305
1332
|
|
|
1306
1333
|
let stuff = {};
|
|
1307
1334
|
|
|
1308
|
-
ssr: if (
|
|
1335
|
+
ssr: if (ssr) {
|
|
1309
1336
|
for (let i = 0; i < nodes.length; i += 1) {
|
|
1310
1337
|
const node = nodes[i];
|
|
1311
1338
|
|
|
@@ -1368,7 +1395,6 @@ async function respond$1(opts) {
|
|
|
1368
1395
|
}
|
|
1369
1396
|
|
|
1370
1397
|
try {
|
|
1371
|
-
// there's no fallthough on an error page, so we know it's not undefined
|
|
1372
1398
|
const error_loaded = /** @type {import('./types').Loaded} */ (
|
|
1373
1399
|
await load_node({
|
|
1374
1400
|
...opts,
|
|
@@ -1410,7 +1436,8 @@ async function respond$1(opts) {
|
|
|
1410
1436
|
state,
|
|
1411
1437
|
$session,
|
|
1412
1438
|
status,
|
|
1413
|
-
error
|
|
1439
|
+
error,
|
|
1440
|
+
ssr
|
|
1414
1441
|
}),
|
|
1415
1442
|
set_cookie_headers
|
|
1416
1443
|
);
|
|
@@ -1460,8 +1487,14 @@ async function respond$1(opts) {
|
|
|
1460
1487
|
* @param {SSRRenderOptions} options
|
|
1461
1488
|
*/
|
|
1462
1489
|
function get_page_config(leaf, options) {
|
|
1490
|
+
// TODO remove for 1.0
|
|
1491
|
+
if ('ssr' in leaf) {
|
|
1492
|
+
throw new Error(
|
|
1493
|
+
'`export const ssr` has been removed — use the handle hook instead: https://kit.svelte.dev/docs#hooks-handle'
|
|
1494
|
+
);
|
|
1495
|
+
}
|
|
1496
|
+
|
|
1463
1497
|
return {
|
|
1464
|
-
ssr: 'ssr' in leaf ? !!leaf.ssr : options.ssr,
|
|
1465
1498
|
router: 'router' in leaf ? !!leaf.router : options.router,
|
|
1466
1499
|
hydrate: 'hydrate' in leaf ? !!leaf.hydrate : options.hydrate
|
|
1467
1500
|
};
|
|
@@ -1484,9 +1517,10 @@ function with_cookies(response, set_cookie_headers) {
|
|
|
1484
1517
|
* @param {RegExpExecArray} match
|
|
1485
1518
|
* @param {import('types/internal').SSRRenderOptions} options
|
|
1486
1519
|
* @param {import('types/internal').SSRRenderState} state
|
|
1520
|
+
* @param {boolean} ssr
|
|
1487
1521
|
* @returns {Promise<import('types/hooks').ServerResponse | undefined>}
|
|
1488
1522
|
*/
|
|
1489
|
-
async function render_page(request, route, match, options, state) {
|
|
1523
|
+
async function render_page(request, route, match, options, state, ssr) {
|
|
1490
1524
|
if (state.initiator === route) {
|
|
1491
1525
|
// infinite request cycle detected
|
|
1492
1526
|
return {
|
|
@@ -1506,7 +1540,8 @@ async function render_page(request, route, match, options, state) {
|
|
|
1506
1540
|
state,
|
|
1507
1541
|
$session,
|
|
1508
1542
|
route,
|
|
1509
|
-
params
|
|
1543
|
+
params,
|
|
1544
|
+
ssr
|
|
1510
1545
|
});
|
|
1511
1546
|
|
|
1512
1547
|
if (response) {
|
|
@@ -1761,20 +1796,25 @@ async function respond(incoming, options, state = {}) {
|
|
|
1761
1796
|
print_error('path', 'pathname');
|
|
1762
1797
|
print_error('query', 'searchParams');
|
|
1763
1798
|
|
|
1799
|
+
let ssr = true;
|
|
1800
|
+
|
|
1764
1801
|
try {
|
|
1765
1802
|
return await options.hooks.handle({
|
|
1766
1803
|
request,
|
|
1767
|
-
resolve: async (request) => {
|
|
1804
|
+
resolve: async (request, opts) => {
|
|
1805
|
+
if (opts && 'ssr' in opts) ssr = /** @type {boolean} */ (opts.ssr);
|
|
1806
|
+
|
|
1768
1807
|
if (state.prerender && state.prerender.fallback) {
|
|
1769
1808
|
return await render_response({
|
|
1770
1809
|
url: request.url,
|
|
1771
1810
|
params: request.params,
|
|
1772
1811
|
options,
|
|
1773
1812
|
$session: await options.hooks.getSession(request),
|
|
1813
|
+
page_config: { router: true, hydrate: true },
|
|
1774
1814
|
stuff: {},
|
|
1775
|
-
page_config: { ssr: false, router: true, hydrate: true },
|
|
1776
1815
|
status: 200,
|
|
1777
|
-
branch: []
|
|
1816
|
+
branch: [],
|
|
1817
|
+
ssr: false
|
|
1778
1818
|
});
|
|
1779
1819
|
}
|
|
1780
1820
|
|
|
@@ -1787,7 +1827,7 @@ async function respond(incoming, options, state = {}) {
|
|
|
1787
1827
|
const response =
|
|
1788
1828
|
route.type === 'endpoint'
|
|
1789
1829
|
? await render_endpoint(request, route, match)
|
|
1790
|
-
: await render_page(request, route, match, options, state);
|
|
1830
|
+
: await render_page(request, route, match, options, state, ssr);
|
|
1791
1831
|
|
|
1792
1832
|
if (response) {
|
|
1793
1833
|
// inject ETags for 200 responses
|
|
@@ -1827,7 +1867,8 @@ async function respond(incoming, options, state = {}) {
|
|
|
1827
1867
|
state,
|
|
1828
1868
|
$session,
|
|
1829
1869
|
status: 404,
|
|
1830
|
-
error: new Error(`Not found: ${request.url.pathname}`)
|
|
1870
|
+
error: new Error(`Not found: ${request.url.pathname}`),
|
|
1871
|
+
ssr
|
|
1831
1872
|
});
|
|
1832
1873
|
}
|
|
1833
1874
|
}
|
|
@@ -1845,7 +1886,8 @@ async function respond(incoming, options, state = {}) {
|
|
|
1845
1886
|
state,
|
|
1846
1887
|
$session,
|
|
1847
1888
|
status: 500,
|
|
1848
|
-
error
|
|
1889
|
+
error,
|
|
1890
|
+
ssr
|
|
1849
1891
|
});
|
|
1850
1892
|
} catch (/** @type {unknown} */ e) {
|
|
1851
1893
|
const error = coalesce_to_error(e);
|
package/package.json
CHANGED
package/types/config.d.ts
CHANGED
package/types/hooks.d.ts
CHANGED
|
@@ -23,10 +23,14 @@ export interface GetSession<Locals = Record<string, any>, Body = unknown, Sessio
|
|
|
23
23
|
(request: ServerRequest<Locals, Body>): MaybePromise<Session>;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
+
export interface ResolveOpts {
|
|
27
|
+
ssr?: boolean;
|
|
28
|
+
}
|
|
29
|
+
|
|
26
30
|
export interface Handle<Locals = Record<string, any>, Body = unknown> {
|
|
27
31
|
(input: {
|
|
28
32
|
request: ServerRequest<Locals, Body>;
|
|
29
|
-
resolve(request: ServerRequest<Locals, Body
|
|
33
|
+
resolve(request: ServerRequest<Locals, Body>, opts?: ResolveOpts): MaybePromise<ServerResponse>;
|
|
30
34
|
}): MaybePromise<ServerResponse>;
|
|
31
35
|
}
|
|
32
36
|
|
|
@@ -35,7 +39,10 @@ export interface Handle<Locals = Record<string, any>, Body = unknown> {
|
|
|
35
39
|
export interface InternalHandle<Locals = Record<string, any>, Body = unknown> {
|
|
36
40
|
(input: {
|
|
37
41
|
request: ServerRequest<Locals, Body>;
|
|
38
|
-
resolve(
|
|
42
|
+
resolve(
|
|
43
|
+
request: ServerRequest<Locals, Body>,
|
|
44
|
+
opts?: ResolveOpts
|
|
45
|
+
): MaybePromise<ServerResponse | undefined>;
|
|
39
46
|
}): MaybePromise<ServerResponse | undefined>;
|
|
40
47
|
}
|
|
41
48
|
|
package/types/index.d.ts
CHANGED
package/types/internal.d.ts
CHANGED
|
@@ -44,11 +44,9 @@ export interface Logger {
|
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
export interface SSRComponent {
|
|
47
|
-
ssr?: boolean;
|
|
48
47
|
router?: boolean;
|
|
49
48
|
hydrate?: boolean;
|
|
50
49
|
prerender?: boolean;
|
|
51
|
-
preload?: any; // TODO remove for 1.0
|
|
52
50
|
load: Load;
|
|
53
51
|
default: {
|
|
54
52
|
render(props: Record<string, any>): {
|
|
@@ -143,7 +141,6 @@ export interface SSRRenderOptions {
|
|
|
143
141
|
root: SSRComponent['default'];
|
|
144
142
|
router: boolean;
|
|
145
143
|
service_worker?: string;
|
|
146
|
-
ssr: boolean;
|
|
147
144
|
target: string;
|
|
148
145
|
template({ head, body, assets }: { head: string; body: string; assets: string }): string;
|
|
149
146
|
trailing_slash: TrailingSlash;
|