Skip to content

docs: web worker adapter#1013

Merged
dinwwwh merged 2 commits intomiddleapi:mainfrom
yzuyr:docs/web-worker
Sep 19, 2025
Merged

docs: web worker adapter#1013
dinwwwh merged 2 commits intomiddleapi:mainfrom
yzuyr:docs/web-worker

Conversation

@yzuyr
Copy link
Copy Markdown
Contributor

@yzuyr yzuyr commented Sep 18, 2025

Summary by CodeRabbit

  • Documentation
    • Added a “Web Workers” docs page with examples for wiring worker (server) and client, including Vite worker usage and Message Port guidance.
    • Updated docs examples to clarify context handling and added a sidebar entry under Adapters for easier navigation.
  • Chores
    • Relaxed lint restrictions for content/examples to reduce noisy linting during documentation/playground edits.

@vercel
Copy link
Copy Markdown

vercel Bot commented Sep 18, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
orpc Ready Ready Preview Comment Sep 19, 2025 3:53am

@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Sep 18, 2025
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Sep 18, 2025

Note

Other AI code review bot(s) detected

CodeRabbit 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.

Walkthrough

Adds a new "Web Workers" docs page and sidebar entry; updates example comments and the worker-threads example to pass an options object to upgrade; relaxes no-restricted-globals ESLint rule in several docs/playground overrides.

Changes

Cohort / File(s) Summary of Changes
Docs Sidebar Config
apps/content/.vitepress/config.ts
Inserted { text: 'Web Workers', link: '/docs/adapters/web-workers' } into the /docs/ sidebar Adapters group (placed adjacent to existing adapter entries).
New Docs Page: Web Workers Adapter
apps/content/docs/adapters/web-workers.md
Added a new documentation page describing the Web Workers adapter with frontmatter, worker and main-thread code examples, Vite-specific worker import example, and links/notes to related docs.
Message Port Docs (comment only)
apps/content/docs/adapters/message-port.md
Minor inline comment change for the context option in the server upgrade example (no runtime/type changes).
Worker Threads Example (API usage change)
apps/content/docs/adapters/worker-threads.md
Updated example to call upgrade(message, { context: {} }) (adds options object containing context). Implies upgrade accepts a second options parameter.
ESLint Overrides
eslint.config.js
Added no-restricted-globals: 'off' to two override blocks (for apps/content/examples/** and a broader set including docs/playgrounds) to suppress the rule in those paths.

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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • unnoq/orpc#785 — Modifies the docs sidebar Adapters group similarly (adds an adapter entry).
  • unnoq/orpc#985 — Edits the docs sidebar configuration; closely related to navigation changes.
  • unnoq/orpc#702 — Also updates apps/content/.vitepress/config.ts and sidebar entries; related to documentation layout edits.

Poem

A rabbit taps the worker’s door,
"Come link your port, I'll send a score." 🐇
Context set, messages start to hum,
Sidebar opens — new docs have come.
Type-safe hops between thread and core.

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title "docs: web worker adapter" is concise and accurately reflects the primary change in the PR—adding documentation for a Web Workers adapter (new docs page and sidebar entry). It uses the conventional "docs:" prefix and is clear enough for a teammate scanning history to understand the main intent of the changeset.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

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

  1. 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.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

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.

Comment thread apps/content/docs/adapters/web-workers.md
Comment thread apps/content/docs/adapters/web-workers.md Outdated
Comment thread apps/content/docs/adapters/web-workers.md
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

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 interoperability

Current 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” construction

Either 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 createORPCClient API uses a single link prop instead of links, adjust accordingly.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fc1ae52 and 75aceef.

📒 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 — LGTM

Placement after “Worker Threads” and the path /docs/adapters/web-workers match the new page.

Comment thread apps/content/docs/adapters/web-workers.md Outdated
@dinwwwh dinwwwh changed the title docs(web worker): add vite web worker docs docs: web worker adapter Sep 19, 2025
@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Sep 19, 2025
@codecov
Copy link
Copy Markdown

codecov Bot commented Sep 19, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Sep 19, 2025

More templates

@orpc/arktype

npm i https://pkg.pr.new/@orpc/arktype@1013

@orpc/client

npm i https://pkg.pr.new/@orpc/client@1013

@orpc/contract

npm i https://pkg.pr.new/@orpc/contract@1013

@orpc/experimental-durable-event-iterator

npm i https://pkg.pr.new/@orpc/experimental-durable-event-iterator@1013

@orpc/hey-api

npm i https://pkg.pr.new/@orpc/hey-api@1013

@orpc/interop

npm i https://pkg.pr.new/@orpc/interop@1013

@orpc/json-schema

npm i https://pkg.pr.new/@orpc/json-schema@1013

@orpc/nest

npm i https://pkg.pr.new/@orpc/nest@1013

@orpc/openapi

npm i https://pkg.pr.new/@orpc/openapi@1013

@orpc/openapi-client

npm i https://pkg.pr.new/@orpc/openapi-client@1013

@orpc/otel

npm i https://pkg.pr.new/@orpc/otel@1013

@orpc/react

npm i https://pkg.pr.new/@orpc/react@1013

@orpc/react-query

npm i https://pkg.pr.new/@orpc/react-query@1013

@orpc/experimental-react-swr

npm i https://pkg.pr.new/@orpc/experimental-react-swr@1013

@orpc/server

npm i https://pkg.pr.new/@orpc/server@1013

@orpc/shared

npm i https://pkg.pr.new/@orpc/shared@1013

@orpc/solid-query

npm i https://pkg.pr.new/@orpc/solid-query@1013

@orpc/standard-server

npm i https://pkg.pr.new/@orpc/standard-server@1013

@orpc/standard-server-aws-lambda

npm i https://pkg.pr.new/@orpc/standard-server-aws-lambda@1013

@orpc/standard-server-fetch

npm i https://pkg.pr.new/@orpc/standard-server-fetch@1013

@orpc/standard-server-node

npm i https://pkg.pr.new/@orpc/standard-server-node@1013

@orpc/standard-server-peer

npm i https://pkg.pr.new/@orpc/standard-server-peer@1013

@orpc/svelte-query

npm i https://pkg.pr.new/@orpc/svelte-query@1013

@orpc/tanstack-query

npm i https://pkg.pr.new/@orpc/tanstack-query@1013

@orpc/trpc

npm i https://pkg.pr.new/@orpc/trpc@1013

@orpc/valibot

npm i https://pkg.pr.new/@orpc/valibot@1013

@orpc/vue-colada

npm i https://pkg.pr.new/@orpc/vue-colada@1013

@orpc/vue-query

npm i https://pkg.pr.new/@orpc/vue-query@1013

@orpc/zod

npm i https://pkg.pr.new/@orpc/zod@1013

commit: e29b104

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between 75aceef and e29b104.

📒 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

Comment thread apps/content/docs/adapters/worker-threads.md
@dinwwwh dinwwwh merged commit 34c9217 into middleapi:main Sep 19, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm This PR has been approved by a maintainer size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants