
Product
Introducing Tier 1 Reachability: Precision CVE Triage for Enterprise Teams
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.
react-native-shiki-engine
Advanced tools
Shiki syntax highlighting for React Native. Zero bridge overhead with native Oniguruma regex engine.
Oniguruma regex engine implementation for React Native, providing high-performance syntax highlighting capabilities through Shiki. This module implements a JSI-based native bridge to Oniguruma, enabling efficient pattern matching and syntax highlighting in React Native applications.
[!IMPORTANT] React Native Shiki Engine requires the New Architecture to be enabled (react-native 0.71+)
yarn add react-native-shiki-engine
cd ios && pod install
npx expo install react-native-shiki-engine
npx expo prebuild
import { createHighlighterCore } from '@shikijs/core'
import { createNativeEngine, isNativeEngineAvailable } from 'react-native-shiki-engine'
import javascript from '@shikijs/langs/dist/javascript.mjs'
import nord from '@shikijs/themes/dist/nord.mjs'
if (!isNativeEngineAvailable()) {
throw new Error('Native engine is not available')
}
const highlighter = createHighlighterCore({
themes: ['nord'],
langs: ['javascript'],
engine: createNativeEngine(),
})
[!IMPORTANT]
Performance Note: The Highlighter Instance
Create and maintain a single Highlighter instance at the app level. Avoid instantiating new highlighters inside components or frequently called functions.
Recommended:
- Store the highlighter instance in a global singleton or context
- Initialize it during app startup
- Reuse the same instance across your entire React Native application
Not Recommended:
- Creating new instances inside component render methods
- Initializing highlighters inside useEffect or event handlers
- Multiple instances for the same language/theme combination
See the example directory for a reference implementation using React Context to maintain a single highlighter instance.
The native engine supports configuration options to optimize performance:
createNativeEngine({
// Maximum number of patterns to cache
maxCacheSize: 1000,
})
For web applications, this native engine is not compatible as it relies on React Native's TurboModules and JSI. To support web platforms, you can use Shiki's default WASM or JavaScript engine instead.
import { createHighlighterCore } from '@shikijs/core'
import { createOnigurumaEngine } from '@shikijs/engine-oniguruma'
import { createNativeEngine, isNativeEngineAvailable } from 'react-native-shiki-engine'
function createAdaptiveEngine() {
// Use native engine for native platforms
if (isNativeEngineAvailable()) {
return createNativeEngine()
}
// Fallback to Shiki's WASM engine for web platforms
return createOnigurumaEngine(import('shiki/wasm'))
}
const highlighter = createHighlighterCore({
themes: ['nord'],
langs: ['javascript'],
engine: createAdaptiveEngine(),
})
This approach ensures:
The module uses a three-layer architecture optimizing for both performance and developer experience:
JavaScript Layer (src/
)
JSI Bridge (cpp/
)
Oniguruma Core (vendored)
The engine implements a sophisticated multi-level caching system:
L1 Cache: Hot patterns in JSI host objects
L2 Cache: Compiled patterns in native memory
Memory Management
Platform | Architecture | Description | Status |
---|---|---|---|
iOS Simulator | x86_64 | Intel-based simulators | ✅ |
iOS Simulator | arm64 | Apple Silicon simulators | ✅ |
iOS Device | arm64 | All modern iOS devices | ✅ |
Android | arm64-v8a | Modern Android devices (64-bit ARM) | ✅ |
Android | armeabi-v7a | Older Android devices (32-bit ARM) | ✅ |
Android | x86 | Android emulators (32-bit Intel/AMD) | ✅ |
Android | x86_64 | Android emulators (64-bit Intel/AMD) | ✅ |
Contributions are welcome! Please read our Contributing Guide for details on:
MIT License - see the LICENSE file for details
For questions, bug reports, or feature requests:
FAQs
Shiki syntax highlighting for React Native. Zero bridge overhead with native Oniguruma regex engine.
We found that react-native-shiki-engine demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.
Research
/Security News
Ongoing npm supply chain attack spreads to DuckDB: multiple packages compromised with the same wallet-drainer malware.
Security News
The MCP Steering Committee has launched the official MCP Registry in preview, a central hub for discovering and publishing MCP servers.