@sveltejs/kit 1.0.0-next.422 → 1.0.0-next.425

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sveltejs/kit",
3
- "version": "1.0.0-next.422",
3
+ "version": "1.0.0-next.425",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/sveltejs/kit",
@@ -162,10 +162,11 @@ function get_groups(manifest_data, routes_dir) {
162
162
  /** @type {Node} */
163
163
  const node = { ...nodes[i] }; // shallow copy so we don't mutate the original when setting parent
164
164
 
165
+ const file_path = /** @type {string} */ (node.component ?? node.shared ?? node.server);
165
166
  // skip default layout/error
166
- if (!node?.component?.startsWith(routes_dir)) continue;
167
+ if (!file_path.startsWith(routes_dir)) continue;
167
168
 
168
- const parts = /** @type {string} */ (node.component ?? node.shared ?? node.server).split('/');
169
+ const parts = file_path.split('/');
169
170
 
170
171
  const file = /** @type {string} */ (parts.pop());
171
172
  const dir = parts.join('/').slice(routes_dir.length + 1);
@@ -284,7 +285,7 @@ function write_types_for_dir(config, manifest_data, routes_dir, dir, groups, ts)
284
285
  manifest_data.routes.forEach((route) => {
285
286
  if (route.type === 'page' && route.id.startsWith(dir + '/')) {
286
287
  // TODO this is O(n^2), see if we need to speed it up
287
- for (const name of parse_route_id(route.id).names) {
288
+ for (const name of parse_route_id(route.id.slice(dir.length + 1)).names) {
288
289
  layout_params.add(name);
289
290
  }
290
291
  }
@@ -425,7 +426,7 @@ function process_node(ts, node, outdir, params, groups) {
425
426
  written_proxies.push(write(`${outdir}/proxy${basename}`, proxy.code));
426
427
  }
427
428
 
428
- server_data = get_data_type(node.server, 'load', 'null', proxy);
429
+ server_data = get_data_type(node.server, 'null', proxy);
429
430
  server_load = `Kit.ServerLoad<${params}, ${get_parent_type('LayoutServerData')}, OutputData>`;
430
431
 
431
432
  if (proxy) {
@@ -449,6 +450,8 @@ function process_node(ts, node, outdir, params, groups) {
449
450
  server_data = 'null';
450
451
  }
451
452
 
453
+ const parent_type = get_parent_type('LayoutData');
454
+
452
455
  if (node.shared) {
453
456
  const content = fs.readFileSync(node.shared, 'utf8');
454
457
  const proxy = tweak_types(ts, content, shared_names);
@@ -456,29 +459,32 @@ function process_node(ts, node, outdir, params, groups) {
456
459
  written_proxies.push(write(`${outdir}/proxy${path.basename(node.shared)}`, proxy.code));
457
460
  }
458
461
 
459
- data = get_data_type(node.shared, 'load', server_data, proxy);
460
- load = `Kit.Load<${params}, ${server_data}, ${get_parent_type('LayoutData')}, OutputData>`;
462
+ const type = get_data_type(node.shared, `${parent_type} & ${server_data}`, proxy);
463
+
464
+ data = `Omit<${parent_type}, keyof ${type}> & ${type}`;
465
+ load = `Kit.Load<${params}, ${server_data}, ${parent_type}, OutputData>`;
466
+ } else if (server_data === 'null') {
467
+ data = parent_type;
461
468
  } else {
462
- data = server_data;
469
+ data = `Omit<${parent_type}, keyof ${server_data}> & ${server_data}`;
463
470
  }
464
471
 
465
472
  return { data, server_data, load, server_load, errors, written_proxies };
466
473
 
467
474
  /**
468
475
  * @param {string} file_path
469
- * @param {string} method
470
476
  * @param {string} fallback
471
477
  * @param {Proxy} proxy
472
478
  */
473
- function get_data_type(file_path, method, fallback, proxy) {
479
+ function get_data_type(file_path, fallback, proxy) {
474
480
  if (proxy) {
475
- if (proxy.exports.includes(method)) {
481
+ if (proxy.exports.includes('load')) {
476
482
  // If the file wasn't tweaked, we can use the return type of the original file.
477
483
  // The advantage is that type updates are reflected without saving.
478
484
  const from = proxy.modified
479
485
  ? `./proxy${replace_ext_with_js(path.basename(file_path))}`
480
486
  : path_to_original(outdir, file_path);
481
- return `Kit.AwaitedProperties<Awaited<ReturnType<typeof import('${from}').${method}>>>`;
487
+ return `Kit.AwaitedProperties<Awaited<ReturnType<typeof import('${from}').load>>>`;
482
488
  } else {
483
489
  return fallback;
484
490
  }
@@ -268,7 +268,22 @@ export function create_client({ target, base, trailing_slash }) {
268
268
  navigation_result.props.page.url = url;
269
269
  }
270
270
 
271
- root.$set(navigation_result.props);
271
+ if (import.meta.env.DEV) {
272
+ // Nasty hack to silence harmless warnings the user can do nothing about
273
+ const warn = console.warn;
274
+ console.warn = (...args) => {
275
+ if (
276
+ args.length !== 1 ||
277
+ !/<(Layout|Page)(_[\w$]+)?> was created with unknown prop '(data|errors)'/.test(args[0])
278
+ ) {
279
+ warn(...args);
280
+ }
281
+ };
282
+ root.$set(navigation_result.props);
283
+ tick().then(() => (console.warn = warn));
284
+ } else {
285
+ root.$set(navigation_result.props);
286
+ }
272
287
  } else {
273
288
  initialize(navigation_result);
274
289
  }
@@ -347,11 +362,30 @@ export function create_client({ target, base, trailing_slash }) {
347
362
 
348
363
  page = result.props.page;
349
364
 
350
- root = new Root({
351
- target,
352
- props: { ...result.props, stores },
353
- hydrate: true
354
- });
365
+ if (import.meta.env.DEV) {
366
+ // Nasty hack to silence harmless warnings the user can do nothing about
367
+ const warn = console.warn;
368
+ console.warn = (...args) => {
369
+ if (
370
+ args.length !== 1 ||
371
+ !/<(Layout|Page)(_[\w$]+)?> was created with unknown prop '(data|errors)'/.test(args[0])
372
+ ) {
373
+ warn(...args);
374
+ }
375
+ };
376
+ root = new Root({
377
+ target,
378
+ props: { ...result.props, stores },
379
+ hydrate: true
380
+ });
381
+ console.warn = warn;
382
+ } else {
383
+ root = new Root({
384
+ target,
385
+ props: { ...result.props, stores },
386
+ hydrate: true
387
+ });
388
+ }
355
389
 
356
390
  if (router_enabled) {
357
391
  const navigation = { from: null, to: new URL(location.href) };
@@ -403,10 +437,10 @@ export function create_client({ target, base, trailing_slash }) {
403
437
  let data = {};
404
438
  let data_changed = false;
405
439
  for (let i = 0; i < filtered.length; i += 1) {
406
- Object.assign(data, filtered[i].data);
440
+ data = { ...data, ...filtered[i].data };
407
441
  // Only set props if the node actually updated. This prevents needless rerenders.
408
- if (!current.branch.some((node) => node === filtered[i])) {
409
- result.props[`data_${i}`] = filtered[i].data;
442
+ if (data_changed || !current.branch.some((node) => node === filtered[i])) {
443
+ result.props[`data_${i}`] = data;
410
444
  data_changed = true;
411
445
  }
412
446
  }
@@ -83,18 +83,31 @@ export async function render_response({
83
83
  navigating: writable(null),
84
84
  updated
85
85
  },
86
- /** @type {import('types').Page} */
87
- page: {
88
- error,
89
- params: /** @type {Record<string, any>} */ (event.params),
90
- routeId: event.routeId,
91
- status,
92
- url: state.prerendering ? new PrerenderingURL(event.url) : event.url,
93
- data: branch.reduce((acc, { data }) => (Object.assign(acc, data), acc), {})
94
- },
95
86
  components: await Promise.all(branch.map(({ node }) => node.component()))
96
87
  };
97
88
 
89
+ let data = {};
90
+
91
+ // props_n (instead of props[n]) makes it easy to avoid
92
+ // unnecessary updates for layout components
93
+ for (let i = 0; i < branch.length; i += 1) {
94
+ data = { ...data, ...branch[i].data };
95
+ props[`data_${i}`] = data;
96
+ }
97
+
98
+ props.page = {
99
+ error,
100
+ params: /** @type {Record<string, any>} */ (event.params),
101
+ routeId: event.routeId,
102
+ status,
103
+ url: state.prerendering ? new PrerenderingURL(event.url) : event.url,
104
+ data
105
+ };
106
+
107
+ if (validation_errors) {
108
+ props.errors = validation_errors;
109
+ }
110
+
98
111
  // TODO remove this for 1.0
99
112
  /**
100
113
  * @param {string} property
@@ -112,16 +125,6 @@ export async function render_response({
112
125
  print_error('path', 'pathname');
113
126
  print_error('query', 'searchParams');
114
127
 
115
- // props_n (instead of props[n]) makes it easy to avoid
116
- // unnecessary updates for layout components
117
- for (let i = 0; i < branch.length; i += 1) {
118
- props[`data_${i}`] = branch[i].data;
119
- }
120
-
121
- if (validation_errors) {
122
- props.errors = validation_errors;
123
- }
124
-
125
128
  rendered = options.root.render(props);
126
129
 
127
130
  for (const { node } of branch) {
@@ -123,6 +123,9 @@ export function get_default_build_config({ config, input, ssr, outDir }) {
123
123
  resolve: {
124
124
  alias: get_aliases(config.kit)
125
125
  },
126
+ optimizeDeps: {
127
+ exclude: ['@sveltejs/kit']
128
+ },
126
129
  ssr: {
127
130
  noExternal: ['@sveltejs/kit']
128
131
  },
package/src/vite/index.js CHANGED
@@ -273,6 +273,9 @@ function kit() {
273
273
  // under different IDs, which breaks a bunch of stuff
274
274
  // https://github.com/vitejs/vite/pull/9296
275
275
  external: ['@sveltejs/kit']
276
+ },
277
+ optimizeDeps: {
278
+ exclude: ['@sveltejs/kit']
276
279
  }
277
280
  };
278
281