From c99990bda0cdfcdb1c7bb1dad5b4c65bf7f918f0 Mon Sep 17 00:00:00 2001 From: Bart Ledoux Date: Wed, 29 Jan 2025 21:38:59 +0100 Subject: [PATCH] feat: parse docs is 2 steps to avoid user waiting with nothing --- ui/src/components/docs/ContextDocs.vue | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/ui/src/components/docs/ContextDocs.vue b/ui/src/components/docs/ContextDocs.vue index b8948c549c2..794c39a6f62 100644 --- a/ui/src/components/docs/ContextDocs.vue +++ b/ui/src/components/docs/ContextDocs.vue @@ -90,8 +90,15 @@ if (!("canShare" in navigator)) { content = content.replaceAll(/\s*web-share\s*/g, ""); } - const parse = await getMDCParser() - ast.value = await parse(content); + const parse = await getMDCParser(); + // this hack alleviates a little the parsing load of the first render on big docs + // by only rendering the first 50 lines of the doc on opening + // since they are the only ones visible in the beginning + const firstLinesOfContent = content.split("---\n")[2].split("\n").slice(0, 50).join("\n") + "\nLoading the rest...\n"; + ast.value = await parse(firstLinesOfContent); + setTimeout(async () => { + ast.value = await parse(content); + }, 50); } watch(docPath, async (val) => {