Skip to content

Conversation

avivkeller
Copy link
Member

@avivkeller avivkeller commented Sep 1, 2025

Fixes #7932


Introduces @shikijs/twoslash support in @node-core/rehype-shiki. Since twoslash depends on TypeScript declaration files, it cannot be bundled and must instead be listed under serverExternalPackages.

Because TypeScript declarations aren’t imported like regular files (they’re loaded through a TSVFS), they need to be explicitly included in the output bundle.

Because Cloudflare doesn't support WASM or Top-Level awaits, rehype-shiki has been rewritten to not rely on them.

@avivkeller avivkeller self-assigned this Sep 1, 2025
Copy link

vercel bot commented Sep 1, 2025

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

Project Deployment Preview Updated (UTC)
nodejs-org Ready Ready Preview Sep 30, 2025 8:18pm

Copy link

codecov bot commented Sep 1, 2025

Codecov Report

❌ Patch coverage is 45.85987% with 85 lines in your changes missing coverage. Please review.
✅ Project coverage is 76.42%. Comparing base (5140729) to head (d7f4d57).
⚠️ Report is 5 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
packages/rehype-shiki/src/index.mjs 11.25% 71 Missing ⚠️
packages/rehype-shiki/src/plugin.mjs 76.74% 10 Missing ⚠️
packages/rehype-shiki/src/highlighter.mjs 85.71% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8132      +/-   ##
==========================================
- Coverage   76.58%   76.42%   -0.17%     
==========================================
  Files         115      115              
  Lines        9602     9629      +27     
  Branches      322      316       -6     
==========================================
+ Hits         7354     7359       +5     
- Misses       2247     2269      +22     
  Partials        1        1              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@AugustinMauroy
Copy link
Member

Hype 😁 !

@avivkeller
Copy link
Member Author

Locally:
image

Copy link
Contributor

@Copilot 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 adds TypeScript TwoSlash support to the syntax highlighting system, enabling interactive TypeScript error displays and type information tooltips in code blocks.

Key Changes:

  • Integrated TwoSlash transformer for TypeScript/JavaScript code highlighting
  • Refactored metadata parsing system from string-based to object-based approach
  • Added CSS styling for TwoSlash popup containers and error displays

Reviewed Changes

Copilot reviewed 10 out of 11 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
packages/rehype-shiki/src/index.mjs Added TwoSlash transformer import and configuration
packages/rehype-shiki/src/highlighter.mjs Updated functions to accept metadata parameter and pass transformers
packages/rehype-shiki/src/plugin.mjs Replaced string-based metadata parsing with comprehensive object-based system
packages/rehype-shiki/src/twoslash.css Added CSS styling for TwoSlash popup containers
packages/rehype-shiki/package.json Added TwoSlash dependency and exported CSS file
packages/ui-components/src/Common/BaseCodeBox/index.module.css Added CSS transforms for proper positioning
apps/site/next.config.mjs Configured external packages and file tracing for TwoSlash
apps/site/package.json Added twoslash dependency
apps/site/styles/index.css Imported TwoSlash CSS styles
apps/site/pages/en/learn/typescript/transpile.md Updated TypeScript example to use TwoSlash error annotations
Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@jakebailey
Copy link
Member

Is this all server side?

I'm asking because given the TS port to Go, I'm not sure what the deal will be for shiki on the web; probably having to include a large Go binary in Wasm to work with all of the fancy stuff if not prerendered...

@avivkeller
Copy link
Member Author

avivkeller commented Sep 6, 2025

Lastly, we also need to look at how this impacts page performance.

When checking the output HTML file sizes for our home page, I see:

Nodejs.org: 175.73 KB

Preview: 228.79 KB

It might be good to run a comparison with @next/bundle-analyzer to see how much load this adds to the pages 🤔

It's not supposed to be passed to the client at all, so we should definitely investigate that

@avivkeller avivkeller marked this pull request as draft September 6, 2025 21:01
@avivkeller
Copy link
Member Author

The popover that’s supposed to display the types on horizontally scrollable sections doesn’t open in the correct position

Copy to clipboard also copies the types into the clipboard

Fixed in the latest commit, which introduced some styling issues (regarding wrapping).

@avivkeller
Copy link
Member Author

