From 3d8619f5d65caec9a457485461958e3f16f81d04 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 26 Jan 2026 10:27:40 +0000 Subject: [PATCH 1/2] Initial plan From 91fbb84dfd556e74bd7c137f5c215fb4b336d0d8 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 26 Jan 2026 10:30:57 +0000 Subject: [PATCH 2/2] Fix router base handling, bq-if directive, and CHANGELOG issues MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Fix router base handling: Keep routes base-relative, only add base to browser history - Fix flattenRoutes to not include base in route paths - Fix bq-if directive to use replaceWith() to handle moved elements - Fix CHANGELOG typos: "dangrous" → "dangerous", "brodken" → "broken" - Fix CHANGELOG heading format to use brackets [x.y.z] consistently - Update test to reflect correct base path behavior Co-authored-by: JosunLP <20913954+JosunLP@users.noreply.github.com> --- CHANGELOG.md | 28 ++++++++++++++-------------- src/router/router.ts | 4 ++-- src/router/utils.ts | 5 +++-- src/view/directives/if.ts | 9 ++++----- tests/router.test.ts | 5 +++-- 5 files changed, 26 insertions(+), 25 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bfad5b38..7f1b0774 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,20 +14,20 @@ and this project adheres to Semantic Versioning. - [Fixed (1.3.0)](#fixed-130) - [[1.2.0] - 2026-01-24](#120---2026-01-24) - [Added (1.2.0)](#added-120) - - [(1.1.2) - 2026-01-24](#112---2026-01-24) + - [[1.1.2] - 2026-01-24](#112---2026-01-24) - [Fixed (1.1.2)](#fixed-112) - [Security (1.1.2)](#security-112) - - [(1.1.1) - 2026-01-24](#111---2026-01-24) + - [[1.1.1] - 2026-01-24](#111---2026-01-24) - [Fixed (1.1.1)](#fixed-111) - - [(1.1.0) - 2026-01-23](#110---2026-01-23) + - [[1.1.0] - 2026-01-23](#110---2026-01-23) - [Added (1.1.0)](#added-110) - [Changed (1.1.0)](#changed-110) - [Security (1.1.0)](#security-110) - - [(1.0.2) - 2026-01-23](#102---2026-01-23) + - [[1.0.2] - 2026-01-23](#102---2026-01-23) - [Fixed (1.0.2)](#fixed-102) - - [(1.0.1) - 2026-01-23](#101---2026-01-23) + - [[1.0.1] - 2026-01-23](#101---2026-01-23) - [Fixed (1.0.1)](#fixed-101) - - [(1.0.0) - 2026-01-21](#100---2026-01-21) + - [[1.0.0] - 2026-01-21](#100---2026-01-21) - [Added (1.0.0)](#added-100) ## [1.3.0] - 2026-01-26 @@ -98,7 +98,7 @@ and this project adheres to Semantic Versioning. - Custom directive prefix support. - Automatic HTML sanitization for security. -## (1.1.2) - 2026-01-24 +## [1.1.2] - 2026-01-24 ### Fixed (1.1.2) @@ -108,13 +108,13 @@ and this project adheres to Semantic Versioning. - Added `rel="noopener noreferrer"` to external links for improved security. -## (1.1.1) - 2026-01-24 +## [1.1.1] - 2026-01-24 ### Fixed (1.1.1) -- Fixed a possibly dangrous html handling in the playground examples. +- Fixed a possibly dangerous html handling in the playground examples. -## (1.1.0) - 2026-01-23 +## [1.1.0] - 2026-01-23 ### Added (1.1.0) @@ -152,13 +152,13 @@ and this project adheres to Semantic Versioning. - Added protection against DOM clobbering attacks by preventing reserved IDs like `document`, `cookie`, `location`. - Improved URL sanitization to prevent Unicode bypass attacks using zero-width characters. -## (1.0.2) - 2026-01-23 +## [1.0.2] - 2026-01-23 ### Fixed (1.0.2) -- Fixed brodken documentation links in README.md. +- Fixed broken documentation links in README.md. -## (1.0.1) - 2026-01-23 +## [1.0.1] - 2026-01-23 ### Fixed (1.0.1) @@ -167,7 +167,7 @@ and this project adheres to Semantic Versioning. - Revised the homepage URL in `package.json` to point to the official bQuery website. - Added publish configuration in `package.json` to ensure public accessibility on npm registry. -## (1.0.0) - 2026-01-21 +## [1.0.0] - 2026-01-21 ### Added (1.0.0) diff --git a/src/router/router.ts b/src/router/router.ts index ee7ee4de..11db2955 100644 --- a/src/router/router.ts +++ b/src/router/router.ts @@ -52,8 +52,8 @@ export const createRouter = (options: RouterOptions): Router => { const beforeGuards: NavigationGuard[] = []; const afterHooks: Array<(to: Route, from: Route) => void> = []; - // Flatten nested routes - const flatRoutes = flattenRoutes(routes, base); + // Flatten nested routes (base-relative, not including the base path) + const flatRoutes = flattenRoutes(routes); /** * Gets the current path from the URL. diff --git a/src/router/utils.ts b/src/router/utils.ts index 01d893e6..e717fd76 100644 --- a/src/router/utils.ts +++ b/src/router/utils.ts @@ -13,13 +13,14 @@ import type { RouteDefinition } from './types'; /** * Flattens nested routes into a single array with full paths. + * Does NOT include the router base - base is only for browser history. * @internal */ -export const flattenRoutes = (routes: RouteDefinition[], base = ''): RouteDefinition[] => { +export const flattenRoutes = (routes: RouteDefinition[], parentPath = ''): RouteDefinition[] => { const result: RouteDefinition[] = []; for (const route of routes) { - const fullPath = route.path === '*' ? '*' : `${base}${route.path}`.replace(/\/+/g, '/'); + const fullPath = route.path === '*' ? '*' : `${parentPath}${route.path}`.replace(/\/+/g, '/'); result.push({ ...route, diff --git a/src/view/directives/if.ts b/src/view/directives/if.ts index c60c9c49..57839ce4 100644 --- a/src/view/directives/if.ts +++ b/src/view/directives/if.ts @@ -7,7 +7,6 @@ import type { DirectiveHandler } from '../types'; * @internal */ export const handleIf: DirectiveHandler = (el, expression, context, cleanups) => { - const parent = el.parentNode; const placeholder = document.createComment(`bq-if: ${expression}`); // Store original element state @@ -17,12 +16,12 @@ export const handleIf: DirectiveHandler = (el, expression, context, cleanups) => const condition = evaluate(expression, context); if (condition && !isInserted) { - // Insert element - parent?.replaceChild(el, placeholder); + // Insert element using replaceWith to handle moved elements + placeholder.replaceWith(el); isInserted = true; } else if (!condition && isInserted) { - // Remove element - parent?.replaceChild(placeholder, el); + // Remove element using replaceWith to handle moved elements + el.replaceWith(placeholder); isInserted = false; } }); diff --git a/tests/router.test.ts b/tests/router.test.ts index 1d093085..0ac3e263 100644 --- a/tests/router.test.ts +++ b/tests/router.test.ts @@ -1263,7 +1263,7 @@ describe('Router', () => { expect(stack[stack.length - 1].url).toBe('/app/page'); }); - it('should flatten nested routes with base path', () => { + it('should flatten nested routes without including base path', () => { router = createRouter({ routes: [ { @@ -1276,7 +1276,8 @@ describe('Router', () => { }); expect(router.routes).toHaveLength(2); - expect(router.routes[1].path).toBe('/app/parent/child'); + // Routes should not include base - base is only for browser history + expect(router.routes[1].path).toBe('/parent/child'); }); });