Skip to content

fix(vscode): use node:crypto randomUUID for webview view IDs#2207

Open
StackOverFlow11 wants to merge 1 commit into
MoonshotAI:mainfrom
StackOverFlow11:fix/vscode-webview-node-crypto
Open

fix(vscode): use node:crypto randomUUID for webview view IDs#2207
StackOverFlow11 wants to merge 1 commit into
MoonshotAI:mainfrom
StackOverFlow11:fix/vscode-webview-node-crypto

Conversation

@StackOverFlow11

Copy link
Copy Markdown

Related Issue

No linked issue — this is a clear, reproducible crash reported by a user; the problem is explained below.

Problem

Extension builds up to 0.5.10 declare "engines": { "vscode": "^1.70.0" }, so the marketplace happily installs them on older VS Code releases (e.g. 1.85.2, whose extension host runs Node 18). KimiWebviewProvider.resolveWebviewView() / createPanel() call the global crypto.randomUUID(), which only exists in extension hosts running Node >= 20. On those clients the call throws before the sidebar renders, and the user just sees:

An error occurred while loading view: kimi.webview

Observed on VS Code 1.85.2 with extension 0.5.10 (window renderer.log):

[error] crypto is not defined: ReferenceError: crypto is not defined
    at vn.resolveWebviewView (.../moonshot-ai.kimi-code-0.5.10-win32-x64/dist/extension.js:25:12091)

main has since raised engines.vscode to ^1.100.0, so new installs are gated — but older VS Code clients are still served the broken 0.5.x builds, and relying on an implicit Web Crypto global in extension-host code stays fragile (it is not part of the node runtime contract the code actually runs against). This may also be worth cherry-picking if a 0.5.x hotfix is ever published.

What changed

apps/vscode/src/KimiWebviewProvider.ts: import randomUUID from node:crypto (available since Node 14.17) instead of the global crypto, matching the existing pattern in apps/vscode/src/runtime/reverse-rpc.ts. Behavior is identical on supported VS Code versions; the code no longer depends on the runtime exposing Web Crypto as a global.

Verified: pnpm typecheck, pnpm exec oxlint src/KimiWebviewProvider.ts (0 errors), and the extension test suite (14 files, 297 tests, all passing).

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue, or explained the problem above.
  • I have added tests that prove my feature works. (No new tests — behavior-preserving fix; ran the existing apps/vscode suite, 297/297 passing.)
  • Ran gen-changesets skill, or this PR needs no changeset. (No changeset — the VS Code extension is versioned and released outside the changesets flow.)
  • Ran gen-docs skill, or this PR needs no doc update. (No user-facing docs change.)

@changeset-bot

changeset-bot Bot commented Jul 26, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: e999a1f

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

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.

1 participant