On the line where the error messages are displayed, the scrolled section looks cut off. Additionally, the text and background color used here don’t seem to have sufficient contrast ratio

Is that even possible to fix? iiuc CSS doesn't allow us to set this element to width + overflow?

@avivkeller
Copy link
Member Author

avivkeller commented Sep 8, 2025

The size increase comes from the additional HTML needed for these tooltips

@avivkeller
Copy link
Member Author

avivkeller commented Sep 8, 2025

I don't like that it's all chunked on the main page, this would be better as an imported script, but that would need to be changed as part of our Markdown to JSX

@dario-piotrowicz
Copy link
Member

@dario-piotrowicz Does this setup not support OpenNext? If not, we can make it conditional, like we do for the WASM engine

Sorry @avivkeller, I only now saw your message 🙇

Tomorrow I'll have a closer look 🙇 , however by quickly skimming though your changes I didn't spot anything that could be problematic, on the contrary, it seems like you are conditionally using the wasm implementation only if Cloudflare is not in global 🤔

Do you have any suspicion on what might be causing the Cloudflare incompatibility? 🙂

@dario-piotrowicz
Copy link
Member

@avivkeller I'm looking into the issue, for now what I've seen is that this problematic WebAssembly.instantiate call is being made by shiki:
https://github.com/shikijs/shiki/blob/e46261819005a7519c64b54679a504d783dfdcbc/packages/engine-oniguruma/src/wasm-inlined.ts#L8

but I thought that in our setup shiki would not use wasm? 🤔

@avivkeller
Copy link
Member Author

Our Shiki setup doesn't use WASM when "Cloudflare" in global, can you point me to how you know this is the cause of the issue, so I can investigate why it's occurring?

@dario-piotrowicz
Copy link
Member

Our Shiki setup doesn't use WASM when "Cloudflare" in global

Yes, that's exactly what I saw/thought, but definitely shiki seems to be trying to instantiate wasm anyways here 😕

(Also via the debugger I can indeed see that Cloudflare is in global when the error is thrown 😕)

can you point me to how you know this is the cause of the issue, so I can investigate why it's occurring?

In the site directory you can build the worker via: pnpm cloudflare:build:worker then you spin it up with pnpm cloudflare:preview when you do that, before doing anything press d that will open your chrome devtools, there make sure to have ticked the pause on caught exceptions checkbox and then simply visit the site, then in the devtools keep resuming the script until it hits the wasm issue:
Screenshot 2025-09-11 at 13 47 30

Minification

To make the code a bit more decipherable I've disable minification in the next config:
Screenshot 2025-09-11 at 13 52 49

@avivkeller
Copy link
Member Author

FYI @dario-piotrowicz, still not working

@avivkeller
Copy link
Member Author

Bump @dario-piotrowicz

@avivkeller
Copy link
Member Author

@nodejs/nodejs-website @nodejs/web-infra for reviews. Currently, this is disabled on CF, but there's a TODO to enable it.

Copy link
Member

@AugustinMauroy AugustinMauroy left a comment

Choose a reason for hiding this comment

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

Light/dark theme didn't work well but I didn't see why
Capture d’écran 2025-09-25 à 08 53 20
Capture d’écran 2025-09-25 à 08 53 35


These type definitions allow TypeScript to understand Node.js APIs and provide proper type checking and autocompletion when you use functions like `fs.readFile` or `http.createServer`. For example:

```js
Copy link
Member

Choose a reason for hiding this comment

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

This is supper weird. I see the idea of showing auto completion.
But it's strange

When I was looking at this, I was expecting an interactive thing.

Copy link
Member Author

Choose a reason for hiding this comment

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

How so? I can change it if it's not good

Copy link
Member

Choose a reason for hiding this comment

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

  1. (big) solution having "editor" that user can use to learn such as a complet learning platform. IMO not good idea.
  2. just don't use this feature

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it makes sense, as we are discussing auto-complete, cc @nodejs/nodejs-website @nodejs/typescript for opinions

@avivkeller
Copy link
Member Author

I'll get to Augustin's review today, @nodejs/web any other comments / concerns

Copy link
Member

@flakey5 flakey5 left a comment

Choose a reason for hiding this comment

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

thank you!

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.

Type Info on the Docs & Guides
6 participants