diff --git a/package-lock.json b/package-lock.json index 0031d6499..8b66ebbf4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -19125,12 +19125,12 @@ }, "packages/ts/file-router": { "name": "@vaadin/hilla-file-router", - "version": "24.6.0-beta5", + "version": "24.6.0-beta6", "license": "Apache-2.0", "dependencies": { - "@vaadin/hilla-generator-utils": "24.6.0-beta5", - "@vaadin/hilla-react-auth": "24.6.0-beta5", - "@vaadin/hilla-react-signals": "24.6.0-beta5", + "@vaadin/hilla-generator-utils": "24.6.0-beta6", + "@vaadin/hilla-react-auth": "24.6.0-beta6", + "@vaadin/hilla-react-signals": "24.6.0-beta6", "react": "^18.2.0", "rollup": "^4.12.0", "typescript": "5.6.2" @@ -19175,7 +19175,7 @@ }, "packages/ts/frontend": { "name": "@vaadin/hilla-frontend", - "version": "24.6.0-beta5", + "version": "24.6.0-beta6", "license": "Apache-2.0", "dependencies": { "@vaadin/common-frontend": "^0.0.19", @@ -19220,11 +19220,11 @@ }, "packages/ts/generator-cli": { "name": "@vaadin/hilla-generator-cli", - "version": "24.6.0-beta5", + "version": "24.6.0-beta6", "license": "Apache 2.0", "dependencies": { - "@vaadin/hilla-generator-core": "24.6.0-beta5", - "@vaadin/hilla-generator-utils": "24.6.0-beta5", + "@vaadin/hilla-generator-core": "24.6.0-beta6", + "@vaadin/hilla-generator-utils": "24.6.0-beta6", "get-stdin": "^9.0.0", "meow": "^12.1.1" }, @@ -19238,7 +19238,7 @@ "@types/node": "^20.7.1", "@types/sinon": "^10.0.17", "@types/sinon-chai": "^3.2.10", - "@vaadin/hilla-generator-core": "24.6.0-beta5", + "@vaadin/hilla-generator-core": "24.6.0-beta6", "c8": "^10.1.2", "chai": "^4.3.10", "chai-as-promised": "^7.1.1", @@ -19285,11 +19285,11 @@ }, "packages/ts/generator-core": { "name": "@vaadin/hilla-generator-core", - "version": "24.6.0-beta5", + "version": "24.6.0-beta6", "license": "Apache 2.0", "dependencies": { "@apidevtools/swagger-parser": "^10.1.0", - "@vaadin/hilla-generator-utils": "24.6.0-beta5", + "@vaadin/hilla-generator-utils": "24.6.0-beta6", "meow": "^12.1.1", "openapi-types": "^12.1.3", "typescript": "5.6.2" @@ -19357,12 +19357,12 @@ }, "packages/ts/generator-plugin-backbone": { "name": "@vaadin/hilla-generator-plugin-backbone", - "version": "24.6.0-beta5", + "version": "24.6.0-beta6", "license": "Apache 2.0", "dependencies": { - "@vaadin/hilla-generator-core": "24.6.0-beta5", - "@vaadin/hilla-generator-plugin-client": "24.6.0-beta5", - "@vaadin/hilla-generator-utils": "24.6.0-beta5", + "@vaadin/hilla-generator-core": "24.6.0-beta6", + "@vaadin/hilla-generator-plugin-client": "24.6.0-beta6", + "@vaadin/hilla-generator-utils": "24.6.0-beta6", "fast-deep-equal": "^3.1.3", "openapi-types": "^12.1.3", "typescript": "5.6.2" @@ -19373,8 +19373,8 @@ "@types/node": "^20.7.1", "@types/sinon": "^10.0.17", "@types/sinon-chai": "^3.2.10", - "@vaadin/hilla-generator-core": "24.6.0-beta5", - "@vaadin/hilla-generator-plugin-client": "24.6.0-beta5", + "@vaadin/hilla-generator-core": "24.6.0-beta6", + "@vaadin/hilla-generator-plugin-client": "24.6.0-beta6", "c8": "^10.1.2", "chai": "^4.3.10", "concurrently": "^8.2.1", @@ -19422,12 +19422,12 @@ }, "packages/ts/generator-plugin-barrel": { "name": "@vaadin/hilla-generator-plugin-barrel", - "version": "24.6.0-beta5", + "version": "24.6.0-beta6", "license": "Apache 2.0", "dependencies": { - "@vaadin/hilla-generator-core": "24.6.0-beta5", - "@vaadin/hilla-generator-plugin-backbone": "24.6.0-beta5", - "@vaadin/hilla-generator-utils": "24.6.0-beta5", + "@vaadin/hilla-generator-core": "24.6.0-beta6", + "@vaadin/hilla-generator-plugin-backbone": "24.6.0-beta6", + "@vaadin/hilla-generator-utils": "24.6.0-beta6", "typescript": "5.6.2" }, "devDependencies": { @@ -19436,8 +19436,8 @@ "@types/node": "^20.7.1", "@types/sinon": "^10.0.17", "@types/sinon-chai": "^3.2.10", - "@vaadin/hilla-generator-core": "24.6.0-beta5", - "@vaadin/hilla-generator-plugin-backbone": "24.6.0-beta5", + "@vaadin/hilla-generator-core": "24.6.0-beta6", + "@vaadin/hilla-generator-plugin-backbone": "24.6.0-beta6", "c8": "^10.1.2", "chai": "^4.3.10", "concurrently": "^8.2.1", @@ -19485,11 +19485,11 @@ }, "packages/ts/generator-plugin-client": { "name": "@vaadin/hilla-generator-plugin-client", - "version": "24.6.0-beta5", + "version": "24.6.0-beta6", "license": "Apache 2.0", "dependencies": { - "@vaadin/hilla-generator-core": "24.6.0-beta5", - "@vaadin/hilla-generator-utils": "24.6.0-beta5", + "@vaadin/hilla-generator-core": "24.6.0-beta6", + "@vaadin/hilla-generator-utils": "24.6.0-beta6", "typescript": "5.6.2" }, "devDependencies": { @@ -19498,7 +19498,7 @@ "@types/node": "^20.7.1", "@types/sinon": "^10.0.17", "@types/sinon-chai": "^3.2.10", - "@vaadin/hilla-generator-core": "24.6.0-beta5", + "@vaadin/hilla-generator-core": "24.6.0-beta6", "c8": "^10.1.2", "chai": "^4.3.10", "concurrently": "^8.2.1", @@ -19546,13 +19546,13 @@ }, "packages/ts/generator-plugin-model": { "name": "@vaadin/hilla-generator-plugin-model", - "version": "24.6.0-beta5", + "version": "24.6.0-beta6", "license": "Apache 2.0", "dependencies": { - "@vaadin/hilla-generator-core": "24.6.0-beta5", - "@vaadin/hilla-generator-plugin-backbone": "24.6.0-beta5", - "@vaadin/hilla-generator-utils": "24.6.0-beta5", - "@vaadin/hilla-lit-form": "24.6.0-beta5", + "@vaadin/hilla-generator-core": "24.6.0-beta6", + "@vaadin/hilla-generator-plugin-backbone": "24.6.0-beta6", + "@vaadin/hilla-generator-utils": "24.6.0-beta6", + "@vaadin/hilla-lit-form": "24.6.0-beta6", "fast-deep-equal": "^3.1.3", "openapi-types": "^12.1.3", "typescript": "5.6.2" @@ -19563,8 +19563,8 @@ "@types/node": "^20.7.1", "@types/sinon": "^10.0.17", "@types/sinon-chai": "^3.2.10", - "@vaadin/hilla-generator-core": "24.6.0-beta5", - "@vaadin/hilla-generator-plugin-client": "24.6.0-beta5", + "@vaadin/hilla-generator-core": "24.6.0-beta6", + "@vaadin/hilla-generator-plugin-client": "24.6.0-beta6", "c8": "^10.1.2", "chai": "^4.3.10", "concurrently": "^8.2.1", @@ -19612,12 +19612,12 @@ }, "packages/ts/generator-plugin-push": { "name": "@vaadin/hilla-generator-plugin-push", - "version": "24.6.0-beta5", + "version": "24.6.0-beta6", "license": "Apache 2.0", "dependencies": { - "@vaadin/hilla-generator-core": "24.6.0-beta5", - "@vaadin/hilla-generator-plugin-client": "24.6.0-beta5", - "@vaadin/hilla-generator-utils": "24.6.0-beta5", + "@vaadin/hilla-generator-core": "24.6.0-beta6", + "@vaadin/hilla-generator-plugin-client": "24.6.0-beta6", + "@vaadin/hilla-generator-utils": "24.6.0-beta6", "fast-deep-equal": "^3.1.3", "openapi-types": "^12.1.3", "typescript": "5.6.2" @@ -19628,8 +19628,8 @@ "@types/node": "^20.7.1", "@types/sinon": "^10.0.17", "@types/sinon-chai": "^3.2.10", - "@vaadin/hilla-generator-core": "24.6.0-beta5", - "@vaadin/hilla-generator-plugin-client": "24.6.0-beta5", + "@vaadin/hilla-generator-core": "24.6.0-beta6", + "@vaadin/hilla-generator-plugin-client": "24.6.0-beta6", "c8": "^10.1.2", "chai": "^4.3.10", "concurrently": "^8.2.1", @@ -19677,13 +19677,13 @@ }, "packages/ts/generator-plugin-signals": { "name": "@vaadin/hilla-generator-plugin-signals", - "version": "24.6.0-beta5", + "version": "24.6.0-beta6", "license": "Apache 2.0", "dependencies": { - "@vaadin/hilla-generator-core": "24.6.0-beta5", - "@vaadin/hilla-generator-plugin-backbone": "24.6.0-beta5", - "@vaadin/hilla-generator-plugin-client": "24.6.0-beta5", - "@vaadin/hilla-generator-utils": "24.6.0-beta5", + "@vaadin/hilla-generator-core": "24.6.0-beta6", + "@vaadin/hilla-generator-plugin-backbone": "24.6.0-beta6", + "@vaadin/hilla-generator-plugin-client": "24.6.0-beta6", + "@vaadin/hilla-generator-utils": "24.6.0-beta6", "fast-deep-equal": "^3.1.3", "iterator-helpers-polyfill": "^3.0.1", "openapi-types": "^12.1.3", @@ -19695,8 +19695,8 @@ "@types/node": "^20.7.1", "@types/sinon": "^10.0.17", "@types/sinon-chai": "^3.2.10", - "@vaadin/hilla-generator-core": "24.6.0-beta5", - "@vaadin/hilla-generator-plugin-client": "24.6.0-beta5", + "@vaadin/hilla-generator-core": "24.6.0-beta6", + "@vaadin/hilla-generator-plugin-client": "24.6.0-beta6", "c8": "^8.0.1", "chai": "^4.3.10", "concurrently": "^8.2.1", @@ -19845,13 +19845,13 @@ }, "packages/ts/generator-plugin-subtypes": { "name": "@vaadin/hilla-generator-plugin-subtypes", - "version": "24.6.0-beta5", + "version": "24.6.0-beta6", "license": "Apache 2.0", "dependencies": { - "@vaadin/hilla-generator-core": "24.6.0-beta5", - "@vaadin/hilla-generator-plugin-client": "24.6.0-beta5", - "@vaadin/hilla-generator-plugin-model": "24.6.0-beta5", - "@vaadin/hilla-generator-utils": "24.6.0-beta5", + "@vaadin/hilla-generator-core": "24.6.0-beta6", + "@vaadin/hilla-generator-plugin-client": "24.6.0-beta6", + "@vaadin/hilla-generator-plugin-model": "24.6.0-beta6", + "@vaadin/hilla-generator-utils": "24.6.0-beta6", "fast-deep-equal": "^3.1.3", "openapi-types": "^12.1.3", "typescript": "5.6.2" @@ -19862,9 +19862,9 @@ "@types/node": "^20.7.1", "@types/sinon": "^10.0.17", "@types/sinon-chai": "^3.2.10", - "@vaadin/hilla-generator-core": "24.6.0-beta5", - "@vaadin/hilla-generator-plugin-client": "24.6.0-beta5", - "@vaadin/hilla-generator-plugin-model": "24.6.0-beta5", + "@vaadin/hilla-generator-core": "24.6.0-beta6", + "@vaadin/hilla-generator-plugin-client": "24.6.0-beta6", + "@vaadin/hilla-generator-plugin-model": "24.6.0-beta6", "c8": "^10.1.2", "chai": "^4.3.10", "concurrently": "^8.2.1", @@ -19912,7 +19912,7 @@ }, "packages/ts/generator-utils": { "name": "@vaadin/hilla-generator-utils", - "version": "24.6.0-beta5", + "version": "24.6.0-beta6", "license": "Apache 2.0", "dependencies": { "pino": "^8.15.1", @@ -19972,10 +19972,10 @@ }, "packages/ts/lit-form": { "name": "@vaadin/hilla-lit-form", - "version": "24.6.0-beta5", + "version": "24.6.0-beta6", "license": "Apache-2.0", "dependencies": { - "@vaadin/hilla-frontend": "24.6.0-beta5", + "@vaadin/hilla-frontend": "24.6.0-beta6", "validator": "^13.11.0" }, "devDependencies": { @@ -20011,10 +20011,10 @@ }, "packages/ts/models": { "name": "@vaadin/hilla-models", - "version": "24.6.0-beta5", + "version": "24.6.0-beta6", "license": "Apache-2.0", "dependencies": { - "@vaadin/hilla-lit-form": "24.6.0-beta5" + "@vaadin/hilla-lit-form": "24.6.0-beta6" }, "devDependencies": { "@esm-bundle/chai": "^4.3.4-fix.0", @@ -20105,10 +20105,10 @@ }, "packages/ts/react-auth": { "name": "@vaadin/hilla-react-auth", - "version": "24.6.0-beta5", + "version": "24.6.0-beta6", "license": "Apache-2.0", "dependencies": { - "@vaadin/hilla-frontend": "24.6.0-beta5" + "@vaadin/hilla-frontend": "24.6.0-beta6" }, "devDependencies": { "@esm-bundle/chai": "^4.3.4-fix.0", @@ -20178,12 +20178,12 @@ }, "packages/ts/react-crud": { "name": "@vaadin/hilla-react-crud", - "version": "24.6.0-beta5", + "version": "24.6.0-beta6", "license": "Apache-2.0", "dependencies": { - "@vaadin/hilla-frontend": "24.6.0-beta5", - "@vaadin/hilla-lit-form": "24.6.0-beta5", - "@vaadin/hilla-react-form": "24.6.0-beta5", + "@vaadin/hilla-frontend": "24.6.0-beta6", + "@vaadin/hilla-lit-form": "24.6.0-beta6", + "@vaadin/hilla-react-form": "24.6.0-beta6", "@vaadin/react-components": "24.6.0-rc1" }, "devDependencies": { @@ -20255,10 +20255,10 @@ }, "packages/ts/react-form": { "name": "@vaadin/hilla-react-form", - "version": "24.6.0-beta5", + "version": "24.6.0-beta6", "license": "Apache-2.0", "dependencies": { - "@vaadin/hilla-lit-form": "24.6.0-beta5" + "@vaadin/hilla-lit-form": "24.6.0-beta6" }, "devDependencies": { "@esm-bundle/chai": "^4.3.4-fix.0", @@ -20327,11 +20327,11 @@ }, "packages/ts/react-i18n": { "name": "@vaadin/hilla-react-i18n", - "version": "24.6.0-beta5", + "version": "24.6.0-beta6", "license": "Apache-2.0", "dependencies": { - "@vaadin/hilla-frontend": "24.6.0-beta5", - "@vaadin/hilla-react-signals": "24.6.0-beta5", + "@vaadin/hilla-frontend": "24.6.0-beta6", + "@vaadin/hilla-react-signals": "24.6.0-beta6", "intl-messageformat": "^10.5.11" }, "devDependencies": { @@ -20402,11 +20402,11 @@ }, "packages/ts/react-signals": { "name": "@vaadin/hilla-react-signals", - "version": "24.6.0-beta5", + "version": "24.6.0-beta6", "license": "Apache-2.0", "dependencies": { "@preact/signals-react": "^2.0.0", - "@vaadin/hilla-frontend": "24.6.0-beta5", + "@vaadin/hilla-frontend": "24.6.0-beta6", "nanoid": "^5.0.7" }, "devDependencies": { diff --git a/packages/ts/file-router/package.json b/packages/ts/file-router/package.json index 2c2a93706..b2773d998 100644 --- a/packages/ts/file-router/package.json +++ b/packages/ts/file-router/package.json @@ -1,6 +1,6 @@ { "name": "@vaadin/hilla-file-router", - "version": "24.6.0-beta5", + "version": "24.6.0-beta6", "description": "Hilla file-based router", "main": "index.js", "module": "index.js", @@ -81,9 +81,9 @@ "type-fest": "^4.9.0" }, "dependencies": { - "@vaadin/hilla-generator-utils": "24.6.0-beta5", - "@vaadin/hilla-react-auth": "24.6.0-beta5", - "@vaadin/hilla-react-signals": "24.6.0-beta5", + "@vaadin/hilla-generator-utils": "24.6.0-beta6", + "@vaadin/hilla-react-auth": "24.6.0-beta6", + "@vaadin/hilla-react-signals": "24.6.0-beta6", "react": "^18.2.0", "rollup": "^4.12.0", "typescript": "5.6.2" diff --git a/packages/ts/file-router/src/runtime/RouterConfigurationBuilder.ts b/packages/ts/file-router/src/runtime/RouterConfigurationBuilder.ts index 0180c653b..9752c01c6 100644 --- a/packages/ts/file-router/src/runtime/RouterConfigurationBuilder.ts +++ b/packages/ts/file-router/src/runtime/RouterConfigurationBuilder.ts @@ -37,13 +37,14 @@ function isReactRouteModule(module?: Module): module is RouteModule = ( - original: RouteObject | undefined, - overriding: T | undefined, - children?: RouteList, -) => RouteObject | undefined; +export type RouteTransformerOptions = Readonly<{ + children?: RouteList; + original?: RouteObject; + overriding?: T; + dupe: boolean; +}>; -export type RouteListSplittingRule = (route: RouteObject) => boolean; +export type RouteTransformer = (opts: RouteTransformerOptions) => RouteObject | undefined; type RoutesModifier = (routes: RouteList | undefined) => RouteList | undefined; @@ -90,7 +91,7 @@ export class RouterConfigurationBuilder { * @param routes - A list of routes to add to the current list. */ withFileRoutes(routes: readonly AgnosticRoute[]): this { - return this.update(routes, (original, added, children) => { + return this.update(routes, ({ original, overriding: added, children }) => { if (added) { const { module, path, flowLayout } = added; if (!isReactRouteModule(module)) { @@ -146,8 +147,8 @@ export class RouterConfigurationBuilder { { index: true, element: createElement(component), handle: config }, ]; - this.update(fallbackRoutes, (original, added, children) => { - if (original && !getRouteHandleFlag(original, RouteHandleFlags.IGNORE_FALLBACK)) { + this.update(fallbackRoutes, ({ original, overriding: added, children, dupe }) => { + if (original && !getRouteHandleFlag(original, RouteHandleFlags.IGNORE_FALLBACK) && !dupe) { if (!children) { return original; } @@ -282,7 +283,7 @@ export class RouterConfigurationBuilder { * and the user is not authenticated. */ protect(redirectPath?: string): this { - this.update(undefined, (route, _, children) => { + this.update(undefined, ({ original: route, children }) => { const finalRoute = protectRoute(route!, redirectPath); finalRoute.children = children as RouteObject[] | undefined; return finalRoute; @@ -291,11 +292,18 @@ export class RouterConfigurationBuilder { return this; } + /** + * Deeply updates the current list of routes with the given routes merging + * them in process. + * + * @param routes - A list of routes to merge with the current list. + * @param callback - A callback to transform the routes during the merge. + */ update(routes: undefined, callback: RouteTransformer): this; update(routes: readonly T[], callback?: RouteTransformer): this; update( routes: readonly T[] | undefined, - callback: RouteTransformer = (original, overriding, children) => + callback: RouteTransformer = ({ original, overriding, children }) => ({ ...original, ...overriding, @@ -303,42 +311,104 @@ export class RouterConfigurationBuilder { }) as RouteObject, ): this { this.#modifiers.push((existingRoutes) => - transformTree<[RouteList | undefined, readonly T[] | undefined], RouteList | undefined>( + // Going through the existing and added list of routes. + transformTree( [existingRoutes, routes], null, ([original, added], next) => { if (original && added) { - const originalMap = new Map(original.map((route) => createRouteEntry(route))); - const addedMap = new Map(added.map((route) => createRouteEntry(route))); - - const paths = new Set([...originalMap.keys(), ...addedMap.keys()]); + // If we have both original and added routes, we have to merge them. + const final: Array = []; + const paths = new Set([...original.map(({ path }) => path), ...added.map(({ path }) => path)]); for (const path of paths) { - const originalRoute = originalMap.get(path); - const addedRoute = addedMap.get(path); - - let route: RouteObject | undefined; - if (originalRoute && addedRoute) { - route = callback(originalRoute, addedRoute, next([originalRoute.children, addedRoute.children])); - } else if (originalRoute) { - route = callback(originalRoute, undefined, next([originalRoute.children, undefined])); - } else { - route = callback(undefined, addedRoute, next([undefined, addedRoute!.children])); + // We can have multiple routes with the same path, so we have to + // consider all of them. + const originalRoutes = original.filter((r) => r.path === path); + // We can have only one route with the same path in the added list. + const addedRoutes = added.filter((r) => r.path === path); + + if (addedRoutes.length > 1) { + throw new Error('Adding multiple routes with the same path is not allowed'); } - if (route) { - originalMap.set(path, route); + const addedRoute = addedRoutes[0] as T | undefined; + + if (originalRoutes.length > 0 && addedRoute) { + // In case we have both original and added routes, we run + // the callback for each original route in pair with the added + // route. To make the difference, we flag all the routes except + // the last one as `dupe`. + // + // Why the last one is not `dupe`? According to the + // `react-router` logic, the last route is the fallback for all + // routes with the same path. So, if we apply callback to it, + // we implicitly apply it to all other routes with the same + // path. + // + // In case this logic doesn't work, the user can apply the + // callback without considering the `dupe` flag. + for (let i = 0; i < originalRoutes.length; i++) { + final.push( + callback({ + original: originalRoutes[i], + overriding: addedRoute, + children: next([originalRoutes[i].children, addedRoute.children]), + dupe: i < originalRoutes.length - 1, + }) ?? originalRoutes[i], + ); + } + } else if (originalRoutes.length > 0) { + // In case we don't have the added route with the path being + // processed, we run the callback for each original route. + for (let i = 0; i < originalRoutes.length; i++) { + final.push( + callback({ + original: originalRoutes[i], + children: next([originalRoutes[i].children, undefined]), + dupe: i < originalRoutes.length - 1, + }) ?? originalRoutes[i], + ); + } + } else { + // In case we don't have the original route with the path being + // processed, we run the callback for only the added route. + const result = callback({ + overriding: addedRoute, + children: next([undefined, addedRoute!.children]), + dupe: false, + }); + + if (result) { + final.push(result); + } } } - return [...originalMap.values()]; + return final.filter((r) => r != null); } else if (original) { + // If we have only original routes, we run the callback for each + // original route. return original - .map((route) => callback(route, undefined, next([route.children, undefined]))) + .map((route) => + callback({ + original: route, + children: next([route.children, undefined]), + dupe: false, + }), + ) .filter((r) => r != null); } else if (added) { + // If we have only added routes, we run the callback for each added + // route. return added - .map((route) => callback(undefined, route, next([undefined, route.children]))) + .map((route) => + callback({ + overriding: route, + children: next([undefined, route.children]), + dupe: false, + }), + ) .filter((r) => r != null); } diff --git a/packages/ts/file-router/src/vite-plugin.ts b/packages/ts/file-router/src/vite-plugin.ts index 2d8bc14e5..a3d7a86b3 100644 --- a/packages/ts/file-router/src/vite-plugin.ts +++ b/packages/ts/file-router/src/vite-plugin.ts @@ -115,7 +115,8 @@ export default function vitePluginFileSystemRouter({ }, transform(code, id): Promise | TransformResult { let modifiedCode = code; - if (id.startsWith(fileURLToPath(_viewsDir)) && !basename(id).startsWith('_')) { + const viewsDirUsingSlashes = fileURLToPath(_viewsDir).replaceAll('\\', '/'); + if (id.startsWith(viewsDirUsingSlashes) && !basename(id).startsWith('_')) { if (isDevMode) { // To enable HMR for route files with exported configurations, we need // to address a limitation in `react-refresh`. This library requires diff --git a/packages/ts/file-router/test/runtime/RouterConfigurationBuilder.spec.tsx b/packages/ts/file-router/test/runtime/RouterConfigurationBuilder.spec.tsx index 08898a864..8caba49ad 100644 --- a/packages/ts/file-router/test/runtime/RouterConfigurationBuilder.spec.tsx +++ b/packages/ts/file-router/test/runtime/RouterConfigurationBuilder.spec.tsx @@ -43,6 +43,17 @@ describe('RouterBuilder', () => { }, ]); reset = mockDocumentBaseURI('https://example.com/foo'); + globalThis.window = { + // @ts-expect-error Fake just enough so tests pass + history: { + replaceState: () => {}, + }, + // @ts-expect-error Fake just enough so tests pass + location: '', + addEventListener: () => {}, + }; + // @ts-expect-error Fake just enough so tests pass + globalThis.document.defaultView = globalThis.window; }); afterEach(() => { @@ -168,9 +179,6 @@ describe('RouterBuilder', () => { { path: '/test', element:
Test
, - }, - { - path: '/test', children: [ { path: '/child-test', @@ -830,4 +838,76 @@ describe('RouterBuilder', () => { reset(); }); }); + describe('issues', () => { + it('#2954', () => { + const { routes } = new RouterConfigurationBuilder() + .withFileRoutes([ + { + path: '', + children: [ + { + path: '', + module: { + config: { + menu: { order: 0 }, + title: 'Public view', + }, + default: NextTest, + }, + }, + { + path: 'login', + module: { + config: { + menu: { exclude: true }, + flowLayout: false, + }, + }, + }, + ], + }, + ]) + .withFallback(Server) + .protect() + .build(); + + expect(routes).to.be.like([ + { + path: '', + children: [ + { + path: 'login', + handle: { + menu: { + exclude: true, + }, + flowLayout: false, + title: 'undefined', + }, + }, + ], + handle: { + title: 'undefined', + }, + }, + { + path: '', + children: [ + { + element: , + handle: { + menu: { order: 0 }, + title: 'Public view', + }, + index: true, + }, + { path: '*', element: }, + ], + handle: { title: 'undefined' }, + }, + { path: '*', element: }, + { index: true, element: }, + ]); + }); + }); }); diff --git a/packages/ts/frontend/package.json b/packages/ts/frontend/package.json index 0ae139c8e..c080b2286 100644 --- a/packages/ts/frontend/package.json +++ b/packages/ts/frontend/package.json @@ -1,6 +1,6 @@ { "name": "@vaadin/hilla-frontend", - "version": "24.6.0-beta5", + "version": "24.6.0-beta6", "description": "Hilla core frontend utils", "main": "index.js", "module": "index.js", diff --git a/packages/ts/generator-cli/package.json b/packages/ts/generator-cli/package.json index 94ada077b..137b8d304 100644 --- a/packages/ts/generator-cli/package.json +++ b/packages/ts/generator-cli/package.json @@ -1,6 +1,6 @@ { "name": "@vaadin/hilla-generator-cli", - "version": "24.6.0-beta5", + "version": "24.6.0-beta6", "description": "A Hilla tool to generate TypeScript code from the OpenAPI document", "main": "index.js", "type": "module", @@ -45,8 +45,8 @@ "tsgen": "bin/index.js" }, "dependencies": { - "@vaadin/hilla-generator-core": "24.6.0-beta5", - "@vaadin/hilla-generator-utils": "24.6.0-beta5", + "@vaadin/hilla-generator-core": "24.6.0-beta6", + "@vaadin/hilla-generator-utils": "24.6.0-beta6", "get-stdin": "^9.0.0", "meow": "^12.1.1" }, @@ -57,7 +57,7 @@ "@types/node": "^20.7.1", "@types/sinon": "^10.0.17", "@types/sinon-chai": "^3.2.10", - "@vaadin/hilla-generator-core": "24.6.0-beta5", + "@vaadin/hilla-generator-core": "24.6.0-beta6", "c8": "^10.1.2", "chai": "^4.3.10", "chai-as-promised": "^7.1.1", diff --git a/packages/ts/generator-core/package.json b/packages/ts/generator-core/package.json index 2c488e4cc..9fbbf7d0a 100644 --- a/packages/ts/generator-core/package.json +++ b/packages/ts/generator-core/package.json @@ -1,6 +1,6 @@ { "name": "@vaadin/hilla-generator-core", - "version": "24.6.0-beta5", + "version": "24.6.0-beta6", "description": "A Hilla tool to generate TypeScript code from the OpenAPI document", "main": "index.js", "type": "module", @@ -72,7 +72,7 @@ }, "dependencies": { "@apidevtools/swagger-parser": "^10.1.0", - "@vaadin/hilla-generator-utils": "24.6.0-beta5", + "@vaadin/hilla-generator-utils": "24.6.0-beta6", "meow": "^12.1.1", "openapi-types": "^12.1.3", "typescript": "5.6.2" diff --git a/packages/ts/generator-plugin-backbone/package.json b/packages/ts/generator-plugin-backbone/package.json index 45112f17a..453f82cf6 100644 --- a/packages/ts/generator-plugin-backbone/package.json +++ b/packages/ts/generator-plugin-backbone/package.json @@ -1,6 +1,6 @@ { "name": "@vaadin/hilla-generator-plugin-backbone", - "version": "24.6.0-beta5", + "version": "24.6.0-beta6", "description": "A Hilla TypeScript Generator plugin to generate basic code", "main": "index.js", "type": "module", @@ -51,9 +51,9 @@ "access": "public" }, "dependencies": { - "@vaadin/hilla-generator-core": "24.6.0-beta5", - "@vaadin/hilla-generator-plugin-client": "24.6.0-beta5", - "@vaadin/hilla-generator-utils": "24.6.0-beta5", + "@vaadin/hilla-generator-core": "24.6.0-beta6", + "@vaadin/hilla-generator-plugin-client": "24.6.0-beta6", + "@vaadin/hilla-generator-utils": "24.6.0-beta6", "fast-deep-equal": "^3.1.3", "openapi-types": "^12.1.3", "typescript": "5.6.2" @@ -64,8 +64,8 @@ "@types/node": "^20.7.1", "@types/sinon": "^10.0.17", "@types/sinon-chai": "^3.2.10", - "@vaadin/hilla-generator-core": "24.6.0-beta5", - "@vaadin/hilla-generator-plugin-client": "24.6.0-beta5", + "@vaadin/hilla-generator-core": "24.6.0-beta6", + "@vaadin/hilla-generator-plugin-client": "24.6.0-beta6", "c8": "^10.1.2", "chai": "^4.3.10", "concurrently": "^8.2.1", diff --git a/packages/ts/generator-plugin-barrel/package.json b/packages/ts/generator-plugin-barrel/package.json index 61e6f0f58..a72e2db9f 100644 --- a/packages/ts/generator-plugin-barrel/package.json +++ b/packages/ts/generator-plugin-barrel/package.json @@ -1,6 +1,6 @@ { "name": "@vaadin/hilla-generator-plugin-barrel", - "version": "24.6.0-beta5", + "version": "24.6.0-beta6", "description": "A Hilla TypeScript Generator plugin to generate barrel file", "main": "index.js", "type": "module", @@ -51,9 +51,9 @@ "access": "public" }, "dependencies": { - "@vaadin/hilla-generator-core": "24.6.0-beta5", - "@vaadin/hilla-generator-plugin-backbone": "24.6.0-beta5", - "@vaadin/hilla-generator-utils": "24.6.0-beta5", + "@vaadin/hilla-generator-core": "24.6.0-beta6", + "@vaadin/hilla-generator-plugin-backbone": "24.6.0-beta6", + "@vaadin/hilla-generator-utils": "24.6.0-beta6", "typescript": "5.6.2" }, "devDependencies": { @@ -62,8 +62,8 @@ "@types/node": "^20.7.1", "@types/sinon": "^10.0.17", "@types/sinon-chai": "^3.2.10", - "@vaadin/hilla-generator-core": "24.6.0-beta5", - "@vaadin/hilla-generator-plugin-backbone": "24.6.0-beta5", + "@vaadin/hilla-generator-core": "24.6.0-beta6", + "@vaadin/hilla-generator-plugin-backbone": "24.6.0-beta6", "c8": "^10.1.2", "chai": "^4.3.10", "concurrently": "^8.2.1", diff --git a/packages/ts/generator-plugin-client/package.json b/packages/ts/generator-plugin-client/package.json index 7892213a1..4a8a41baf 100644 --- a/packages/ts/generator-plugin-client/package.json +++ b/packages/ts/generator-plugin-client/package.json @@ -1,6 +1,6 @@ { "name": "@vaadin/hilla-generator-plugin-client", - "version": "24.6.0-beta5", + "version": "24.6.0-beta6", "description": "A Hilla TypeScript Generator plugin to generate default client implementation", "main": "index.js", "type": "module", @@ -51,8 +51,8 @@ "access": "public" }, "dependencies": { - "@vaadin/hilla-generator-core": "24.6.0-beta5", - "@vaadin/hilla-generator-utils": "24.6.0-beta5", + "@vaadin/hilla-generator-core": "24.6.0-beta6", + "@vaadin/hilla-generator-utils": "24.6.0-beta6", "typescript": "5.6.2" }, "devDependencies": { @@ -61,7 +61,7 @@ "@types/node": "^20.7.1", "@types/sinon": "^10.0.17", "@types/sinon-chai": "^3.2.10", - "@vaadin/hilla-generator-core": "24.6.0-beta5", + "@vaadin/hilla-generator-core": "24.6.0-beta6", "c8": "^10.1.2", "chai": "^4.3.10", "concurrently": "^8.2.1", diff --git a/packages/ts/generator-plugin-model/package.json b/packages/ts/generator-plugin-model/package.json index 5320c647b..ff0e4ceb5 100644 --- a/packages/ts/generator-plugin-model/package.json +++ b/packages/ts/generator-plugin-model/package.json @@ -1,6 +1,6 @@ { "name": "@vaadin/hilla-generator-plugin-model", - "version": "24.6.0-beta5", + "version": "24.6.0-beta6", "description": "A Hilla TypeScript Generator plugin to generate form models", "main": "index.js", "type": "module", @@ -51,10 +51,10 @@ "access": "public" }, "dependencies": { - "@vaadin/hilla-generator-core": "24.6.0-beta5", - "@vaadin/hilla-generator-plugin-backbone": "24.6.0-beta5", - "@vaadin/hilla-generator-utils": "24.6.0-beta5", - "@vaadin/hilla-lit-form": "24.6.0-beta5", + "@vaadin/hilla-generator-core": "24.6.0-beta6", + "@vaadin/hilla-generator-plugin-backbone": "24.6.0-beta6", + "@vaadin/hilla-generator-utils": "24.6.0-beta6", + "@vaadin/hilla-lit-form": "24.6.0-beta6", "fast-deep-equal": "^3.1.3", "openapi-types": "^12.1.3", "typescript": "5.6.2" @@ -65,8 +65,8 @@ "@types/node": "^20.7.1", "@types/sinon": "^10.0.17", "@types/sinon-chai": "^3.2.10", - "@vaadin/hilla-generator-core": "24.6.0-beta5", - "@vaadin/hilla-generator-plugin-client": "24.6.0-beta5", + "@vaadin/hilla-generator-core": "24.6.0-beta6", + "@vaadin/hilla-generator-plugin-client": "24.6.0-beta6", "c8": "^10.1.2", "chai": "^4.3.10", "concurrently": "^8.2.1", diff --git a/packages/ts/generator-plugin-push/package.json b/packages/ts/generator-plugin-push/package.json index b6b4242bb..4e3845a5a 100644 --- a/packages/ts/generator-plugin-push/package.json +++ b/packages/ts/generator-plugin-push/package.json @@ -1,6 +1,6 @@ { "name": "@vaadin/hilla-generator-plugin-push", - "version": "24.6.0-beta5", + "version": "24.6.0-beta6", "description": "A Hilla TypeScript Generator plugin to add push support", "main": "index.js", "type": "module", @@ -51,9 +51,9 @@ "access": "public" }, "dependencies": { - "@vaadin/hilla-generator-core": "24.6.0-beta5", - "@vaadin/hilla-generator-plugin-client": "24.6.0-beta5", - "@vaadin/hilla-generator-utils": "24.6.0-beta5", + "@vaadin/hilla-generator-core": "24.6.0-beta6", + "@vaadin/hilla-generator-plugin-client": "24.6.0-beta6", + "@vaadin/hilla-generator-utils": "24.6.0-beta6", "fast-deep-equal": "^3.1.3", "openapi-types": "^12.1.3", "typescript": "5.6.2" @@ -64,8 +64,8 @@ "@types/node": "^20.7.1", "@types/sinon": "^10.0.17", "@types/sinon-chai": "^3.2.10", - "@vaadin/hilla-generator-core": "24.6.0-beta5", - "@vaadin/hilla-generator-plugin-client": "24.6.0-beta5", + "@vaadin/hilla-generator-core": "24.6.0-beta6", + "@vaadin/hilla-generator-plugin-client": "24.6.0-beta6", "c8": "^10.1.2", "chai": "^4.3.10", "concurrently": "^8.2.1", diff --git a/packages/ts/generator-plugin-signals/package.json b/packages/ts/generator-plugin-signals/package.json index f54c64646..aeadca6c5 100644 --- a/packages/ts/generator-plugin-signals/package.json +++ b/packages/ts/generator-plugin-signals/package.json @@ -1,6 +1,6 @@ { "name": "@vaadin/hilla-generator-plugin-signals", - "version": "24.6.0-beta5", + "version": "24.6.0-beta6", "description": "A Hilla TypeScript Generator plugin to add Shared Signals support", "main": "index.js", "type": "module", @@ -51,10 +51,10 @@ "access": "public" }, "dependencies": { - "@vaadin/hilla-generator-core": "24.6.0-beta5", - "@vaadin/hilla-generator-plugin-backbone": "24.6.0-beta5", - "@vaadin/hilla-generator-plugin-client": "24.6.0-beta5", - "@vaadin/hilla-generator-utils": "24.6.0-beta5", + "@vaadin/hilla-generator-core": "24.6.0-beta6", + "@vaadin/hilla-generator-plugin-backbone": "24.6.0-beta6", + "@vaadin/hilla-generator-plugin-client": "24.6.0-beta6", + "@vaadin/hilla-generator-utils": "24.6.0-beta6", "fast-deep-equal": "^3.1.3", "iterator-helpers-polyfill": "^3.0.1", "openapi-types": "^12.1.3", @@ -66,8 +66,8 @@ "@types/node": "^20.7.1", "@types/sinon": "^10.0.17", "@types/sinon-chai": "^3.2.10", - "@vaadin/hilla-generator-core": "24.6.0-beta5", - "@vaadin/hilla-generator-plugin-client": "24.6.0-beta5", + "@vaadin/hilla-generator-core": "24.6.0-beta6", + "@vaadin/hilla-generator-plugin-client": "24.6.0-beta6", "c8": "^8.0.1", "chai": "^4.3.10", "concurrently": "^8.2.1", diff --git a/packages/ts/generator-plugin-subtypes/package.json b/packages/ts/generator-plugin-subtypes/package.json index 27b194dd7..a770f6d94 100644 --- a/packages/ts/generator-plugin-subtypes/package.json +++ b/packages/ts/generator-plugin-subtypes/package.json @@ -1,6 +1,6 @@ { "name": "@vaadin/hilla-generator-plugin-subtypes", - "version": "24.6.0-beta5", + "version": "24.6.0-beta6", "description": "A Hilla TypeScript Generator plugin to support JsonSubTypes", "main": "index.js", "type": "module", @@ -50,10 +50,10 @@ "access": "public" }, "dependencies": { - "@vaadin/hilla-generator-core": "24.6.0-beta5", - "@vaadin/hilla-generator-plugin-client": "24.6.0-beta5", - "@vaadin/hilla-generator-plugin-model": "24.6.0-beta5", - "@vaadin/hilla-generator-utils": "24.6.0-beta5", + "@vaadin/hilla-generator-core": "24.6.0-beta6", + "@vaadin/hilla-generator-plugin-client": "24.6.0-beta6", + "@vaadin/hilla-generator-plugin-model": "24.6.0-beta6", + "@vaadin/hilla-generator-utils": "24.6.0-beta6", "fast-deep-equal": "^3.1.3", "openapi-types": "^12.1.3", "typescript": "5.6.2" @@ -64,9 +64,9 @@ "@types/node": "^20.7.1", "@types/sinon": "^10.0.17", "@types/sinon-chai": "^3.2.10", - "@vaadin/hilla-generator-core": "24.6.0-beta5", - "@vaadin/hilla-generator-plugin-client": "24.6.0-beta5", - "@vaadin/hilla-generator-plugin-model": "24.6.0-beta5", + "@vaadin/hilla-generator-core": "24.6.0-beta6", + "@vaadin/hilla-generator-plugin-client": "24.6.0-beta6", + "@vaadin/hilla-generator-plugin-model": "24.6.0-beta6", "c8": "^10.1.2", "chai": "^4.3.10", "concurrently": "^8.2.1", diff --git a/packages/ts/generator-utils/package.json b/packages/ts/generator-utils/package.json index e1d8e6a20..107f675bd 100644 --- a/packages/ts/generator-utils/package.json +++ b/packages/ts/generator-utils/package.json @@ -1,6 +1,6 @@ { "name": "@vaadin/hilla-generator-utils", - "version": "24.6.0-beta5", + "version": "24.6.0-beta6", "description": "A set of utils for developing Hilla generator plugins", "main": "index.js", "type": "module", diff --git a/packages/ts/lit-form/package.json b/packages/ts/lit-form/package.json index f80328bf5..e43425579 100644 --- a/packages/ts/lit-form/package.json +++ b/packages/ts/lit-form/package.json @@ -1,6 +1,6 @@ { "name": "@vaadin/hilla-lit-form", - "version": "24.6.0-beta5", + "version": "24.6.0-beta6", "description": "Hilla form utils", "main": "index.js", "module": "index.js", @@ -71,7 +71,7 @@ "access": "public" }, "dependencies": { - "@vaadin/hilla-frontend": "24.6.0-beta5", + "@vaadin/hilla-frontend": "24.6.0-beta6", "validator": "^13.11.0" }, "peerDependencies": { diff --git a/packages/ts/models/package.json b/packages/ts/models/package.json index 9a62044e3..c6b0f1a56 100644 --- a/packages/ts/models/package.json +++ b/packages/ts/models/package.json @@ -1,6 +1,6 @@ { "name": "@vaadin/hilla-models", - "version": "24.6.0-beta5", + "version": "24.6.0-beta6", "description": "Generative form models for Hilla", "main": "index.js", "module": "index.js", @@ -46,7 +46,7 @@ "access": "public" }, "dependencies": { - "@vaadin/hilla-lit-form": "24.6.0-beta5" + "@vaadin/hilla-lit-form": "24.6.0-beta6" }, "peerDependencies": { "react": "^18" diff --git a/packages/ts/react-auth/package.json b/packages/ts/react-auth/package.json index 5ef753e35..ccbd69c14 100644 --- a/packages/ts/react-auth/package.json +++ b/packages/ts/react-auth/package.json @@ -1,6 +1,6 @@ { "name": "@vaadin/hilla-react-auth", - "version": "24.6.0-beta5", + "version": "24.6.0-beta6", "description": "Hilla auth utils for React", "main": "index.js", "module": "index.js", @@ -46,7 +46,7 @@ "access": "public" }, "dependencies": { - "@vaadin/hilla-frontend": "24.6.0-beta5" + "@vaadin/hilla-frontend": "24.6.0-beta6" }, "peerDependencies": { "react": "^18", diff --git a/packages/ts/react-crud/package.json b/packages/ts/react-crud/package.json index fdd7381ca..1970cdd33 100644 --- a/packages/ts/react-crud/package.json +++ b/packages/ts/react-crud/package.json @@ -1,6 +1,6 @@ { "name": "@vaadin/hilla-react-crud", - "version": "24.6.0-beta5", + "version": "24.6.0-beta6", "description": "Hilla CRUD utils for React", "main": "index.js", "module": "index.js", @@ -56,9 +56,9 @@ "access": "public" }, "dependencies": { - "@vaadin/hilla-frontend": "24.6.0-beta5", - "@vaadin/hilla-lit-form": "24.6.0-beta5", - "@vaadin/hilla-react-form": "24.6.0-beta5", + "@vaadin/hilla-frontend": "24.6.0-beta6", + "@vaadin/hilla-lit-form": "24.6.0-beta6", + "@vaadin/hilla-react-form": "24.6.0-beta6", "@vaadin/react-components": "24.6.0-rc1" }, "peerDependencies": { diff --git a/packages/ts/react-form/package.json b/packages/ts/react-form/package.json index 2f82ca255..1fe946e24 100644 --- a/packages/ts/react-form/package.json +++ b/packages/ts/react-form/package.json @@ -1,6 +1,6 @@ { "name": "@vaadin/hilla-react-form", - "version": "24.6.0-beta5", + "version": "24.6.0-beta6", "description": "Hilla form utils for React", "main": "index.js", "module": "index.js", @@ -46,7 +46,7 @@ "access": "public" }, "dependencies": { - "@vaadin/hilla-lit-form": "24.6.0-beta5" + "@vaadin/hilla-lit-form": "24.6.0-beta6" }, "peerDependencies": { "react": "^18" diff --git a/packages/ts/react-i18n/package.json b/packages/ts/react-i18n/package.json index 00372aad7..dc1b4434f 100644 --- a/packages/ts/react-i18n/package.json +++ b/packages/ts/react-i18n/package.json @@ -1,6 +1,6 @@ { "name": "@vaadin/hilla-react-i18n", - "version": "24.6.0-beta5", + "version": "24.6.0-beta6", "description": "Hilla I18n utils for React", "main": "index.js", "module": "index.js", @@ -46,8 +46,8 @@ "access": "public" }, "dependencies": { - "@vaadin/hilla-frontend": "24.6.0-beta5", - "@vaadin/hilla-react-signals": "24.6.0-beta5", + "@vaadin/hilla-frontend": "24.6.0-beta6", + "@vaadin/hilla-react-signals": "24.6.0-beta6", "intl-messageformat": "^10.5.11" }, "peerDependencies": { diff --git a/packages/ts/react-signals/package.json b/packages/ts/react-signals/package.json index 59bbee8f0..6a2dceae9 100644 --- a/packages/ts/react-signals/package.json +++ b/packages/ts/react-signals/package.json @@ -1,6 +1,6 @@ { "name": "@vaadin/hilla-react-signals", - "version": "24.6.0-beta5", + "version": "24.6.0-beta6", "description": "Signals for Hilla React", "main": "index.js", "module": "index.js", @@ -47,7 +47,7 @@ }, "dependencies": { "@preact/signals-react": "^2.0.0", - "@vaadin/hilla-frontend": "24.6.0-beta5", + "@vaadin/hilla-frontend": "24.6.0-beta6", "nanoid": "^5.0.7" }, "peerDependencies": {