-
Notifications
You must be signed in to change notification settings - Fork 89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(NcRichText): async import remark-gfm library #6259
base: master
Are you sure you want to change the base?
Conversation
Signed-off-by: Maksim Sukharev <[email protected]>
Signed-off-by: Maksim Sukharev <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure this is a good idea with remark-gfm
.
If the connection is slow - it first renders the raw text value, and then it flashes to rendered Markdown.
Unlike code => code with highlights
update, this is a huge visible change. Imagine a message with headings and lists, that is first a plain text and then formatted.
I'm not sure we need a dynamic module here. But if we do it, we should render content ONLY when remark-gfm
is loaded, and render nothing during loading.
setup(props) { | ||
if (props.useExtendedMarkdown && !remarkGfmLoaded.value) { | ||
importRemarkGfmLibrary() | ||
} | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This loads the lib only if useExtendedMarkdown
was true initially. It doesn't support prop update.
&& attrs?.attrs?.class?.includes('language') | ||
&& !rehypeHighlightLoaded.value) { | ||
importRehypeHighlightLibrary() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
makes sense 👍
let remarkGfm | ||
const remarkGfmLoaded = ref(false) | ||
/** | ||
* Load 'remark-gfm' library when prop `useExtendedMarkdown` is truthy | ||
*/ | ||
async function importRemarkGfmLibrary() { | ||
const module = await import('remark-gfm') | ||
remarkGfm = module.default | ||
remarkGfmLoaded.value = true | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just realized, we only need one variable here.
let remarkGfm | |
const remarkGfmLoaded = ref(false) | |
/** | |
* Load 'remark-gfm' library when prop `useExtendedMarkdown` is truthy | |
*/ | |
async function importRemarkGfmLibrary() { | |
const module = await import('remark-gfm') | |
remarkGfm = module.default | |
remarkGfmLoaded.value = true | |
} | |
const remarkGfm = ref(null) | |
/** | |
* Load 'remark-gfm' library when prop `useExtendedMarkdown` is truthy | |
*/ | |
async function importRemarkGfmLibrary() { | |
const module = await import('remark-gfm') | |
remarkGfm.value = module.default | |
} |
☑️ Resolves
remark-gfm
could be async loaded to reduce initial size #6246remark-gfm
is 39.5 kB in dev build, which is 30% of rehype-highlight library size (111kB which we're also importing async)rehype-highlight
won't be imported for code blocks without language provided/recognised🖼️ Screenshots
No visual changes
🏁 Checklist
next
requested with a Vue 3 upgradeSigned-off-by: Maksim Sukharev [email protected]