Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. WalkthroughAdds a new "Web Workers" docs page and sidebar entry; updates example comments and the worker-threads example to pass an options object to Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant Main as Main Thread (Client)
participant Worker as Web Worker
participant RPC as RPCHandler / RPCLink
rect rgba(230,245,255,0.5)
note over Worker: Worker startup (server side)
Worker->>RPC: upgrade(self, { context: {} }) %% new options arg
RPC-->>Worker: attach message handler
Worker->>Worker: message.start()
end
rect rgba(240,255,230,0.5)
note over Main: Client initialization
Main->>Worker: instantiate Worker (or Vite worker import)
Main->>RPC: new RPCLink({ port: worker })
RPC-->>Main: link ready
end
rect rgba(255,245,230,0.5)
note over Main,Worker: RPC call flow
Main->>Worker: invoke router method via RPCLink
Worker-->>Main: return result or error
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Summary of Changes
Hello @yzuyr, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request enhances the project's documentation by introducing a comprehensive guide for integrating Web Workers with oRPC, specifically tailored for Vite environments. The new documentation aims to help developers establish type-safe communication between their web applications and Web Workers, leveraging the Message Port Adapter. This addition improves the clarity and completeness of the project's adapter guides.
Highlights
- New Documentation Page: Added a new documentation page for 'Web Workers' under the 'Adapters' section, providing guidance on integrating Vite Web Workers with oRPC for type-safe communication.
- Navigation Update: Updated the VitePress configuration to include the new 'Web Workers' documentation link in the sidebar navigation.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in pull request comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
Code Review
This pull request adds documentation for using oRPC with Vite Web Workers. The changes are good, adding a new page under the adapters section. I've provided a few suggestions on the new documentation file (apps/content/docs/adapters/web-workers.md) to improve the clarity and completeness of the code examples for users. Specifically, I've recommended clarifying a variable in one snippet, removing unused imports in another, and adding an informational block to guide users to more detailed client examples.
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
apps/content/docs/adapters/web-workers.md (2)
10-12: Clarify Comlink note to avoid implying zero‑config interoperabilityCurrent phrasing may overpromise. Suggest rewording to state the constraint (pass the raw Worker/MessagePort, not a wrapped proxy).
-:::info -This guide is specific to Vite, but Comlink Web Workers should also work out of the box. -::: +:::info +This guide targets Vite workers. Libraries like Comlink can also be used as long as you pass the underlying Worker/MessagePort directly to oRPC (do not wrap the port). Verify in your setup. +:::
32-43: Client snippet: unused imports and missing “client” constructionEither remove unused types/functions, or demonstrate the typed client. Recommended:
-import OrpcWorker from './worker?worker' -import { createORPCClient } from '@orpc/client' -import { RPCLink } from '@orpc/client/message-port' -import type { RouterClient } from '@orpc/server' - -const orpcWorker = new OrpcWorker() - -export const link = new RPCLink({ - port: orpcWorker -}) +import OrpcWorker from './worker?worker' +import { createORPCClient } from '@orpc/client' +import { RPCLink } from '@orpc/client/message-port' +import type { RouterClient } from '@orpc/server' +import type { AppRouter } from './router' // export the router type from your worker module + +const orpcWorker = new OrpcWorker() +const link = new RPCLink({ port: orpcWorker }) + +export const client = createORPCClient<RouterClient<AppRouter>>({ + links: [link], +})Note: if your
createORPCClientAPI uses a singlelinkprop instead oflinks, adjust accordingly.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
apps/content/.vitepress/config.ts(1 hunks)apps/content/docs/adapters/web-workers.md(1 hunks)
🔇 Additional comments (1)
apps/content/.vitepress/config.ts (1)
133-134: Add “Web Workers” sidebar entry — LGTMPlacement after “Worker Threads” and the path
/docs/adapters/web-workersmatch the new page.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
More templates
@orpc/arktype
@orpc/client
@orpc/contract
@orpc/experimental-durable-event-iterator
@orpc/hey-api
@orpc/interop
@orpc/json-schema
@orpc/nest
@orpc/openapi
@orpc/openapi-client
@orpc/otel
@orpc/react
@orpc/react-query
@orpc/experimental-react-swr
@orpc/server
@orpc/shared
@orpc/solid-query
@orpc/standard-server
@orpc/standard-server-aws-lambda
@orpc/standard-server-fetch
@orpc/standard-server-node
@orpc/standard-server-peer
@orpc/svelte-query
@orpc/tanstack-query
@orpc/trpc
@orpc/valibot
@orpc/vue-colada
@orpc/vue-query
@orpc/zod
commit: |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (4)
apps/content/docs/adapters/worker-threads.md (3)
26-27: Optional: note that port.start() is not strictly required in Node worker_threads.It’s harmless, but Node’s MessagePort already emits 'message' with listeners; consider a brief note to avoid reader confusion.
41-47: Use resilient Worker path resolution (ESM/CJS).Bare paths can fail depending on cwd. Prefer URL (ESM) or path.resolve (CJS).
Apply this diff for ESM:
-const worker = new Worker('some-worker.js') +const worker = new Worker(new URL('./some-worker.js', import.meta.url), { type: 'module' })Or CJS (example, not a diff in this file):
const { resolve } = require('node:path') const worker = new Worker(resolve(__dirname, 'some-worker.js'))
18-19: Clarify where router comes from.Add a one-liner or link showing router creation to make the snippet copy‑pasteable.
eslint.config.js (1)
85-86: Scope disabling of no-restricted-globals.Turning it off across docs/shared/blog/playgrounds is broad. Narrow it to the specific examples that need
self(Web Workers) to keep guardrails elsewhere.Example adjustments:
@@ rules: { @@ - 'antfu/no-import-node-modules-by-path': 'off', - 'no-restricted-globals': 'off', + 'antfu/no-import-node-modules-by-path': 'off', }, }, { - files: ['apps/content/examples/**'], + files: ['apps/content/examples/**'], rules: { - 'import/first': 'off', + 'import/first': 'off', + 'no-restricted-globals': 'off', }, }, { + files: ['apps/content/docs/adapters/web-workers.md', 'apps/content/docs/adapters/worker-threads.md'], + rules: { + 'no-restricted-globals': 'off', + }, +}, {
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
apps/content/.vitepress/config.ts(1 hunks)apps/content/docs/adapters/message-port.md(1 hunks)apps/content/docs/adapters/web-workers.md(1 hunks)apps/content/docs/adapters/worker-threads.md(1 hunks)eslint.config.js(1 hunks)
✅ Files skipped from review due to trivial changes (1)
- apps/content/docs/adapters/message-port.md
🚧 Files skipped from review as they are similar to previous changes (2)
- apps/content/.vitepress/config.ts
- apps/content/docs/adapters/web-workers.md
Summary by CodeRabbit