Skip to content
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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Antreesy
Copy link
Contributor

☑️ Resolves

🖼️ Screenshots

No visual changes

🏁 Checklist

  • ⛑️ Tests are included or are not applicable
  • 📘 Component documentation has been extended, updated or is not applicable
  • 3️⃣ Backport to next requested with a Vue 3 upgrade
    Signed-off-by: Maksim Sukharev [email protected]

@Antreesy Antreesy added 3. to review Waiting for reviews technical debt feature: richtext Related to the richtext component labels Nov 22, 2024
@Antreesy Antreesy added this to the 8.21.1 milestone Nov 22, 2024
@Antreesy Antreesy self-assigned this Nov 22, 2024
Copy link
Contributor

@ShGKme ShGKme left a 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.

Comment on lines +422 to +426
setup(props) {
if (props.useExtendedMarkdown && !remarkGfmLoaded.value) {
importRemarkGfmLibrary()
}
},
Copy link
Contributor

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.

Comment on lines +509 to +511
&& attrs?.attrs?.class?.includes('language')
&& !rehypeHighlightLoaded.value) {
importRehypeHighlightLibrary()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense 👍

Comment on lines +323 to +332
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
}
Copy link
Contributor

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.

Suggested change
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
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3. to review Waiting for reviews feature: richtext Related to the richtext component technical debt
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Enhancement] NcRichText: remark-gfm could be async loaded to reduce initial size
2 participants