From 9443c06be9fc677553c4186a1442a3b1b1f5d14a Mon Sep 17 00:00:00 2001 From: ggoma Date: Wed, 27 Mar 2024 02:41:22 +0900 Subject: [PATCH 1/4] fix: broken devtools with dynamic path --- .changeset/silver-plums-repeat.md | 5 +++++ src/frog-base.tsx | 11 +++++++++++ 2 files changed, 16 insertions(+) create mode 100644 .changeset/silver-plums-repeat.md diff --git a/.changeset/silver-plums-repeat.md b/.changeset/silver-plums-repeat.md new file mode 100644 index 00000000..a72c481c --- /dev/null +++ b/.changeset/silver-plums-repeat.md @@ -0,0 +1,5 @@ +--- +"frog": patch +--- + +Fixed the `/dev` route to be prioritized over dynamic path (`/:dynamic-path`) \ No newline at end of file diff --git a/src/frog-base.tsx b/src/frog-base.tsx index f4ac23a2..d644c337 100644 --- a/src/frog-base.tsx +++ b/src/frog-base.tsx @@ -274,6 +274,17 @@ export class FrogBase< if (dev) this.dev = { enabled: true, ...(dev ?? {}) } this._dev = undefined // this is set `true` by `devtools` helper + + this.hono.all('*', async (c, next) => { + if (this._dev) { + for (const { handler, path } of c.req.matchedRoutes) { + if (path === this._dev) { + return handler(c, next) + } + } + } + await next() + }) } frame: HandlerInterface = ( From 502eb9fb340f862ce03f853ffbd218bfd179fb80 Mon Sep 17 00:00:00 2001 From: undefined Date: Wed, 27 Mar 2024 19:48:17 +0900 Subject: [PATCH 2/4] Update silver-plums-repeat.md --- .changeset/silver-plums-repeat.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/silver-plums-repeat.md b/.changeset/silver-plums-repeat.md index a72c481c..36d6d256 100644 --- a/.changeset/silver-plums-repeat.md +++ b/.changeset/silver-plums-repeat.md @@ -2,4 +2,4 @@ "frog": patch --- -Fixed the `/dev` route to be prioritized over dynamic path (`/:dynamic-path`) \ No newline at end of file +Fixed the `this._dev` route to be prioritized over dynamic path (`/:dynamic-path`) if it exists From 30961cca1d3248274b2218bdad3ee678ac641826 Mon Sep 17 00:00:00 2001 From: Tom Meagher Date: Wed, 27 Mar 2024 16:44:11 -0400 Subject: [PATCH 3/4] chore: up --- playground/src/index.tsx | 20 ++++++++++++++++++++ src/frog-base.tsx | 11 ++++------- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/playground/src/index.tsx b/playground/src/index.tsx index 647e1752..132a861e 100644 --- a/playground/src/index.tsx +++ b/playground/src/index.tsx @@ -221,6 +221,26 @@ export const app = new Frog({ ], }) }) + .frame('/:dynamic', (c) => { + const dynamic = c.req.param('dynamic') + return c.res({ + image: ( +
+ dynamic route {dynamic} should still work with devtools +
+ ), + intents: [], + }) + }) .route('/fonts', fontsApp) .route('/middleware', middlewareApp) .route('/neynar', neynarApp) diff --git a/src/frog-base.tsx b/src/frog-base.tsx index d644c337..92e94b23 100644 --- a/src/frog-base.tsx +++ b/src/frog-base.tsx @@ -275,14 +275,11 @@ export class FrogBase< if (dev) this.dev = { enabled: true, ...(dev ?? {}) } this._dev = undefined // this is set `true` by `devtools` helper + // allow devtools to work with dynamic params off base path this.hono.all('*', async (c, next) => { - if (this._dev) { - for (const { handler, path } of c.req.matchedRoutes) { - if (path === this._dev) { - return handler(c, next) - } - } - } + if (this._dev) + for (const { handler, path } of c.req.matchedRoutes) + if (path === this._dev) return handler(c, next) await next() }) } From c564f295cf07e04bb62786eb883f2d82050e3204 Mon Sep 17 00:00:00 2001 From: awkweb Date: Wed, 27 Mar 2024 16:44:54 -0400 Subject: [PATCH 4/4] Update .changeset/silver-plums-repeat.md --- .changeset/silver-plums-repeat.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/silver-plums-repeat.md b/.changeset/silver-plums-repeat.md index 36d6d256..b25ffc46 100644 --- a/.changeset/silver-plums-repeat.md +++ b/.changeset/silver-plums-repeat.md @@ -2,4 +2,4 @@ "frog": patch --- -Fixed the `this._dev` route to be prioritized over dynamic path (`/:dynamic-path`) if it exists +Prioritized devtools route over dynamic path if it exists.