Conversation
WalkthroughReplaces README.md template with documentation for the react-vscode-webview-ipc library, detailing IPC paradigms, usage, and examples. Updates package.json formatting for typesVersions entries and adds jsdom as a devDependency. No source code or public API changes. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Suggested labels
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 inconclusive)
✅ Passed checks (2 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 @hbmartin, 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 introduces comprehensive documentation for a new library, react-vscode-webview-ipc, designed to streamline and type-safely manage communication between VS Code extension hosts and their React-based webviews. It details two primary communication patterns—a unidirectional dataflow (UDF) reducer IPC and a Remote Procedure Call (RPC) promises IPC—providing clear examples and usage guidelines for both. The changes also include the necessary dependency updates to support the library's functionality, notably the addition of jsdom for development purposes.
Highlights
- New Library Documentation: The
README.mdhas been completely rewritten to introduce and documentreact-vscode-webview-ipc, a library designed for type-safe, two-way communication between VS Code extension hosts and React webviews. - Dual IPC Paradigms Supported: The library offers two distinct communication patterns: UDF Reducer IPC for unidirectional state updates via actions and patches, and RPC Promises IPC for calling host functions with typed results and broadcasting events to webviews.
- Dependency Updates: New development dependencies, including
jsdomand various web parsing/styling libraries, have been added to support the functionality and testing of thereact-vscode-webview-ipclibrary.
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. ↩
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
|||||||||||
There was a problem hiding this comment.
Important
Looks good to me! 👍
Reviewed everything up to ac9e21a in 1 minute and 41 seconds. Click for details.
- Reviewed
498lines of code in2files - Skipped
1files when reviewing. - Skipped posting
2draft comments. View those below. - Modify your settings and rules to customize what types of comments Ellipsis leaves. And don't forget to react with 👍 or 👎 to teach Ellipsis.
1. README.md:118
- Draft comment:
Consider providing a helper to brand view keys rather than using the repetitive 'as unknown as WebviewKey' cast. This could improve type safety and code clarity. - Reason this comment was not posted:
Decided after close inspection that this draft comment was likely wrong and/or not actionable: usefulness confidence = 20% vs. threshold = 50% While the suggestion could improve code clarity, it's more of an optional enhancement than a required change. The current approach is already documented in the Tips section and works fine. The comment is suggesting a nice-to-have refactor rather than pointing out a real problem that needs fixing. The suggestion could improve type safety and reduce repetition. However, I might be underestimating the maintenance burden of the current approach. The current approach is already documented, working, and simple enough. The benefit of adding a helper function doesn't outweigh the overhead of maintaining another API surface. While the suggestion is reasonable, it's not important enough to warrant a comment. The current approach is documented and functional.
2. package.json:87
- Draft comment:
The addition of the 'jsdom' dependency should be confirmed as necessary for tests to avoid potential version conflicts. - Reason this comment was not posted:
Comment did not seem useful. Confidence is useful =0%<= threshold50%The comment is asking the PR author to confirm the necessity of a dependency addition, which violates the rule against asking for confirmation or ensuring behavior is intended. It also touches on potential version conflicts, which is related to dependencies, another area we should not comment on.
Workflow ID: wflow_UHMVCBcYWqcffyAo
You can customize by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.
There was a problem hiding this comment.
Code Review
This pull request is a fantastic improvement, replacing the boilerplate README with comprehensive documentation for the library. The new README is well-structured, with clear explanations of the core concepts, detailed examples for both UDF and RPC patterns, and helpful sequence diagrams. I've added a few minor suggestions to further improve clarity and code style in the examples. Overall, great work on making the library much more approachable for new users.
| ]) | ||
| # react-vscode-webview-ipc | ||
|
|
||
| A small library to make two-way communication between a VS Code extension host and a React webview simple and type‑safe. |
There was a problem hiding this comment.
The documentation uses a non-breaking hyphen (‑) in "type‑safe". This might have been unintentional. Using a standard hyphen (-) is recommended for consistency and to avoid potential issues with text processing, searching, or copy-pasting. This character is also used in "long‑running" on line 379.
| A small library to make two-way communication between a VS Code extension host and a React webview simple and type‑safe. | |
| A small library to make two-way communication between a VS Code extension host and a React webview simple and type-safe. |
| // provider.api.triggerEvent('onTick', currentCount) | ||
| ``` |
There was a problem hiding this comment.
This example snippet is inside a code block and is also commented out, which might be confusing. Consider moving this example outside the main code block and presenting it as a separate, standalone snippet for clarity. For example:
...
}
```
Elsewhere in your extension, you can broadcast events:
```ts
// Assuming `provider` is an instance of MyRpcViewProvider
provider.api.triggerEvent('onTick', currentCount);
```There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (5)
package.json (1)
38-40: Mark package as side‑effect free for better tree‑shakingIf builds are pure ESM/CJS outputs without global side effects, declare sideEffects: false.
Apply:
"files": [ "dist" ], + "sideEffects": false,README.md (4)
16-18: Add a language to fenced code block (MD040)Specify bash to appease markdownlint and enable syntax highlighting.
Apply:
-``` +```bash npm i react-vscode-webview-ipc--- `92-96`: **Avoid style-src 'unsafe-inline' where possible** For stricter CSP, prefer a nonce or hashed styles over 'unsafe-inline' (keep external CSS). Note: VS Code webviews support nonces. Example: ```diff - content="default-src 'none'; img-src ${webview.cspSource} https:; style-src ${webview.cspSource} 'unsafe-inline'; script-src ${webview.cspSource};" + content="default-src 'none'; img-src ${webview.cspSource} https:; style-src ${webview.cspSource}; script-src 'nonce-${nonce}';"and add nonce to your script tag and injected styles.
117-124: Branded WebviewKey ergonomicsDouble cast
as unknown as WebviewKeyis noisy. Consider exporting a helper (e.g., asWebviewKey('my.view')) to brand safely, or document a recommended pattern.
303-309: Remove unnecessary cast in listener registrationType the callback as MyHostEvents['onTick'] to avoid
asat call sites.Apply:
- useEffect(() => { - const onTick = (n: number) => console.log('tick', n); - addListener('onTick', onTick as MyHostEvents['onTick']); - return () => removeListener('onTick', onTick as MyHostEvents['onTick']); - }, [addListener, removeListener]); + useEffect(() => { + const onTick: MyHostEvents['onTick'] = (n) => console.log('tick', n); + addListener('onTick', onTick); + return () => removeListener('onTick', onTick); + }, [addListener, removeListener]);
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
package-lock.jsonis excluded by!**/package-lock.json
📒 Files selected for processing (2)
README.md(1 hunks)package.json(2 hunks)
🧰 Additional context used
🪛 markdownlint-cli2 (0.17.2)
README.md
16-16: Fenced code blocks should have a language specified
(MD040, fenced-code-language)
🔇 Additional comments (3)
package.json (2)
18-23: typesVersions formatting LGTMReformat to arrays is fine and preserves resolution for subpaths host/client.
87-87: Confirm jsdom + Vitest env configNo vitest.config.* found and vite.config.ts has no test.environment — Vitest will not pick up jsdom just from package.json; add
test: { environment: 'jsdom' }to vite.config.ts (or create vitest.config.ts / add avitestconfig in package.json), or annotate DOM tests with@vitest-environment jsdom.README.md (1)
351-358: Nice clarity on coexistence rulesGood separation of message channels; consumers will appreciate the non-interference guarantees.
If feasible, add a small “both paradigms” example repo link later.
| declare function acquireVsCodeApi(): { | ||
| postMessage(message: unknown): Thenable<boolean>; | ||
| getState(): unknown; | ||
| setState(state: unknown): void; | ||
| }; | ||
|
|
There was a problem hiding this comment.
🧩 Analysis chain
Verify acquireVsCodeApi().postMessage return type
Docs snippet types postMessage as Thenable. In the webview context it may be void; host-side webview.postMessage is Thenable. Confirm to prevent copy/paste type drift.
🌐 Web query:
In a VS Code webview (window context), what is the return type of acquireVsCodeApi().postMessage(message)? Is it void or Thenable<boolean>?
💡 Result:
acquireVsCodeApi().postMessage(...) (webview/window side) returns void. (npmjs.com)
Notes: the VS Code extension-side Webview.postMessage(...) (webview object in extension API) returns Thenable, which is a different API. (cocalc.com)
Citations:
- 1: https://www.npmjs.com/package/%40types/vscode-webview?utm_source=openai
- 2: https://cocalc.com/github/microsoft/vscode/blob/main/src/vscode-dts/vscode.d.ts?utm_source=openai
Change acquireVsCodeApi().postMessage return type to void
acquireVsCodeApi().postMessage in the webview/window context returns void (the extension-side Webview.postMessage returns Thenable). Update README.md (lines 132–137) to:
declare function acquireVsCodeApi(): {
postMessage(message: unknown): void;
getState(): unknown;
setState(state: unknown): void;
};
🤖 Prompt for AI Agents
In README.md around lines 132 to 137, the TypeScript declaration for
acquireVsCodeApi incorrectly types postMessage as returning Thenable<boolean>;
update the declaration so postMessage returns void instead. Edit the block to
change the postMessage return type from Thenable<boolean> to void, leaving
getState and setState as-is, so the README matches the webview/window context
behavior.
PR Type
Documentation
Description
Complete rewrite of README with comprehensive library documentation
Added detailed examples for UDF reducer IPC pattern
Added detailed examples for RPC promises IPC pattern
Added installation instructions and API reference
Diagram Walkthrough
File Walkthrough
README.md
Complete library documentation rewriteREADME.md
documentation
package.json
Minor dependency and formatting updatespackage.json
jsdomas development dependencytypesVersionsarrays for better readabilityImportant
Update
README.mdwith detailed documentation forreact-vscode-webview-ipcand addjsdomtopackage.json.README.mdto documentreact-vscode-webview-ipclibrary.jsdomas a development dependency inpackage.json.This description was created by
for ac9e21a. You can customize this summary. It will automatically update as commits are pushed.
Summary by CodeRabbit