@sveltejs/kit 1.0.0-next.373 → 1.0.0-next.374

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.
@@ -17,10 +17,14 @@ function coalesce_to_error(err) {
17
17
  }
18
18
 
19
19
  /**
20
- * @param {import('types').LoadOutput} loaded
20
+ * @param {import('types').LoadOutput | void} loaded
21
21
  * @returns {import('types').NormalizedLoadOutput}
22
22
  */
23
23
  function normalize(loaded) {
24
+ if (!loaded) {
25
+ return {};
26
+ }
27
+
24
28
  // TODO remove for 1.0
25
29
  // @ts-expect-error
26
30
  if (loaded.fallthrough) {
@@ -1030,24 +1034,17 @@ function create_client({ target, session, base, trailing_slash }) {
1030
1034
  });
1031
1035
  }
1032
1036
 
1033
- let loaded;
1034
-
1035
1037
  if (import.meta.env.DEV) {
1036
1038
  try {
1037
1039
  lock_fetch();
1038
- loaded = await module.load.call(null, load_input);
1040
+ node.loaded = normalize(await module.load.call(null, load_input));
1039
1041
  } finally {
1040
1042
  unlock_fetch();
1041
1043
  }
1042
1044
  } else {
1043
- loaded = await module.load.call(null, load_input);
1044
- }
1045
-
1046
- if (!loaded) {
1047
- throw new Error('load function must return a value');
1045
+ node.loaded = normalize(await module.load.call(null, load_input));
1048
1046
  }
1049
1047
 
1050
- node.loaded = normalize(loaded);
1051
1048
  if (node.loaded.stuff) node.stuff = node.loaded.stuff;
1052
1049
  if (node.loaded.dependencies) {
1053
1050
  node.loaded.dependencies.forEach(add_dependency);
@@ -1088,7 +1085,7 @@ function create_client({ target, session, base, trailing_slash }) {
1088
1085
  let stuff = root_stuff;
1089
1086
  let stuff_changed = false;
1090
1087
 
1091
- /** @type {number | undefined} */
1088
+ /** @type {number} */
1092
1089
  let status = 200;
1093
1090
 
1094
1091
  /** @type {Error | null} */
@@ -1174,7 +1171,7 @@ function create_client({ target, session, base, trailing_slash }) {
1174
1171
 
1175
1172
  if (node.loaded) {
1176
1173
  if (node.loaded.error) {
1177
- status = node.loaded.status;
1174
+ status = node.loaded.status ?? 500;
1178
1175
  error = node.loaded.error;
1179
1176
  }
1180
1177
 
@@ -1703,7 +1700,7 @@ function create_client({ target, session, base, trailing_slash }) {
1703
1700
  if (node.loaded.error) {
1704
1701
  if (error) throw node.loaded.error;
1705
1702
  error_args = {
1706
- status: node.loaded.status,
1703
+ status: node.loaded.status ?? 500,
1707
1704
  error: node.loaded.error,
1708
1705
  url,
1709
1706
  routeId
@@ -1369,6 +1369,14 @@ async function render_response({
1369
1369
  }
1370
1370
 
1371
1371
  if (resolve_opts.ssr) {
1372
+ const leaf = /** @type {import('./types.js').Loaded} */ (branch.at(-1));
1373
+
1374
+ if (leaf.loaded.status) {
1375
+ // explicit status returned from `load` or a page endpoint trumps
1376
+ // initial status
1377
+ status = leaf.loaded.status;
1378
+ }
1379
+
1372
1380
  for (const { node, props, loaded, fetched, uses_credentials } of branch) {
1373
1381
  if (node.imports) {
1374
1382
  node.imports.forEach((url) => modulepreloads.add(url));
@@ -2096,10 +2104,14 @@ var parseString_1 = setCookie.exports.parseString = parseString;
2096
2104
  var splitCookiesString_1 = setCookie.exports.splitCookiesString = splitCookiesString;
2097
2105
 
2098
2106
  /**
2099
- * @param {import('types').LoadOutput} loaded
2107
+ * @param {import('types').LoadOutput | void} loaded
2100
2108
  * @returns {import('types').NormalizedLoadOutput}
2101
2109
  */
2102
2110
  function normalize(loaded) {
2111
+ if (!loaded) {
2112
+ return {};
2113
+ }
2114
+
2103
2115
  // TODO remove for 1.0
2104
2116
  // @ts-expect-error
2105
2117
  if (loaded.fallthrough) {
@@ -2241,7 +2253,7 @@ async function load_node({
2241
2253
  /** @type {import('set-cookie-parser').Cookie[]} */
2242
2254
  const new_cookies = [];
2243
2255
 
2244
- /** @type {import('types').LoadOutput} */
2256
+ /** @type {import('types').NormalizedLoadOutput} */
2245
2257
  let loaded;
2246
2258
 
2247
2259
  const should_prerender = node.module.prerender ?? options.prerender.default;
@@ -2264,12 +2276,10 @@ async function load_node({
2264
2276
 
2265
2277
  if (shadow.error) {
2266
2278
  loaded = {
2267
- status: shadow.status,
2268
2279
  error: shadow.error
2269
2280
  };
2270
2281
  } else if (shadow.redirect) {
2271
2282
  loaded = {
2272
- status: shadow.status,
2273
2283
  redirect: shadow.redirect
2274
2284
  };
2275
2285
  } else if (module.load) {
@@ -2537,7 +2547,7 @@ async function load_node({
2537
2547
  return proxy;
2538
2548
  },
2539
2549
  stuff: { ...stuff },
2540
- status: is_error ? status ?? null : null,
2550
+ status: (is_error ? status : shadow.status) ?? null,
2541
2551
  error: is_error ? error ?? null : null
2542
2552
  };
2543
2553
 
@@ -2550,12 +2560,7 @@ async function load_node({
2550
2560
  });
2551
2561
  }
2552
2562
 
2553
- loaded = await module.load.call(null, load_input);
2554
-
2555
- if (!loaded) {
2556
- // TODO do we still want to enforce this now that there's no fallthrough?
2557
- throw new Error(`load function must return a value${options.dev ? ` (${node.file})` : ''}`);
2558
- }
2563
+ loaded = normalize(await module.load.call(null, load_input));
2559
2564
  } else if (shadow.body) {
2560
2565
  loaded = {
2561
2566
  props: shadow.body
@@ -2564,6 +2569,8 @@ async function load_node({
2564
2569
  loaded = {};
2565
2570
  }
2566
2571
 
2572
+ loaded.status = loaded.status ?? shadow.status;
2573
+
2567
2574
  // generate __data.json files when prerendering
2568
2575
  if (shadow.body && state.prerendering) {
2569
2576
  const pathname = `${event.url.pathname.replace(/\/$/, '')}/__data.json`;
@@ -2579,7 +2586,7 @@ async function load_node({
2579
2586
  return {
2580
2587
  node,
2581
2588
  props: shadow.body,
2582
- loaded: normalize(loaded),
2589
+ loaded,
2583
2590
  stuff: loaded.stuff || stuff,
2584
2591
  fetched,
2585
2592
  set_cookie_headers: new_cookies.map((new_cookie) => {
@@ -2622,7 +2629,7 @@ async function load_shadow_data(route, event, options, prerender) {
2622
2629
 
2623
2630
  /** @type {import('types').ShadowData} */
2624
2631
  const data = {
2625
- status: 200,
2632
+ status: undefined,
2626
2633
  cookies: [],
2627
2634
  body: {}
2628
2635
  };
@@ -2662,13 +2669,13 @@ async function load_shadow_data(route, event, options, prerender) {
2662
2669
  if (get) {
2663
2670
  const { status, headers, body } = validate_shadow_output(await get(event));
2664
2671
  add_cookies(/** @type {string[]} */ (data.cookies), headers);
2665
- data.status = status;
2666
2672
 
2667
2673
  if (body instanceof Error) {
2668
2674
  if (status < 400) {
2669
2675
  data.status = 500;
2670
2676
  data.error = new Error('A non-error status code was returned with an error body');
2671
2677
  } else {
2678
+ data.status = status;
2672
2679
  data.error = body;
2673
2680
  }
2674
2681
 
@@ -2676,11 +2683,13 @@ async function load_shadow_data(route, event, options, prerender) {
2676
2683
  }
2677
2684
 
2678
2685
  if (status >= 400) {
2686
+ data.status = status;
2679
2687
  data.error = new Error('Failed to load data');
2680
2688
  return data;
2681
2689
  }
2682
2690
 
2683
2691
  if (status >= 300) {
2692
+ data.status = status;
2684
2693
  data.redirect = /** @type {string} */ (
2685
2694
  headers instanceof Headers ? headers.get('location') : headers.location
2686
2695
  );
@@ -2969,7 +2978,8 @@ async function respond$1(opts) {
2969
2978
  }
2970
2979
 
2971
2980
  if (loaded.loaded.error) {
2972
- ({ status, error } = loaded.loaded);
2981
+ error = loaded.loaded.error;
2982
+ status = loaded.loaded.status ?? 500;
2973
2983
  }
2974
2984
  } catch (err) {
2975
2985
  const e = coalesce_to_error(err);
package/dist/cli.js CHANGED
@@ -18,7 +18,7 @@ function handle_error(e) {
18
18
  process.exit(1);
19
19
  }
20
20
 
21
- const prog = sade('svelte-kit').version('1.0.0-next.373');
21
+ const prog = sade('svelte-kit').version('1.0.0-next.374');
22
22
 
23
23
  prog
24
24
  .command('package')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sveltejs/kit",
3
- "version": "1.0.0-next.373",
3
+ "version": "1.0.0-next.374",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/sveltejs/kit",
@@ -80,7 +80,7 @@ declare module '$app/env' {
80
80
  export const dev: boolean;
81
81
 
82
82
  /**
83
- * The Vite.js mode the app is running in. Configure in `config.kit.vite.mode`.
83
+ * The Vite.js mode the app is running in. Configure in [`vite.config.js`](https://vitejs.dev/config/shared-options.html#mode).
84
84
  * Vite.js loads the dotenv file associated with the provided mode, `.env.[mode]` or `.env.[mode].local`.
85
85
  * By default, `vite dev` runs with `mode=development` and `vite build` runs with `mode=production`.
86
86
  */
package/types/index.d.ts CHANGED
@@ -151,7 +151,6 @@ export interface KitConfig {
151
151
  name?: string;
152
152
  pollInterval?: number;
153
153
  };
154
- vite?: import('vite').UserConfig | (() => MaybePromise<import('vite').UserConfig>);
155
154
  }
156
155
 
157
156
  export interface ExternalFetch {
@@ -183,7 +182,7 @@ export interface Load<
183
182
  InputProps extends Record<string, any> = Record<string, any>,
184
183
  OutputProps extends Record<string, any> = InputProps
185
184
  > {
186
- (event: LoadEvent<Params, InputProps>): MaybePromise<LoadOutput<OutputProps>>;
185
+ (event: LoadEvent<Params, InputProps>): MaybePromise<LoadOutput<OutputProps> | void>;
187
186
  }
188
187
 
189
188
  export interface LoadEvent<
@@ -113,7 +113,7 @@ export interface MethodOverride {
113
113
  }
114
114
 
115
115
  export type NormalizedLoadOutput = {
116
- status: number;
116
+ status?: number;
117
117
  error?: Error;
118
118
  redirect?: string;
119
119
  props?: Record<string, any> | Promise<Record<string, any>>;
@@ -153,12 +153,9 @@ export interface PrerenderOptions {
153
153
 
154
154
  export type RecursiveRequired<T> = {
155
155
  // Recursive implementation of TypeScript's Required utility type.
156
- // Will recursively continue until it reaches primitive or union
157
- // with a Function in it, except those commented below
156
+ // Will recursively continue until it reaches a primitive or Function
158
157
  [K in keyof T]-?: Extract<T[K], Function> extends never // If it does not have a Function type
159
158
  ? RecursiveRequired<T[K]> // recursively continue through.
160
- : K extends 'vite' // If it reaches the 'vite' key
161
- ? Extract<T[K], Function> // only take the Function type.
162
159
  : T[K]; // Use the exact type for everything else
163
160
  };
164
161