@sveltejs/kit 1.0.0-next.319 → 1.0.0-next.321

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.
@@ -21,6 +21,19 @@ function coalesce_to_error(err) {
21
21
  * @returns {import('types').NormalizedLoadOutput}
22
22
  */
23
23
  function normalize(loaded) {
24
+ // TODO remove for 1.0
25
+ // @ts-expect-error
26
+ if (loaded.fallthrough) {
27
+ throw new Error(
28
+ 'fallthrough is no longer supported. Use matchers instead: https://kit.svelte.dev/docs/routing#advanced-routing-matching'
29
+ );
30
+ }
31
+
32
+ // TODO remove for 1.0
33
+ if ('maxage' in loaded) {
34
+ throw new Error('maxage should be replaced with cache: { maxage }');
35
+ }
36
+
24
37
  const has_error_status =
25
38
  loaded.status && loaded.status >= 400 && loaded.status <= 599 && !loaded.redirect;
26
39
  if (loaded.error || has_error_status) {
@@ -812,9 +825,9 @@ function create_client({ target, session, base, trailing_slash }) {
812
825
  }
813
826
 
814
827
  const leaf = filtered[filtered.length - 1];
815
- const maxage = leaf.loaded && leaf.loaded.maxage;
828
+ const load_cache = leaf?.loaded?.cache;
816
829
 
817
- if (maxage) {
830
+ if (load_cache) {
818
831
  const key = url.pathname + url.search; // omit hash
819
832
  let ready = false;
820
833
 
@@ -827,7 +840,7 @@ function create_client({ target, session, base, trailing_slash }) {
827
840
  clearTimeout(timeout);
828
841
  };
829
842
 
830
- const timeout = setTimeout(clear, maxage * 1000);
843
+ const timeout = setTimeout(clear, load_cache.maxage * 1000);
831
844
 
832
845
  const unsubscribe = stores.session.subscribe(() => {
833
846
  if (ready) clear();
@@ -1056,14 +1069,6 @@ function create_client({ target, session, base, trailing_slash }) {
1056
1069
  }
1057
1070
 
1058
1071
  if (node.loaded) {
1059
- // TODO remove for 1.0
1060
- // @ts-expect-error
1061
- if (node.loaded.fallthrough) {
1062
- throw new Error(
1063
- 'fallthrough is no longer supported. Use matchers instead: https://kit.svelte.dev/docs/routing#advanced-routing-matching'
1064
- );
1065
- }
1066
-
1067
1072
  if (node.loaded.error) {
1068
1073
  status = node.loaded.status;
1069
1074
  error = node.loaded.error;
@@ -1147,7 +1147,8 @@ async function render_response({
1147
1147
  let rendered;
1148
1148
 
1149
1149
  let is_private = false;
1150
- let maxage;
1150
+ /** @type {import('types').NormalizedLoadOutputCache | undefined} */
1151
+ let cache;
1151
1152
 
1152
1153
  if (error) {
1153
1154
  error.stack = options.get_stack(error);
@@ -1163,9 +1164,8 @@ async function render_response({
1163
1164
  if (fetched && page_config.hydrate) serialized_data.push(...fetched);
1164
1165
  if (props) shadow_props = props;
1165
1166
 
1166
- if (uses_credentials) is_private = true;
1167
-
1168
- maxage = loaded.maxage;
1167
+ cache = loaded?.cache;
1168
+ is_private = cache?.private ?? uses_credentials;
1169
1169
  });
1170
1170
 
1171
1171
  const session = writable($session);
@@ -1179,7 +1179,7 @@ async function render_response({
1179
1179
  session: {
1180
1180
  ...session,
1181
1181
  subscribe: (fn) => {
1182
- is_private = true;
1182
+ is_private = cache?.private ?? true;
1183
1183
  return session.subscribe(fn);
1184
1184
  }
1185
1185
  },
@@ -1366,8 +1366,8 @@ async function render_response({
1366
1366
  http_equiv.push(csp_headers);
1367
1367
  }
1368
1368
 
1369
- if (maxage) {
1370
- http_equiv.push(`<meta http-equiv="cache-control" content="max-age=${maxage}">`);
1369
+ if (cache) {
1370
+ http_equiv.push(`<meta http-equiv="cache-control" content="max-age=${cache.maxage}">`);
1371
1371
  }
1372
1372
 
1373
1373
  if (http_equiv.length > 0) {
@@ -1388,8 +1388,8 @@ async function render_response({
1388
1388
  etag: `"${hash(html)}"`
1389
1389
  });
1390
1390
 
1391
- if (maxage) {
1392
- headers.set('cache-control', `${is_private ? 'private' : 'public'}, max-age=${maxage}`);
1391
+ if (cache) {
1392
+ headers.set('cache-control', `${is_private ? 'private' : 'public'}, max-age=${cache.maxage}`);
1393
1393
  }
1394
1394
 
1395
1395
  if (!options.floc) {
@@ -1915,6 +1915,19 @@ var splitCookiesString_1 = setCookie.exports.splitCookiesString = splitCookiesSt
1915
1915
  * @returns {import('types').NormalizedLoadOutput}
1916
1916
  */
1917
1917
  function normalize(loaded) {
1918
+ // TODO remove for 1.0
1919
+ // @ts-expect-error
1920
+ if (loaded.fallthrough) {
1921
+ throw new Error(
1922
+ 'fallthrough is no longer supported. Use matchers instead: https://kit.svelte.dev/docs/routing#advanced-routing-matching'
1923
+ );
1924
+ }
1925
+
1926
+ // TODO remove for 1.0
1927
+ if ('maxage' in loaded) {
1928
+ throw new Error('maxage should be replaced with cache: { maxage }');
1929
+ }
1930
+
1918
1931
  const has_error_status =
1919
1932
  loaded.status && loaded.status >= 400 && loaded.status <= 599 && !loaded.redirect;
1920
1933
  if (loaded.error || has_error_status) {
@@ -2411,14 +2424,6 @@ async function load_node({
2411
2424
  // TODO do we still want to enforce this now that there's no fallthrough?
2412
2425
  throw new Error(`load function must return a value${options.dev ? ` (${node.entry})` : ''}`);
2413
2426
  }
2414
-
2415
- // TODO remove for 1.0
2416
- // @ts-expect-error
2417
- if (loaded.fallthrough) {
2418
- throw new Error(
2419
- 'fallthrough is no longer supported. Use matchers instead: https://kit.svelte.dev/docs/routing#advanced-routing-matching'
2420
- );
2421
- }
2422
2427
  } else if (shadow.body) {
2423
2428
  loaded = {
2424
2429
  props: shadow.body
@@ -169,7 +169,7 @@ async function preview({ port, host, config, https: use_https = false }) {
169
169
  });
170
170
 
171
171
  return new Promise((fulfil) => {
172
- http_server.listen(port, host || '0.0.0.0', () => {
172
+ http_server.listen(port, host, () => {
173
173
  fulfil(http_server);
174
174
  });
175
175
  });
@@ -419,6 +419,10 @@ function trace(file, path, tree, extensions) {
419
419
  const node = tree.get(parts.join('/'));
420
420
  const layout = node?.layouts[layout_id];
421
421
 
422
+ if (layout?.file && layouts.indexOf(layout.file) > -1) {
423
+ throw new Error(`Recursive layout detected: ${layout.file} -> ${layouts.join(' -> ')}`);
424
+ }
425
+
422
426
  // any segment that has neither a __layout nor an __error can be discarded.
423
427
  // in other words these...
424
428
  // layouts: [a, , b, c]
package/dist/cli.js CHANGED
@@ -459,7 +459,7 @@ const options = object(
459
459
 
460
460
  if (input !== '' && (input.endsWith('/') || !input.startsWith('/'))) {
461
461
  throw new Error(
462
- `${keypath} option must be a root-relative path that starts but doesn't end with '/'. See https://kit.svelte.dev/docs/configuration#paths`
462
+ `${keypath} option must either be the empty string or a root-relative path that starts but doesn't end with '/'. See https://kit.svelte.dev/docs/configuration#paths`
463
463
  );
464
464
  }
465
465
 
@@ -870,7 +870,7 @@ async function launch(port, https, base) {
870
870
  exec(`${cmd} ${https ? 'https' : 'http'}://localhost:${port}${base}`);
871
871
  }
872
872
 
873
- const prog = sade('svelte-kit').version('1.0.0-next.319');
873
+ const prog = sade('svelte-kit').version('1.0.0-next.321');
874
874
 
875
875
  prog
876
876
  .command('dev')
@@ -1049,7 +1049,7 @@ async function check_port(port) {
1049
1049
  function welcome({ port, host, https, open, base, loose, allow, cwd }) {
1050
1050
  if (open) launch(port, https, base);
1051
1051
 
1052
- console.log($.bold().cyan(`\n SvelteKit v${'1.0.0-next.319'}\n`));
1052
+ console.log($.bold().cyan(`\n SvelteKit v${'1.0.0-next.321'}\n`));
1053
1053
 
1054
1054
  const protocol = https ? 'https:' : 'http:';
1055
1055
  const exposed = typeof host !== 'undefined' && host !== 'localhost' && host !== '127.0.0.1';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sveltejs/kit",
3
- "version": "1.0.0-next.319",
3
+ "version": "1.0.0-next.321",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/sveltejs/kit",
package/types/index.d.ts CHANGED
@@ -207,10 +207,15 @@ export interface LoadOutput<Props extends Record<string, any> = Record<string, a
207
207
  redirect?: string;
208
208
  props?: Props;
209
209
  stuff?: Partial<App.Stuff>;
210
- maxage?: number;
210
+ cache?: LoadOutputCache;
211
211
  dependencies?: string[];
212
212
  }
213
213
 
214
+ export interface LoadOutputCache {
215
+ maxage: number;
216
+ private?: boolean;
217
+ }
218
+
214
219
  export interface Navigation {
215
220
  from: URL;
216
221
  to: URL;
@@ -117,10 +117,15 @@ export type NormalizedLoadOutput = {
117
117
  redirect?: string;
118
118
  props?: Record<string, any> | Promise<Record<string, any>>;
119
119
  stuff?: Record<string, any>;
120
- maxage?: number;
120
+ cache?: NormalizedLoadOutputCache;
121
121
  dependencies?: string[];
122
122
  };
123
123
 
124
+ export interface NormalizedLoadOutputCache {
125
+ maxage: number;
126
+ private?: boolean;
127
+ }
128
+
124
129
  export interface PageData {
125
130
  type: 'page';
126
131
  id: string;