Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(file-router): preserve empty children for layout routes #2572

Merged
merged 1 commit into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function createImport(mod: string, file: string): ImportDeclaration {
*/
function createRouteData(path: string, mod: string | undefined, children?: readonly CallExpression[]): CallExpression {
return template(
`const route = createRoute("${path}"${mod ? `, ${mod}` : ''}${children && children.length > 0 ? `, CHILDREN` : ''})`,
`const route = createRoute("${path}"${mod ? `, ${mod}` : ''}${children ? `, CHILDREN` : ''})`,
([statement]) => (statement as VariableStatement).declarationList.declarations[0].initializer as CallExpression,
[
transformer((node) =>
Expand Down
11 changes: 11 additions & 0 deletions packages/ts/file-router/test/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export async function createTestingRouteFiles(dir: URL): Promise<void> {
mkdir(new URL('empty-dir/empty-file-subdir/', dir), { recursive: true }),
mkdir(new URL('test', dir), { recursive: true }),
mkdir(new URL('test/issue-002378/{requiredParam}', dir), { recursive: true }),
mkdir(new URL('test/issue-002571-empty-layout/', dir), { recursive: true }),
]);
await Promise.all([
appendFile(
Expand Down Expand Up @@ -109,6 +110,11 @@ export async function createTestingRouteFiles(dir: URL): Promise<void> {
new URL('test/issue-002378/{requiredParam}/edit.tsx', dir),
'export default function Issue002378RequiredParam() {};',
),
appendFile(
new URL('test/issue-002571-empty-layout/@layout.tsx', dir),
'export default function Issue002571EmptyLayout() {};',
),
// this file has no title configured, so it must be derived from its file name
appendFile(
new URL('test/issue-002879-config-below.tsx', dir),
'export default function Issue002879ConfigBelow() {};\nexport const config = { title: "Config Below" };',
Expand Down Expand Up @@ -192,6 +198,11 @@ export function createTestingRouteMeta(dir: URL): readonly RouteMeta[] {
},
],
},
{
path: 'issue-002571-empty-layout',
layout: new URL('test/issue-002571-empty-layout/@layout.tsx', dir),
children: [],
},
{
path: 'issue-002879-config-below',
file: new URL('test/issue-002879-config-below.tsx', dir),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ import * as Layout8 from "../views/profile/friends/@layout.js";
import * as Page10 from "../views/test/{{optional}}.js";
import * as Page11 from "../views/test/{...wildcard}.js";
import * as Page12 from "../views/test/issue-002378/{requiredParam}/edit.js";
import * as Page15 from "../views/test/issue-002879-config-below.js";
import * as Layout15 from "../views/test/issue-002571-empty-layout/@layout.js";
import * as Page16 from "../views/test/issue-002879-config-below.js";
const routes: readonly AgnosticRoute[] = [
createRoute("nameToReplace", Page0),
createRoute("profile", [
Expand All @@ -62,7 +63,8 @@ const routes: readonly AgnosticRoute[] = [
createRoute("edit", Page12)
])
]),
createRoute("issue-002879-config-below", Page15)
createRoute("issue-002571-empty-layout", Layout15, []),
createRoute("issue-002879-config-below", Page16)
])
];
export default routes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ describe('@vaadin/hilla-file-router', () => {
},
],
},
{ route: 'issue-002571-empty-layout', params: {}, title: 'Issue002571 Empty Layout', children: [] },
{ route: 'issue-002879-config-below', title: 'Config Below', params: {} },
],
},
Expand Down
Loading