Skip to content

Commit

Permalink
fix: catch shiki magic move error while language or theme are being u…
Browse files Browse the repository at this point in the history
…pdated
  • Loading branch information
cmgriffing committed Nov 26, 2024
1 parent 810aa02 commit 0255b48
Showing 1 changed file with 29 additions and 18 deletions.
47 changes: 29 additions & 18 deletions packages/shiki-magic-move/src/solid/ShikiMagicMove.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,42 @@ export interface ShikiMagicMoveProps {
}

export function ShikiMagicMove(props: ShikiMagicMoveProps) {
const codeToTokens = (code: string, lineNumbers?: boolean) =>
codeToKeyedTokens(
props.highlighter,
code,
{
lang: props.lang,
theme: props.theme,
},
lineNumbers,
)
const codeToTokens = createMemo(() => {
return (code: string, lineNumbers?: boolean) =>
codeToKeyedTokens(
props.highlighter,
code,
{
lang: props.lang,
theme: props.theme,
},
lineNumbers,
)
})

const machine = createMagicMoveMachine((code, lineNumbers) => codeToTokens(code, lineNumbers))
const machine = createMemo(() => {
const newCodeToTokens = codeToTokens()
return createMagicMoveMachine((code, lineNumbers) =>
newCodeToTokens(code, lineNumbers),
)
})

const result = createMemo(() => {
const lineNumbers = props.options?.lineNumbers ?? false
if (
props.code === machine.current.code &&
props.theme === machine.current.themeName &&
props.lang === machine.current.lang &&
lineNumbers === machine.current.lineNumbers
props.code === machine().current.code &&
props.theme === machine().current.themeName &&
props.lang === machine().current.lang &&
lineNumbers === machine().current.lineNumbers
) {
return machine
return machine()
}
try {
return machine().commit(props.code, props.options)
// eslint-disable-next-line unused-imports/no-unused-vars
} catch (e) {
return machine()
}

return machine.commit(props.code, props.options)
})

return (
Expand Down

0 comments on commit 0255b48

Please sign in to comment.