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

Tips for rpc perf #490

Merged
merged 6 commits into from
Sep 17, 2024
Merged

Tips for rpc perf #490

merged 6 commits into from
Sep 17, 2024

Conversation

m-shaka
Copy link
Contributor

@m-shaka m-shaka commented Sep 14, 2024

Added tips to improve IDE performance when using RPC


However, we have some tips to mitigate this issue.

#### compile your app before using it (recommended)
Copy link
Member

@yusukebe yusukebe Sep 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you write the specific instructions for using d.ts?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated!

@yusukebe
Copy link
Member

Hey @m-shaka

Good descriptions! These are needed. I've left a comment. Check it.

@yusukebe
Copy link
Member

I'm not sure this will help you, but I've created the repo to use d.ts: https://github.com/yusukebe/hono-rpc-with-d-ts

@m-shaka
Copy link
Contributor Author

m-shaka commented Sep 16, 2024

Great!
I was thinking of separating the server project and the client one using a monorepo tool as I'm doing in my job, but your working example looks perfect as a single repo.
I'll add a description about monorepo and the link to your repository to the doc.

@yusukebe
Copy link
Member

yusukebe commented Sep 16, 2024

@m-shaka

Hey. This is another approach in which @nakasyou tried similar things.

https://github.com/yusukebe/hono-rpc-with-d-ts/tree/client-types

In this branch, client/client.ts uses the actual client types emitted from client-types/client.ts. This may be the fastest for the client. This is interesting.

@yusukebe
Copy link
Member

Oooops. Please ignore the CI is failing.

@m-shaka
Copy link
Contributor Author

m-shaka commented Sep 16, 2024

Oh, I see.
Or rather it's better to export a client from the server, right?

// server/client.ts
import routes from './server'
import { hc } from 'hono/client'

type Routes = typeof routes
export const getClient: typeof hc<Routes> = (...args) => hc<Routes>(...args)

// client/client.ts
import { getClient } from '../dist/client'
const client = getClient('http://localhost:3000')

const res = await client.index.$get()
const data = await res.json()
console.log(data)

@m-shaka
Copy link
Contributor Author

m-shaka commented Sep 16, 2024

Some tricks are needed to calculate types on compiling.

// server/client.ts
import routes from './server'
import { hc } from 'hono/client'

type Routes = typeof routes

const client = hc<Routes>('http://localhost:3000')

export type Client = typeof client

export const getClient = (...args: Parameters<typeof hc<Routes>>): Client =>
    hc<Routes>(...args)

@yusukebe
Copy link
Member

@m-shaka

Ah, cool! It's nitpicky, but how about renaming getClient to hcWithType?

@yusukebe
Copy link
Member

@nakasyou any thoughts on it?

@nakasyou
Copy link
Contributor

It looks cool! And I like hcWithType better than getClient.

@m-shaka
Copy link
Contributor Author

m-shaka commented Sep 16, 2024

Thank you, both of you! I revised the doc

@yusukebe
Copy link
Member

Hi @m-shaka

I've updated the format of the docs and added a super short description for the server. Let's go with it. Thanks!

@yusukebe yusukebe merged commit 9c96457 into honojs:main Sep 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants