Skip to content

Commit 28f7de3

Browse files
authored
[fix] Generate types when Svelte file missing (#6066)
Fixes #6044 Also fixes layout params. They wrongfully contained the slugs above them, too.
1 parent b1dafb8 commit 28f7de3

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

.changeset/ninety-vans-talk.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/kit': patch
3+
---
4+
5+
Generate types when Svelte file missing, fix layout params

packages/kit/src/core/sync/write_types.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,11 @@ function get_groups(manifest_data, routes_dir) {
162162
/** @type {Node} */
163163
const node = { ...nodes[i] }; // shallow copy so we don't mutate the original when setting parent
164164

165+
const file_path = /** @type {string} */ (node.component ?? node.shared ?? node.server);
165166
// skip default layout/error
166-
if (!node?.component?.startsWith(routes_dir)) continue;
167+
if (!file_path.startsWith(routes_dir)) continue;
167168

168-
const parts = /** @type {string} */ (node.component ?? node.shared ?? node.server).split('/');
169+
const parts = file_path.split('/');
169170

170171
const file = /** @type {string} */ (parts.pop());
171172
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)
284285
manifest_data.routes.forEach((route) => {
285286
if (route.type === 'page' && route.id.startsWith(dir + '/')) {
286287
// 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) {
288289
layout_params.add(name);
289290
}
290291
}

0 commit comments

Comments
 (0)