Skip to content

Conversation

@SHUBHI-KUMARI
Copy link

@SHUBHI-KUMARI SHUBHI-KUMARI commented Dec 2, 2025

Fix: metaHighlightWord fails with twoslash

Description

Fixes an issue where metaHighlightWord (and other decorations) would throw "Invalid decoration offset" errors when used in conjunction with twoslash.

Changes

packages/core

  • Moved builtInTransformers (which includes transformerDecorations) to run before other transformers in getTransformers.
    • Reason: transformerTwoslash modifies the HAST structure (e.g., adding error lines, popups). If transformerDecorations runs after transformerTwoslash, it attempts to apply decorations based on the original code offsets to a modified HAST, causing mismatches. Running decorations first ensures they are applied to the correct structure.

packages/twoslash

  • Explicitly cleared decorations in the recursive codeToHast call within rendererRich.
    • Reason: When rendering popups, rendererRich calls codeToHast for the popup content. It was inheriting decorations from the parent context. Since the popup content is different from the main code, applying these decorations caused invalid offset errors.

Reproduction

import { codeToHtml } from 'shiki'
import { transformerTwoslash } from '@shikijs/twoslash'
import { transformerMetaWordHighlight } from '@shikijs/transformers'

const code = 'const a = 1'
const html = await codeToHtml(code, {
  lang: 'javascript',
  theme: 'vitesse-dark',
  transformers: [
    transformerMetaWordHighlight(),
    transformerTwoslash({ explicitTrigger: true })
  ],
  meta: {
    __raw: '/codeToHtml/ twoslash'
  }
})

Checklist

  • Tests passed
  • Linting passed

closes: #990

@netlify
Copy link

netlify bot commented Dec 2, 2025

Deploy Preview for shiki-matsu ready!

Name Link
🔨 Latest commit e66ab0f
🔍 Latest deploy log https://app.netlify.com/projects/shiki-matsu/deploys/6931c5e62768ee0008640579
😎 Deploy Preview https://deploy-preview-1174--shiki-matsu.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify
Copy link

netlify bot commented Dec 2, 2025

Deploy Preview for shiki-next ready!

Name Link
🔨 Latest commit e66ab0f
🔍 Latest deploy log https://app.netlify.com/projects/shiki-next/deploys/6931c5e634eefc0008b42812
😎 Deploy Preview https://deploy-preview-1174--shiki-next.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@codecov
Copy link

codecov bot commented Dec 2, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.20%. Comparing base (28dd090) to head (e66ab0f).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1174   +/-   ##
=======================================
  Coverage   95.20%   95.20%           
=======================================
  Files          92       92           
  Lines        7922     7923    +1     
  Branches     1689     1689           
=======================================
+ Hits         7542     7543    +1     
  Misses        374      374           
  Partials        6        6           

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@antfu antfu changed the title Fix: metaHighlightWord fails with twoslash fix: reorder builtin decoration transformers Dec 3, 2025
@SHUBHI-KUMARI SHUBHI-KUMARI marked this pull request as draft December 4, 2025 17:30
@SHUBHI-KUMARI SHUBHI-KUMARI marked this pull request as ready for review December 4, 2025 17:30
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.

metaHighlightWord does not work properly within the twoslash code block

1 participant