Skip to content

Clean up JS-WASM interop: move terminal APIs to xtermConsole.ts#189

Merged
LittleLittleCloud merged 7 commits intomainfrom
copilot/clean-up-js-wasm-interop
Nov 25, 2025
Merged

Clean up JS-WASM interop: move terminal APIs to xtermConsole.ts#189
LittleLittleCloud merged 7 commits intomainfrom
copilot/clean-up-js-wasm-interop

Conversation

Copy link
Contributor

Copilot AI commented Nov 25, 2025

  • Create new xtermConsole.ts file in website/src/lib/ with all terminal-related APIs (renamed from terminalInterop.ts)
  • Move registerComponent and handleKeyboardEvent from main.js to xtermConsole.ts
  • Update main.js to only export createRuntimeAndGetExports
  • Refactor main.js to create dotnet instance only once using getDotnetInstance() helper
  • Remove unused componentRenderer.ts
  • Update XTermPreview.tsx to import all APIs from @/lib/xtermConsole
  • Update main.d.ts to reflect the reduced API surface
  • Fix WASM module import - use static import from razor-console package instead of dynamic import to avoid runtime fetch issues
  • Use exported WasmExports interface from main.d.ts instead of local type definition
  • Verify .NET build and tests pass
Original prompt

This section details on the original issue you should resolve

<issue_title>Clean up JS-WASM interop</issue_title>
<issue_description>Currently all the interop lives in main.js and xterm-interop.js under RanzorConsole.Website. Refactoring it to move all apis from main.js and xterm-interop.js to website/src/lib under xtermConsole.ts and only keeps the dotnet-relavent API in original main.js</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI self-assigned this Nov 25, 2025
Copilot AI and others added 2 commits November 25, 2025 05:55
…SM interop

Co-authored-by: LittleLittleCloud <16876986+LittleLittleCloud@users.noreply.github.com>
Co-authored-by: LittleLittleCloud <16876986+LittleLittleCloud@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor JS-WASM interop by moving APIs to xtermConsole.ts Clean up JS-WASM interop: move terminal APIs to xtermConsole.ts Nov 25, 2025
@github-actions
Copy link

github-actions bot commented Nov 25, 2025

🚀 Preview Deployment

A preview build has been generated for this PR from CI run #19662571470!

Download the artifact:
website-preview-189

To view the preview locally:

  1. Download the artifact from the CI workflow run
  2. Extract the ZIP file
  3. Serve the files with a local web server
    (e.g., npx serve dist)

🌐 Live Preview URL: https://bba7c35e.razorconsole.pages.dev

The live preview will be automatically updated when you push new
commits to this PR.

Copy link
Member

@LittleLittleCloud LittleLittleCloud left a comment

Choose a reason for hiding this comment

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

@copilot fix comments

…move unused componentRenderer.ts

Co-authored-by: LittleLittleCloud <16876986+LittleLittleCloud@users.noreply.github.com>
@LittleLittleCloud LittleLittleCloud marked this pull request as ready for review November 25, 2025 07:25
Copilot AI review requested due to automatic review settings November 25, 2025 07:25
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors the JS-WASM interop layer to establish clearer separation of concerns between terminal manipulation APIs and .NET runtime initialization. Previously, main.js re-exported all terminal functions from xterm-interop.js, creating tight coupling between the WASM runtime and terminal management.

Key Changes

  • Consolidated terminal APIs: All xterm.js operations (init, write, clear, dispose, attachKeyListener) plus WASM interop functions (registerComponent, handleKeyboardEvent) are now centralized in xtermConsole.ts and exposed via window.razorConsoleTerminal
  • Simplified main.js: Reduced to a single export (createRuntimeAndGetExports) that returns WASM assembly exports, with all other APIs delegating to window.razorConsoleTerminal
  • Removed unused files: Deleted xterm-interop.js (functionality moved) and componentRenderer.ts (unused)

Reviewed changes

Copilot reviewed 5 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
website/src/services/componentRenderer.ts Removed unused Blazor component preview renderer service
website/src/lib/xtermConsole.ts Added registerTerminalInstance, getTerminalInstance, WASM interop functions (registerComponent, handleKeyboardEvent), and dynamic import of main.js for WASM exports
website/src/components/XTermPreview.tsx Updated imports from "razor-console" to "@/lib/xtermConsole" to use refactored API
website/package-lock.json Removed unused WASM-related dependencies: vite-plugin-wasm, vite-plugin-top-level-await, @swc/core, @rollup/plugin-virtual, and uuid
src/RazorConsole.Website/wwwroot/xterm-interop.js Deleted - all terminal API functionality migrated to xtermConsole.ts
src/RazorConsole.Website/wwwroot/main.js Refactored to export only createRuntimeAndGetExports; terminal APIs now accessed via window.razorConsoleTerminal
src/RazorConsole.Website/wwwroot/main.d.ts Updated type definitions to reflect new API surface: single createRuntimeAndGetExports export returning WasmExports interface
Files not reviewed (1)
  • website/package-lock.json: Language not supported

Co-authored-by: LittleLittleCloud <16876986+LittleLittleCloud@users.noreply.github.com>
@LittleLittleCloud
Copy link
Member

@copilot get this error in preview deploy

Error: Failed to load WASM module from /wasm/wwwroot/main.js: Failed to fetch dynamically imported module: https://5d965bf9.razorconsole.pages.dev/wasm/wwwroot/main.js

Co-authored-by: LittleLittleCloud <16876986+LittleLittleCloud@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Nov 25, 2025

@copilot get this error in preview deploy

Error: Failed to load WASM module from /wasm/wwwroot/main.js: Failed to fetch dynamically imported module: https://5d965bf9.razorconsole.pages.dev/wasm/ww...

Fixed the WASM module loading issue. The problem was using a dynamic import from /wasm/wwwroot/main.js which doesn't exist at runtime on the deployed site. Changed to use a static import from the razor-console package which is properly bundled by Vite at build time. (5f31f92)

…tion

Co-authored-by: LittleLittleCloud <16876986+LittleLittleCloud@users.noreply.github.com>
@LittleLittleCloud LittleLittleCloud merged commit b2e7243 into main Nov 25, 2025
12 checks passed
@LittleLittleCloud LittleLittleCloud deleted the copilot/clean-up-js-wasm-interop branch November 25, 2025 16:41
@github-actions github-actions bot added this to the v0.2.0 milestone Nov 25, 2025
LittleLittleCloud added a commit that referenced this pull request Nov 25, 2025
LittleLittleCloud added a commit that referenced this pull request Nov 25, 2025
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.

Clean up JS-WASM interop

4 participants