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: broken devtools with dynamic path #200

Merged
merged 4 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
5 changes: 5 additions & 0 deletions .changeset/silver-plums-repeat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"frog": patch
---

Fixed the `this._dev` route to be prioritized over dynamic path (`/:dynamic-path`) if it exists
tmm marked this conversation as resolved.
Show resolved Hide resolved
20 changes: 20 additions & 0 deletions playground/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,26 @@ export const app = new Frog({
],
})
})
.frame('/:dynamic', (c) => {
const dynamic = c.req.param('dynamic')
return c.res({
image: (
<div
style={{
display: 'flex',
backgroundColor: 'black',
color: 'white',
fontSize: 60,
width: '100%',
height: '100%',
}}
>
dynamic route {dynamic} should still work with devtools
</div>
),
intents: [<Button>rerender</Button>],
})
})
.route('/fonts', fontsApp)
.route('/middleware', middlewareApp)
.route('/neynar', neynarApp)
Expand Down
8 changes: 8 additions & 0 deletions src/frog-base.tsx
tmm marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,14 @@ 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)
await next()
})
}

frame: HandlerInterface<env, 'frame', schema, basePath> = (
Expand Down
Loading