It tries to load all `*.tmLanguage.json` unexpectedly
See original GitHub issuehttps://user-images.githubusercontent.com/8336744/132042144-9d816b2a-5354-4609-8621-b065e4bfe2b6.mp4
My source code:
import { Skeleton } from 'antd'
import type { FC } from 'react'
import { setCDN, getHighlighter } from 'shiki'
import './index.less'
import { Rehype } from 'components'
import { usePromise } from 'hooks'
export interface ShikiProps {
theme?: string
lang?: string
children?: string
}
setCDN('/shiki/')
export const Shiki: FC<ShikiProps> = ({
children,
theme = 'dracula',
lang,
}) => {
const [highlighter] = usePromise(() => getHighlighter({ theme }))
return highlighter ? (
<Rehype>{children && highlighter.codeToHtml(children, lang)}</Rehype>
) : (
<Skeleton className="shiki" />
)
}
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (1 by maintainers)
Top Results From Across the Web
vscode/JavaScript.tmLanguage.json at main - GitHub
"This file has been converted from https://github.com/microsoft/TypeScript-TmLanguage/blob/master/TypeScriptReact.tmLanguage",.
Read more >VSCode Unable to load and parse grammar for scope source.ts
Opened the file(TypeScript.tmLanguage.json) and it was empty. Noticed the warnings: Overwriting grammar scope name to file mapping for scope ...
Read more >VS 2019 crashes when editing json file ...
Open a sample Json file without any project in VS to test it. · Please install all of Web workload and try again....
Read more >Vscode language server crashing - Julia Discourse
Hi, for the last month or so, every time my Windows 10 computer gets rebooted the language server will not start when I...
Read more >uwaterloo.cforall-0.1.0 - syntaxes - cfa.tmLanguage.json
{ "include": "#directive.condition.noargs" } · ], · "repository": { · "directive.punctuation": {.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This is a problem with your implementation, not Shiki. You are creating one highlighter per element, and Shiki stores the loaded languages/themes on a highlighter instance rather than in a global cache, which is rather unintuitive, but not necessarily wrong…
Loading grammars up front is also necessary for
codeToHtml
to be synchronous. If you know the language ahead of time, you can pass it togetHighlighter
inlangs
. If you don’t, you could ask Shiki to just load one language (it will load everything if there’s nothing inlangs
), and then add a call tohighlighter.loadLanguage(lang)
withinusePromise
To stop them all from loading it seems you need to pass in the list of languages you need up front.
I’ve also noticed it loads the resources twice (and only twice) regardless.
Three possible opportunities:
Here’s a basic hook for
swr
I’m using which seems to work (I’ll update here if I run into issues later):btw, love shiki so far. If you’d like me to PR any of the above i’d be happy to contribute.