From 95829f04b2d25138eb85682bd41d05276a560777 Mon Sep 17 00:00:00 2001 From: Nils Pukropp Date: Thu, 14 May 2026 17:34:53 +0200 Subject: [PATCH] fixed some build warnings + dynamic imports --- frontend/astro.config.mjs | 5 ++- .../src/components/react/admin/Editor.tsx | 33 +++++++++++++------ frontend/src/lib/markdown.ts | 2 +- 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/frontend/astro.config.mjs b/frontend/astro.config.mjs index c96e206..7e0436a 100644 --- a/frontend/astro.config.mjs +++ b/frontend/astro.config.mjs @@ -21,7 +21,10 @@ export default defineConfig({ service: { entrypoint: 'astro/assets/services/noop' } }, vite: { - plugins: [tailwindcss()] + plugins: [tailwindcss()], + build: { + chunkSizeWarningLimit: 600, + }, }, adapter: node({ diff --git a/frontend/src/components/react/admin/Editor.tsx b/frontend/src/components/react/admin/Editor.tsx index eedf21e..83b04e1 100644 --- a/frontend/src/components/react/admin/Editor.tsx +++ b/frontend/src/components/react/admin/Editor.tsx @@ -1,16 +1,15 @@ -import { useState, useEffect, useRef, useCallback } from 'react'; +import { useState, useEffect, useRef, useCallback, lazy, Suspense } from 'react'; import { EditorView, keymap, placeholder as cmPlaceholder } from '@codemirror/view'; import { EditorState, Compartment } from '@codemirror/state'; import { markdown, markdownLanguage } from '@codemirror/lang-markdown'; import { languages } from '@codemirror/language-data'; import { defaultKeymap, indentWithTab } from '@codemirror/commands'; -import { vim } from '@replit/codemirror-vim'; import { search, searchKeymap } from '@codemirror/search'; import { closeBrackets } from '@codemirror/autocomplete'; -import { renderMarkdown } from '../../../lib/markdown'; import { getPost, savePost, deletePost, getAssets, uploadAsset, ApiError } from '../../../lib/api'; import type { Asset } from '../../../lib/types'; -import AssetManager from './AssetManager'; + +const AssetManager = lazy(() => import('./AssetManager')); interface Props { editSlug?: string; @@ -80,6 +79,7 @@ export default function Editor({ editSlug }: Props) { const previewTimerRef = useRef | null>(null); const updatePreviewRef = useRef<() => void>(() => {}); const uploadFnRef = useRef<(files: File[], insertAt?: number) => void>(() => {}); + const renderMarkdownRef = useRef<((src: string) => string) | null>(null); const today = new Date().toISOString().slice(0, 10); const [title, setTitle] = useState(''); const [slug, setSlug] = useState(editSlug || ''); @@ -107,10 +107,14 @@ export default function Editor({ editSlug }: Props) { setTimeout(() => setAlert(null), 5000); } - const updatePreview = useCallback(() => { + const updatePreview = useCallback(async () => { if (!showPreview || !viewRef.current || !previewRef.current) return; + if (!renderMarkdownRef.current) { + const mod = await import('../../../lib/markdown'); + renderMarkdownRef.current = mod.renderMarkdown; + } const content = viewRef.current.state.doc.toString(); - previewRef.current.innerHTML = renderMarkdown(content); + previewRef.current.innerHTML = renderMarkdownRef.current(content); }, [showPreview]); useEffect(() => { updatePreviewRef.current = updatePreview; }, [updatePreview]); @@ -197,12 +201,19 @@ export default function Editor({ editSlug }: Props) { return () => { view.destroy(); viewRef.current = null; }; }, []); - // Hot-swap vim mode via compartment reconfiguration + // Hot-swap vim mode via compartment reconfiguration; lazy-load vim module useEffect(() => { if (!viewRef.current) return; - viewRef.current.dispatch({ - effects: vimCompartment.reconfigure(vimEnabled ? vim() : []), + if (!vimEnabled) { + viewRef.current.dispatch({ effects: vimCompartment.reconfigure([]) }); + return; + } + let cancelled = false; + import('@replit/codemirror-vim').then(({ vim }) => { + if (cancelled || !viewRef.current) return; + viewRef.current.dispatch({ effects: vimCompartment.reconfigure(vim()) }); }); + return () => { cancelled = true; }; }, [vimEnabled]); // Load existing post for editing @@ -641,7 +652,9 @@ export default function Editor({ editSlug }: Props) {
- + Loading assets…
}> + + diff --git a/frontend/src/lib/markdown.ts b/frontend/src/lib/markdown.ts index 0f6a2d4..4e1d18e 100644 --- a/frontend/src/lib/markdown.ts +++ b/frontend/src/lib/markdown.ts @@ -2,7 +2,7 @@ import { Marked } from 'marked'; import markedKatex from 'marked-katex-extension'; import { markedHighlight } from 'marked-highlight'; import { gfmHeadingId } from 'marked-gfm-heading-id'; -import hljs from 'highlight.js'; +import hljs from 'highlight.js/lib/common'; import DOMPurify from 'isomorphic-dompurify'; function escapeHtml(s: string): string {