Skip to content
This repository was archived by the owner on Dec 18, 2025. It is now read-only.

Commit 58a75d9

Browse files
committed
fix: preview is now dev-preview.17 compatible
1 parent ed69217 commit 58a75d9

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

src/PreviewCode.tsx

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const PreviewInner = styled(Box)`
2727

2828
export interface PreviewCodeProps {
2929
type?: CodeInputType
30-
value?: CodeInputValue
30+
value?: {selection?: CodeInputValue}
3131
}
3232

3333
export default function PreviewCode(props: PreviewCodeProps) {
@@ -52,14 +52,15 @@ export default function PreviewCode(props: PreviewCodeProps) {
5252
const {value, type} = props
5353
const fixedLanguage = type?.options?.language
5454

55-
const mode = value?.language || fixedLanguage || 'text'
56-
const AceEditor = useAceEditor()
55+
const selection = value?.selection
56+
const mode = selection?.language || fixedLanguage || 'text'
5757

58+
const AceEditor = useAceEditor()
5859
return (
5960
<PreviewContainer>
6061
<PreviewInner padding={4}>
6162
{AceEditor && (
62-
<Suspense fallback={<div>Loading code editor...</div>}>
63+
<Suspense fallback={<div>Loading code preview...</div>}>
6364
<AceEditor
6465
ref={aceEditorRef}
6566
focus={false}
@@ -73,10 +74,10 @@ export default function PreviewCode(props: PreviewCodeProps) {
7374
showPrintMargin={false}
7475
highlightActiveLine={false}
7576
cursorStart={-1}
76-
value={(value && value.code) || ''}
77+
value={selection?.code || ''}
7778
markers={
78-
value && value.highlightedLines
79-
? createHighlightMarkers(value.highlightedLines)
79+
selection?.highlightedLines
80+
? createHighlightMarkers(selection.highlightedLines)
8081
: undefined
8182
}
8283
tabSize={2}

src/ace-editor/AceEditorLazy.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export const AceEditorLazy = React.lazy(() => import('./editorSupport'))
1212
export function useAceEditor() {
1313
const [mounted, setMounted] = useState(false)
1414
useEffect(() => {
15-
setMounted(true)
15+
requestAnimationFrame(() => setMounted(true))
1616
}, [])
1717

1818
return mounted ? AceEditorLazy : null

src/schema.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ export default defineType({
5959
return {
6060
title: value.filename || (value.language || 'unknown').toUpperCase(),
6161
media: getMedia(value?.language),
62+
selection: value,
6263
}
6364
},
6465
},

0 commit comments

Comments
 (0)